http://scikit-learn.org/stable/tutorial/basic/tutorial.html Machine learning: the problem setting bash-4.3$ 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() >>> digits = datasets.load_digits() >>> dir(datasets) ['__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '_svmlight_format', 'base', 'california_housing', 'clear_data_home', 'covtype', 'dump_svmlight_file', 'fetch_20newsgroups', 'fetch_20newsgroups_vectorized', 'fetch_california_housing', 'fetch_covtype', 'fetch_lfw_pairs', 'fetch_lfw_people', 'fetch_mldata', 'fetch_olivetti_faces', 'fetch_rcv1', 'fetch_species_distributions', 'get_data_home', 'lfw', 'load_boston', 'load_breast_cancer', 'load_diabetes', 'load_digits', 'load_files', 'load_iris', 'load_lfw_pairs', 'load_lfw_people', 'load_linnerud', 'load_mlcomp', 'load_sample_image', 'load_sample_images', 'load_svmlight_file', 'load_svmlight_files', 'make_biclusters', 'make_blobs', 'make_checkerboard', 'make_circles', 'make_classification', 'make_friedman1', 'make_friedman2', 'make_friedman3', 'make_gaussian_quantiles', 'make_hastie_10_2', 'make_low_rank_matrix', 'make_moons', 'make_multilabel_classification', 'make_regression', 'make_s_curve', 'make_sparse_coded_signal', 'make_sparse_spd_matrix', 'make_sparse_uncorrelated', 'make_spd_matrix', 'make_swiss_roll', 'mlcomp', 'mldata', 'mldata_filename', 'olivetti_faces', 'rcv1', 'samples_generator', 'species_distributions', 'svmlight_format', 'twenty_newsgroups'] >>> dir(digits) ['__class__', '__cmp__', '__contains__', '__delattr__', '__delitem__', '__dict__', '__doc__', '__eq__', '__format__', '__ge__', '__getattr__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'clear', 'copy', 'fromkeys', 'get', 'has_key', 'items', 'iteritems', 'iterkeys', 'itervalues', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values', 'viewitems', 'viewkeys', 'viewvalues'] >>> print (digits.data) [[ 0. 0. 5. ..., 0. 0. 0.] [ 0. 0. 0. ..., 10. 0. 0.] [ 0. 0. 0. ..., 16. 9. 0.] ..., [ 0. 0. 1. ..., 6. 0. 0.] [ 0. 0. 2. ..., 12. 0. 0.] [ 0. 0. 10. ..., 12. 1. 0.]] >>> len (digits.data) 1797 >>> len (digits.data[0]) 64 >>> len (digits.data[9]) 64 >>> digits.target array([0, 1, 2, ..., 8, 9, 8]) >>> len(digits.target) 1797 >>> digits.images[0] array([[ 0., 0., 5., 13., 9., 1., 0., 0.], [ 0., 0., 13., 15., 10., 15., 5., 0.], [ 0., 3., 15., 2., 0., 11., 8., 0.], [ 0., 4., 12., 0., 0., 8., 8., 0.], [ 0., 5., 8., 0., 0., 9., 8., 0.], [ 0., 4., 11., 0., 1., 12., 7., 0.], [ 0., 2., 14., 5., 10., 12., 0., 0.], [ 0., 0., 6., 13., 10., 0., 0., 0.]]) >>> len(digits.images[0]) 8 >>> // 9 File "", line 1 // 9 ^ SyntaxError: invalid syntax >>> ## 9 ... >>> from sklearn import svm >>> clf = svm.SVC(gamma=0.001, c=100.) Traceback (most recent call last): File "", line 1, in TypeError: __init__() got an unexpected keyword argument 'c' >>> clf = svm.SVC(gamma=0.001, C=100.) >>> clf.fit(digits.data[:-1], digits.target[:-1]) SVC(C=100.0, cache_size=200, class_weight=None, coef0=0.0, decision_function_shape=None, degree=3, gamma=0.001, kernel='rbf', max_iter=-1, probability=False, random_state=None, shrinking=True, tol=0.001, verbose=False) >>> digits.target[-1] 8 >>> digit.images[-1] Traceback (most recent call last): File "", line 1, in NameError: name 'digit' is not defined >>> digits.images[-1] array([[ 0., 0., 10., 14., 8., 1., 0., 0.], [ 0., 2., 16., 14., 6., 1., 0., 0.], [ 0., 0., 15., 15., 8., 15., 0., 0.], [ 0., 0., 5., 16., 16., 10., 0., 0.], [ 0., 0., 12., 15., 15., 12., 0., 0.], [ 0., 4., 16., 6., 4., 16., 6., 0.], [ 0., 8., 16., 10., 8., 16., 8., 0.], [ 0., 1., 8., 12., 14., 12., 1., 0.]]) >>> clf.predict(digits.data[-1:]) array([8]) >>> from sklearn import svm >>> from sklearn import datasets >>> clf = svm.SVC() >>> iris = datasets.load_iris() >>> x, y = iris.data, iris.target >>> clf.fit(x,y) SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0, decision_function_shape=None, degree=3, gamma='auto', kernel='rbf', max_iter=-1, probability=False, random_state=None, shrinking=True, tol=0.001, verbose=False) >>> len(x) 150 >>> len(y) 150 >>> x 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.4, 3.9, 1.3, 0.4], [ 5.1, 3.5, 1.4, 0.3], [ 5.7, 3.8, 1.7, 0.3], [ 5.1, 3.8, 1.5, 0.3], [ 5.4, 3.4, 1.7, 0.2], [ 5.1, 3.7, 1.5, 0.4], [ 4.6, 3.6, 1. , 0.2], [ 5.1, 3.3, 1.7, 0.5], [ 4.8, 3.4, 1.9, 0.2], [ 5. , 3. , 1.6, 0.2], [ 5. , 3.4, 1.6, 0.4], [ 5.2, 3.5, 1.5, 0.2], [ 5.2, 3.4, 1.4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2, 2]) >>> import pickle >>> s = pickle.dump(clf) Traceback (most recent call last): File "", line 1, in TypeError: dump() takes at least 2 arguments (1 given) >>> s = pickle.dumps(clf) >>> clf2 = pickle.loads(s) >>> clf2.predict(x[0:1]) array([0]) >>> y[0] 0 >>> from sklearn.externals import joblib >>> joblib.dump(clf, 'filename.pkl') ['filename.pkl', 'filename.pkl_01.npy', 'filename.pkl_02.npy', 'filename.pkl_03.npy', 'filename.pkl_04.npy', 'filename.pkl_05.npy', 'filename.pkl_06.npy', 'filename.pkl_07.npy', 'filename.pkl_08.npy', 'filename.pkl_09.npy', 'filename.pkl_10.npy', 'filename.pkl_11.npy'] >>> >>> import numpy as np >>> from sklearn import random_projection >>> rng = np.random.RandomState(0 ... ) >>> rng >>> X = rnd.rand(10, 2000) Traceback (most recent call last): File "", line 1, in NameError: name 'rnd' is not defined >>> X = rng.rand(10, 2000) >>> x 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.4, 3.9, 1.3, 0.4], [ 5.1, 3.5, 1.4, 0.3], [ 5.7, 3.8, 1.7, 0.3], [ 5.1, 3.8, 1.5, 0.3], [ 5.4, 3.4, 1.7, 0.2], [ 5.1, 3.7, 1.5, 0.4], [ 4.6, 3.6, 1. , 0.2], [ 5.1, 3.3, 1.7, 0.5], [ 4.8, 3.4, 1.9, 0.2], [ 5. , 3. , 1.6, 0.2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2.3], [ 5.6, 2.8, 4.9, 2. ], [ 7.7, 2.8, 6.7, 2. ], [ 6.3, 2.7, 4.9, 1.8], [ 6.7, 3.3, 5.7, 2.1], [ 7.2, 3.2, 6. , 1.8], [ 6.2, 2.8, 4.8, 1.8], [ 6.1, 3. , 4.9, 1.8], [ 6.4, 2.8, 5.6, 2.1], [ 7.2, 3. , 5.8, 1.6], [ 7.4, 2.8, 6.1, 1.9], [ 7.9, 3.8, 6.4, 2. ], [ 6.4, 2.8, 5.6, 2.2], [ 6.3, 2.8, 5.1, 1.5], [ 6.1, 2.6, 5.6, 1.4], [ 7.7, 3. , 6.1, 2.3], [ 6.3, 3.4, 5.6, 2.4], [ 6.4, 3.1, 5.5, 1.8], [ 6. , 3. , 4.8, 1.8], [ 6.9, 3.1, 5.4, 2.1], [ 6.7, 3.1, 5.6, 2.4], [ 6.9, 3.1, 5.1, 2.3], [ 5.8, 2.7, 5.1, 1.9], [ 6.8, 3.2, 5.9, 2.3], [ 6.7, 3.3, 5.7, 2.5], [ 6.7, 3. , 5.2, 2.3], [ 6.3, 2.5, 5. , 1.9], [ 6.5, 3. , 5.2, 2. ], [ 6.2, 3.4, 5.4, 2.3], [ 5.9, 3. , 5.1, 1.8]]) >>> X = np.array(X, dtype='float32') >>> X.dtype dtype('float32') >>> transformer = random_projection.GaussianRandomProjection() >>> X_new = transformer.fit_transform(X) >>> X_new.dtype dtype('float64') >>> from sklearn import datasets >>> iris = datasets.load_iris() >>> clf = SVC() Traceback (most recent call last): File "", line 1, in NameError: name 'SVC' is not defined >>> from sklearn.svm import SVC >>> clf = SVC() >>> clf.fit(iris.data, iris.target) SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0, decision_function_shape=None, degree=3, gamma='auto', kernel='rbf', max_iter=-1, probability=False, random_state=None, shrinking=True, tol=0.001, verbose=False) >>> list(clf.prdict(iris.data[:3])) Traceback (most recent call last): File "", line 1, in AttributeError: 'SVC' object has no attribute 'prdict' >>> list(clf.predict(iris.data[:3])) [0, 0, 0] >>> clf.fit(iris.data, iris.target_names[iris.target]) SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0, decision_function_shape=None, degree=3, gamma='auto', kernel='rbf', max_iter=-1, probability=False, random_state=None, shrinking=True, tol=0.001, verbose=False) >>> list(clf.predict(iris.data[:3])) ['setosa', 'setosa', 'setosa'] >>> import numpy as np >>> from sklearn.svm import SVC >>> rng = np.random.Random.State(0) Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'Random' >>> rng = np.random.RandomState(0) >>> X = rnd.rand(100,10) Traceback (most recent call last): File "", line 1, in NameError: name 'rnd' is not defined >>> X = rng.rand(100, 10) >>> y = rng.binomail(1, 0.5, 100) Traceback (most recent call last): File "", line 1, in AttributeError: 'mtrand.RandomState' object has no attribute 'binomail' >>> y = rng.binomial(1, 0.5, 100) >>> X_test = rng.rand(5, 10) >>> X_test array([[ 0.29594983, 0.92929167, 0.26590563, 0.82814661, 0.98510868, 0.78339665, 0.51898992, 0.06607426, 0.47241379, 0.43825595], [ 0.20279604, 0.42358764, 0.35775788, 0.16368426, 0.44137414, 0.26279996, 0.52206242, 0.03516006, 0.90623142, 0.81636431], [ 0.55258133, 0.85180858, 0.96239507, 0.11052229, 0.63083181, 0.997994 , 0.98788917, 0.60332299, 0.12802087, 0.58319283], [ 0.00206464, 0.19891133, 0.95612316, 0.33044057, 0.63839011, 0.28085949, 0.94782189, 0.72855873, 0.32965116, 0.79176142], [ 0.10816552, 0.39231894, 0.22121813, 0.68372645, 0.10244628, 0.39702583, 0.27664973, 0.50634292, 0.34989768, 0.70641058]]) >>> clf = SBC() Traceback (most recent call last): File "", line 1, in NameError: name 'SBC' is not defined >>> slf = SVC() >>> clf = slf >>> clf.set_params(kernal='rbf').fit(X, y) Traceback (most recent call last): File "", line 1, in File "/usr/lib64/python2.7/site-packages/sklearn/base.py", line 270, in set_params (key, self.__class__.__name__)) ValueError: Invalid parameter kernal for estimator SVC. Check the list of available parameters with `estimator.get_params().keys()`. >>> clf.set_params(kernel='rbf').fit(X, y) SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0, decision_function_shape=None, degree=3, gamma='auto', kernel='rbf', max_iter=-1, probability=False, random_state=None, shrinking=True, tol=0.001, verbose=False) >>> clf.predict(X_test) array([0, 0, 0, 1, 0]) >>> clf.set_params(kernel='linear').fit(X, y) 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) >>> clf.predict(X_test) array([1, 0, 1, 1, 0]) >>> from sklearn.svm import SVC >>> from sklearn.multiclass import OneVsRestClassifier >>> from sklearn.preprocessing import LabelBinarizer >>> X = [[1, 2], [2, 4], [4, 5], [3, 2], [3, 1]] >>> y = [0, 0, 1, 1, 2] >>> classif = OneVsRestClassifier(estimator=SVC(random_state=0)) >>> classif.fit(X, y).predict(X) array([0, 0, 1, 1, 2]) >>> y = LabelBinarizer().fit_transform(y) >>> classif.fit(X, y).predict(X) array([[1, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 0], [0, 0, 0]]) >>> from sklearn.preprocessing import MultiLabelBinarizer >>> y = [[0, 1], [0, 2], [1, 3], [0, 2, 3], [2, 4]] >>> y = preprocessing.MultiLabelBinarizer().fit_transform(y) Traceback (most recent call last): File "", line 1, in NameError: name 'preprocessing' is not defined >>> y = MultiLabelBinarizer().fit_transform(y) >>> classif.fit(X, y).predict(X) array([[1, 1, 0, 0, 0], [1, 0, 1, 0, 0], [0, 1, 0, 1, 0], [1, 0, 1, 0, 0], [1, 0, 1, 0, 0]]) >>> bash-4.3$ exit Process shell finished