官术网_书友最值得收藏!

Loading the training data

The Iris dataset is included with scikit-learn. We first load all the necessary modules, as we did in our earlier examples:

In [1]: import numpy as np
... import cv2
... from sklearn import datasets
... from sklearn import model_selection
... from sklearn import metrics
... import matplotlib.pyplot as plt
... %matplotlib inline
In [2]: plt.style.use('ggplot')

Then, loading the dataset is a one-liner:

In [3]: iris = datasets.load_iris()

This function returns a dictionary we call iris, which contains a bunch of different fields:

In [4]: dir(iris)
Out[4]: ['DESCR', 'data', 'feature_names', 'target', 'target_names']

Here, all the data points are contained in 'data'. There are 150 data points, each of which have four feature values:

In [5]: iris.data.shape
Out[5]: (150, 4)

These four features correspond to the sepal and petal dimensions mentioned earlier:

In [6]: iris.feature_names
Out[6]: ['sepal length (cm)',
'sepal width (cm)',
'petal length (cm)',
'petal width (cm)']

For every data point, we have a class label stored in target:

In [7]: iris.target.shape
Out[7]: (150,)

We can also inspect the class labels, and find that there is a total of three classes:

In [8]: np.unique(iris.target)
Out[8]: array([0, 1, 2])
主站蜘蛛池模板: 林西县| 泰安市| 肇州县| 从江县| 大埔县| 康乐县| 卓尼县| 盱眙县| 洪江市| 平远县| 赤壁市| 荆州市| 广昌县| 长春市| 平山县| 南投县| 嵩明县| 西充县| 鹿邑县| 新邵县| 茌平县| 林州市| 洛隆县| 咸宁市| 西吉县| 邵东县| 本溪市| 安顺市| 武夷山市| 乌审旗| 博罗县| 渭南市| 苏尼特左旗| 治多县| 隆安县| 高台县| 普陀区| 集安市| 泌阳县| 云浮市| 格尔木市|