bash-4.3$ ## http://scikit-learn.org/stable/tutorial/statistical_inference/index.html python Python 2.7.12 (default, Sep 29 2016, 13:30:34) [GCC 6.2.1 20160916 (Red Hat 6.2.1-2)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from sklearn import datasets >>> iris - datasets.load_iris() Traceback (most recent call last): File "", line 1, in NameError: name 'iris' is not defined >>> iris = datasets.load_iris() >>> data = iris.data >>> data.shape (150, 4) >>> 9 9 >>> iris.DESCR 'Iris Plants Database\n\nNotes\n-----\nData Set Characteristics:\n :Number of Instances: 150 (50 in each of three classes)\n :Number of Attributes: 4 numeric, predictive attributes and the class\n :Attribute Information:\n - sepal length in cm\n - sepal width in cm\n - petal length in cm\n - petal width in cm\n - class:\n - Iris-Setosa\n - Iris-Versicolour\n - Iris-Virginica\n :Summary Statistics:\n\n ============== ==== ==== ======= ===== ====================\n Min Max Mean SD Class Correlation\n ============== ==== ==== ======= ===== ====================\n sepal length: 4.3 7.9 5.84 0.83 0.7826\n sepal width: 2.0 4.4 3.05 0.43 -0.4194\n petal length: 1.0 6.9 3.76 1.76 0.9490 (high!)\n petal width: 0.1 2.5 1.20 0.76 0.9565 (high!)\n ============== ==== ==== ======= ===== ====================\n\n :Missing Attribute Values: None\n :Class Distribution: 33.3% for each of 3 classes.\n :Creator: R.A. Fisher\n :Donor: Michael Marshall (MARSHALL%PLU@io.arc.nasa.gov)\n :Date: July, 1988\n\nThis is a copy of UCI ML iris datasets.\nhttp://archive.ics.uci.edu/ml/datasets/Iris\n\nThe famous Iris database, first used by Sir R.A Fisher\n\nThis is perhaps the best known database to be found in the\npattern recognition literature. Fisher\'s paper is a classic in the field and\nis referenced frequently to this day. (See Duda & Hart, for example.) The\ndata set contains 3 classes of 50 instances each, where each class refers to a\ntype of iris plant. One class is linearly separable from the other 2; the\nlatter are NOT linearly separable from each other.\n\nReferences\n----------\n - Fisher,R.A. "The use of multiple measurements in taxonomic problems"\n Annual Eugenics, 7, Part II, 179-188 (1936); also in "Contributions to\n Mathematical Statistics" (John Wiley, NY, 1950).\n - Duda,R.O., & Hart,P.E. (1973) Pattern Classification and Scene Analysis.\n (Q327.D83) John Wiley & Sons. ISBN 0-471-22361-1. See page 218.\n - Dasarathy, B.V. (1980) "Nosing Around the Neighborhood: A New System\n Structure and Classification Rule for Recognition in Partially Exposed\n Environments". IEEE Transactions on Pattern Analysis and Machine\n Intelligence, Vol. PAMI-2, No. 1, 67-71.\n - Gates, G.W. (1972) "The Reduced Nearest Neighbor Rule". IEEE Transactions\n on Information Theory, May 1972, 431-433.\n - See also: 1988 MLC Proceedings, 54-64. Cheeseman et al"s AUTOCLASS II\n conceptual clustering system finds 3 classes in the data.\n - Many, many more ...\n' >>> print (iris.DESCR) Iris Plants Database Notes ----- Data Set Characteristics: :Number of Instances: 150 (50 in each of three classes) :Number of Attributes: 4 numeric, predictive attributes and the class :Attribute Information: - sepal length in cm - sepal width in cm - petal length in cm - petal width in cm - class: - Iris-Setosa - Iris-Versicolour - Iris-Virginica :Summary Statistics: ============== ==== ==== ======= ===== ==================== Min Max Mean SD Class Correlation ============== ==== ==== ======= ===== ==================== sepal length: 4.3 7.9 5.84 0.83 0.7826 sepal width: 2.0 4.4 3.05 0.43 -0.4194 petal length: 1.0 6.9 3.76 1.76 0.9490 (high!) petal width: 0.1 2.5 1.20 0.76 0.9565 (high!) ============== ==== ==== ======= ===== ==================== :Missing Attribute Values: None :Class Distribution: 33.3% for each of 3 classes. :Creator: R.A. Fisher :Donor: Michael Marshall (MARSHALL%PLU@io.arc.nasa.gov) :Date: July, 1988 This is a copy of UCI ML iris datasets. http://archive.ics.uci.edu/ml/datasets/Iris The famous Iris database, first used by Sir R.A Fisher This is perhaps the best known database to be found in the pattern recognition literature. Fisher's paper is a classic in the field and is referenced frequently to this day. (See Duda & Hart, for example.) The data set contains 3 classes of 50 instances each, where each class refers to a type of iris plant. One class is linearly separable from the other 2; the latter are NOT linearly separable from each other. References ---------- - Fisher,R.A. "The use of multiple measurements in taxonomic problems" Annual Eugenics, 7, Part II, 179-188 (1936); also in "Contributions to Mathematical Statistics" (John Wiley, NY, 1950). - Duda,R.O., & Hart,P.E. (1973) Pattern Classification and Scene Analysis. (Q327.D83) John Wiley & Sons. ISBN 0-471-22361-1. See page 218. - Dasarathy, B.V. (1980) "Nosing Around the Neighborhood: A New System Structure and Classification Rule for Recognition in Partially Exposed Environments". IEEE Transactions on Pattern Analysis and Machine Intelligence, Vol. PAMI-2, No. 1, 67-71. - Gates, G.W. (1972) "The Reduced Nearest Neighbor Rule". IEEE Transactions on Information Theory, May 1972, 431-433. - See also: 1988 MLC Proceedings, 54-64. Cheeseman et al"s AUTOCLASS II conceptual clustering system finds 3 classes in the data. - Many, many more ... >>> digits = datasets.load_digits() >>> digits.images.shape (1797, 8, 8) >>> import matplotlib.pyplot as plt /usr/lib64/python2.7/site-packages/matplotlib/font_manager.py:273: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment. warnings.warn('Matplotlib is building the font cache using fc-list. This may take a moment.') >>> plt.imshow(digits.images[-1], cmap=lpt.cm.gray_r) Traceback (most recent call last): File "", line 1, in NameError: name 'lpt' is not defined >>> plt.imshow(digits.images[-1], cmap=plt.cm.gray_r) >>> plt >>> plt.show() >>> iris {'target_names': array(['setosa', 'versicolor', 'virginica'], dtype='|S10'), 'data': array([[ 5.1, 3.5, 1.4, 0.2], [ 4.9, 3. , 1.4, 0.2], [ 4.7, 3.2, 1.3, 0.2], [ 4.6, 3.1, 1.5, 0.2], [ 5. , 3.6, 1.4, 0.2], [ 5.4, 3.9, 1.7, 0.4], [ 4.6, 3.4, 1.4, 0.3], [ 5. , 3.4, 1.5, 0.2], [ 4.4, 2.9, 1.4, 0.2], [ 4.9, 3.1, 1.5, 0.1], [ 5.4, 3.7, 1.5, 0.2], [ 4.8, 3.4, 1.6, 0.2], [ 4.8, 3. , 1.4, 0.1], [ 4.3, 3. , 1.1, 0.1], [ 5.8, 4. , 1.2, 0.2], [ 5.7, 4.4, 1.5, 0.4], [ 5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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]), 'DESCR': 'Iris Plants Database\n\nNotes\n-----\nData Set Characteristics:\n :Number of Instances: 150 (50 in each of three classes)\n :Number of Attributes: 4 numeric, predictive attributes and the class\n :Attribute Information:\n - sepal length in cm\n - sepal width in cm\n - petal length in cm\n - petal width in cm\n - class:\n - Iris-Setosa\n - Iris-Versicolour\n - Iris-Virginica\n :Summary Statistics:\n\n ============== ==== ==== ======= ===== ====================\n Min Max Mean SD Class Correlation\n ============== ==== ==== ======= ===== ====================\n sepal length: 4.3 7.9 5.84 0.83 0.7826\n sepal width: 2.0 4.4 3.05 0.43 -0.4194\n petal length: 1.0 6.9 3.76 1.76 0.9490 (high!)\n petal width: 0.1 2.5 1.20 0.76 0.9565 (high!)\n ============== ==== ==== ======= ===== ====================\n\n :Missing Attribute Values: None\n :Class Distribution: 33.3% for each of 3 classes.\n :Creator: R.A. Fisher\n :Donor: Michael Marshall (MARSHALL%PLU@io.arc.nasa.gov)\n :Date: July, 1988\n\nThis is a copy of UCI ML iris datasets.\nhttp://archive.ics.uci.edu/ml/datasets/Iris\n\nThe famous Iris database, first used by Sir R.A Fisher\n\nThis is perhaps the best known database to be found in the\npattern recognition literature. Fisher\'s paper is a classic in the field and\nis referenced frequently to this day. (See Duda & Hart, for example.) The\ndata set contains 3 classes of 50 instances each, where each class refers to a\ntype of iris plant. One class is linearly separable from the other 2; the\nlatter are NOT linearly separable from each other.\n\nReferences\n----------\n - Fisher,R.A. "The use of multiple measurements in taxonomic problems"\n Annual Eugenics, 7, Part II, 179-188 (1936); also in "Contributions to\n Mathematical Statistics" (John Wiley, NY, 1950).\n - Duda,R.O., & Hart,P.E. (1973) Pattern Classification and Scene Analysis.\n (Q327.D83) John Wiley & Sons. ISBN 0-471-22361-1. See page 218.\n - Dasarathy, B.V. (1980) "Nosing Around the Neighborhood: A New System\n Structure and Classification Rule for Recognition in Partially Exposed\n Environments". IEEE Transactions on Pattern Analysis and Machine\n Intelligence, Vol. PAMI-2, No. 1, 67-71.\n - Gates, G.W. (1972) "The Reduced Nearest Neighbor Rule". IEEE Transactions\n on Information Theory, May 1972, 431-433.\n - See also: 1988 MLC Proceedings, 54-64. Cheeseman et al"s AUTOCLASS II\n conceptual clustering system finds 3 classes in the data.\n - Many, many more ...\n', 'feature_names': ['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)', 'petal width (cm)']} >>> iris_x = iris.data >>> iris_y = iris.target >>> np.unique(iris_y) Traceback (most recent call last): File "", line 1, in NameError: name 'np' is not defined >>> import numpy as np >>> np.unique(iris_y) array([0, 1, 2]) >>> np.random.seed(0) >>> indices = np.random.permutation(len(iris_X)) Traceback (most recent call last): File "", line 1, in NameError: name 'iris_X' is not defined >>> iris_X = iris.data >>> iris_y = iris.target >>> np.unique(iris_y) array([0, 1, 2]) >>> indices = np.random.permutation(len(iris_X)) >>> iris_X_train = iris_X[indices[:-10]] >>> iris_y_train = iris_y[indices[:-10]] >>> iris_X_test = iris_X[indices[-10:]] >>> iris_y_test = iris_y[indices[-10:]] >>> from sklearn.neighbors import KNeighborsClassifier >>> knn = KNeighborsClassifier() >>> knn.fit(iris_X_train, iris_y_train) KNeighborsClassifier(algorithm='auto', leaf_size=30, metric='minkowski', metric_params=None, n_jobs=1, n_neighbors=5, p=2, weights='uniform') >>> knn.predict(iris_X_test) array([1, 2, 1, 0, 0, 0, 2, 1, 2, 0]) >>> iris_y_test array([1, 1, 1, 0, 0, 0, 2, 1, 2, 0]) >>> diabetes = datasets.load_diabetes() >>> diabetes_X_train = diabetes.data[:-20] >>> diabetes_X_test = diabetes.data[-20:] >>> diabetes_y_train = diabetes.target[:-20] >>> diabetes_y_test = diabetes.target[-20:] >>> diabetes {'data': array([[ 0.03807591, 0.05068012, 0.06169621, ..., -0.00259226, 0.01990842, -0.01764613], [-0.00188202, -0.04464164, -0.05147406, ..., -0.03949338, -0.06832974, -0.09220405], [ 0.08529891, 0.05068012, 0.04445121, ..., -0.00259226, 0.00286377, -0.02593034], ..., [ 0.04170844, 0.05068012, -0.01590626, ..., -0.01107952, -0.04687948, 0.01549073], [-0.04547248, -0.04464164, 0.03906215, ..., 0.02655962, 0.04452837, -0.02593034], [-0.04547248, -0.04464164, -0.0730303 , ..., -0.03949338, -0.00421986, 0.00306441]]), 'target': array([ 151., 75., 141., 206., 135., 97., 138., 63., 110., 310., 101., 69., 179., 185., 118., 171., 166., 144., 97., 168., 68., 49., 68., 245., 184., 202., 137., 85., 131., 283., 129., 59., 341., 87., 65., 102., 265., 276., 252., 90., 100., 55., 61., 92., 259., 53., 190., 142., 75., 142., 155., 225., 59., 104., 182., 128., 52., 37., 170., 170., 61., 144., 52., 128., 71., 163., 150., 97., 160., 178., 48., 270., 202., 111., 85., 42., 170., 200., 252., 113., 143., 51., 52., 210., 65., 141., 55., 134., 42., 111., 98., 164., 48., 96., 90., 162., 150., 279., 92., 83., 128., 102., 302., 198., 95., 53., 134., 144., 232., 81., 104., 59., 246., 297., 258., 229., 275., 281., 179., 200., 200., 173., 180., 84., 121., 161., 99., 109., 115., 268., 274., 158., 107., 83., 103., 272., 85., 280., 336., 281., 118., 317., 235., 60., 174., 259., 178., 128., 96., 126., 288., 88., 292., 71., 197., 186., 25., 84., 96., 195., 53., 217., 172., 131., 214., 59., 70., 220., 268., 152., 47., 74., 295., 101., 151., 127., 237., 225., 81., 151., 107., 64., 138., 185., 265., 101., 137., 143., 141., 79., 292., 178., 91., 116., 86., 122., 72., 129., 142., 90., 158., 39., 196., 222., 277., 99., 196., 202., 155., 77., 191., 70., 73., 49., 65., 263., 248., 296., 214., 185., 78., 93., 252., 150., 77., 208., 77., 108., 160., 53., 220., 154., 259., 90., 246., 124., 67., 72., 257., 262., 275., 177., 71., 47., 187., 125., 78., 51., 258., 215., 303., 243., 91., 150., 310., 153., 346., 63., 89., 50., 39., 103., 308., 116., 145., 74., 45., 115., 264., 87., 202., 127., 182., 241., 66., 94., 283., 64., 102., 200., 265., 94., 230., 181., 156., 233., 60., 219., 80., 68., 332., 248., 84., 200., 55., 85., 89., 31., 129., 83., 275., 65., 198., 236., 253., 124., 44., 172., 114., 142., 109., 180., 144., 163., 147., 97., 220., 190., 109., 191., 122., 230., 242., 248., 249., 192., 131., 237., 78., 135., 244., 199., 270., 164., 72., 96., 306., 91., 214., 95., 216., 263., 178., 113., 200., 139., 139., 88., 148., 88., 243., 71., 77., 109., 272., 60., 54., 221., 90., 311., 281., 182., 321., 58., 262., 206., 233., 242., 123., 167., 63., 197., 71., 168., 140., 217., 121., 235., 245., 40., 52., 104., 132., 88., 69., 219., 72., 201., 110., 51., 277., 63., 118., 69., 273., 258., 43., 198., 242., 232., 175., 93., 168., 275., 293., 281., 72., 140., 189., 181., 209., 136., 261., 113., 131., 174., 257., 55., 84., 42., 146., 212., 233., 91., 111., 152., 120., 67., 310., 94., 183., 66., 173., 72., 49., 64., 48., 178., 104., 132., 220., 57.])} >>> from sklearn import linear_model >>> regr = linear_model.LinearRegression() >>> regr.fit(diabetes_X_train, diabetes_y_train) LinearRegression(copy_X=True, fit_intercept=True, n_jobs=1, normalize=False) LinearRegression(copy_X=True, fit_intercept=True, n_jobs=1, normalize=False) >>> Traceback (most recent call last): File "", line 1, in NameError: name 'LinearRegression' is not defined >>> print(regr.coef_) [ 3.03499549e-01 -2.37639315e+02 5.10530605e+02 3.27736980e+02 -8.14131709e+02 4.92814588e+02 1.02848452e+02 1.84606489e+02 7.43519617e+02 7.60951722e+01] >>> np.mean((regr.predict(diabetes_X_test)-diabetes_y_test)**2) 2004.5676026898218 >>> regr.score(diabetes_X_test, diabetes_y_test) 0.58507530226905724 >>> X = np.c_[ .5, 1].T >>> y = [.5, 1] >>> test = np.c_[ 0, 2].T >>> regr = linear_model.LinearRegression() >>> import matplotlib.pyplot as plt >>> plt.figure() >>> plt.show() >>> plt.show(plt.figure()) >>> np.random.seed(0) >>> for _ in range(6): ... this_X = .1*np.random.normal(size=(2, 1)) + X ... regr.fit(this_X, y) ... plt.plot(test, regr.predict(test)) ... plt.scatter(this_X, y, s=3) ... LinearRegression(copy_X=True, fit_intercept=True, n_jobs=1, normalize=False) [] LinearRegression(copy_X=True, fit_intercept=True, n_jobs=1, normalize=False) [] LinearRegression(copy_X=True, fit_intercept=True, n_jobs=1, normalize=False) [] LinearRegression(copy_X=True, fit_intercept=True, n_jobs=1, normalize=False) [] LinearRegression(copy_X=True, fit_intercept=True, n_jobs=1, normalize=False) [] LinearRegression(copy_X=True, fit_intercept=True, n_jobs=1, normalize=False) [] >>> plt.show() >>> logistic = linear_model.LogisticRegression(C=1e5) >>> logistic.fit(iris_X_train, iris_y_train) LogisticRegression(C=100000.0, class_weight=None, dual=False, fit_intercept=True, intercept_scaling=1, max_iter=100, multi_class='ovr', n_jobs=1, penalty='l2', random_state=None, solver='liblinear', tol=0.0001, verbose=0, warm_start=False) >>> from digits import * ================================ Digits Classification Exercise ================================ A tutorial exercise regarding the use of classification techniques on the Digits dataset. This exercise is used in the :ref:`clf_tut` part of the :ref:`supervised_learning_tut` section of the :ref:`stat_learn_tut_index`. digits.py:23: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future X_train = X_digits[:.9 * n_samples] digits.py:24: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future y_train = y_digits[:.9 * n_samples] digits.py:25: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future X_test = X_digits[.9 * n_samples:] digits.py:26: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future y_test = y_digits[.9 * n_samples:] KNN score: 0.961111 LogisticRegression score: 0.938889 >>> from sklearn import svm >>> svc = svm.SVC(kernel='linear') >>> svc.fit(iris_X_train, iris_y_train) SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0, decision_function_shape=None, degree=3, gamma='auto', kernel='linear', max_iter=-1, probability=False, random_state=None, shrinking=True, tol=0.001, verbose=False) >>> svc = svm.SVC(kernel='linear') >>> from plot_iris_dataset import * Traceback (most recent call last): File "", line 1, in ImportError: No module named plot_iris_dataset >>> from plot_iris_exercise import * ================================ SVM Exercise ================================ A tutorial exercise for using different SVM kernels. This exercise is used in the :ref:`using_kernels_tut` part of the :ref:`supervised_learning_tut` section of the :ref:`stat_learn_tut_index`. plot_iris_exercise.py:32: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future X_train = X[:.9 * n_sample] plot_iris_exercise.py:33: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future y_train = y[:.9 * n_sample] plot_iris_exercise.py:34: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future X_test = X[.9 * n_sample:] plot_iris_exercise.py:35: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future y_test = y[.9 * n_sample:] >>> from sklearn import datasets, svm >>> digits = datasets.load_digits() >>> X_digits = digits.data >>> y_digits = digits.target >>> svc = svm.SVC(C=1, kernel='linear') >>> svc.fit(X_digits[:-100], y_digits[:-100]).score(X_digits[-100:], y_digits[-100:]) 0.97999999999999998 >>>