- Machine Learning for OpenCV
- Michael Beyeler
- 192字
- 2021-07-02 19:47:25
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])
推薦閱讀
- JavaScript百煉成仙
- Learn Blockchain Programming with JavaScript
- 流量的秘密:Google Analytics網(wǎng)站分析與優(yōu)化技巧(第2版)
- The Android Game Developer's Handbook
- 編程的修煉
- Android NDK Beginner’s Guide
- jQuery從入門到精通 (軟件開發(fā)視頻大講堂)
- Building a Recommendation Engine with Scala
- TypeScript項(xiàng)目開發(fā)實(shí)戰(zhàn)
- PHP 7+MySQL 8動(dòng)態(tài)網(wǎng)站開發(fā)從入門到精通(視頻教學(xué)版)
- Windows Phone 7.5:Building Location-aware Applications
- Django 3.0應(yīng)用開發(fā)詳解
- Qt5 C++ GUI Programming Cookbook
- Vue.js光速入門及企業(yè)項(xiàng)目開發(fā)實(shí)戰(zhàn)
- Learning D