機械学習がどんなものかを学ぶビデオ・レッスンです。
機械学習が何をしようとしているのかをコーディングを通して、教えてくれます。
GoogleのJosh Gordonさんのレッスンでシリーズものになっています。
その4回目
Scikit-learnのパイプラインを書こう – 機械学習レシピ4
以下はムービーの説明を補足するヘルプです
Dataset
Label | |
Click here to claim your prize! | Spam |
What’s new? | Not spam |
Hang out later? | Not spam |
You have won $1000,000 | Spam |
Train
Label | |
Click here to claim your prize! | Spam |
What’s new? | Not spam |
Hang out later? | Not spam |
Test
Label | |
Pick up groceries | Not spam |
Free free free ! | Spam |
Android 5.0 questions | Not spam |
ムービーと異なり、ubuntu 16.04 LTS + Python3の環境で実行する場合
ムービーのコードの変更点
× from sklearn.cross_validation import train_test_split
○ from sklearn.model_selection import train_test_split
【test4.py】
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#import a dataset from sklearn import datasets iris = datasets.load_iris() x = iris.data y = iris.target from sklearn.model_selection import train_test_split x_train,x_test,y_train,y_test = train_test_split(x,y,test_size = .5) from sklearn import tree my_classifier = tree.DecisionTreeClassifier() my_classifier.fit(x_train,y_train) predictions = my_classifier.predict(x_test) print(predictions) |
$python3 test4.py
結果
【test5.py】
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#import a dataset from sklearn import datasets iris = datasets.load_iris() x = iris.data y = iris.target from sklearn.model_selection import train_test_split x_train,x_test,y_train,y_test = train_test_split(x,y,test_size = .5) from sklearn import tree my_classifier = tree.DecisionTreeClassifier() my_classifier.fit(x_train,y_train) predictions = my_classifier.predict(x_test) <strong>from sklearn.metrics import accuracy_score</strong> <strong>print(accuracy_score(y_test,predictions))</strong> |
$python3 test5.py
結果
【test6.py】
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#import a dataset from sklearn import datasets iris = datasets.load_iris() x = iris.data y = iris.target from sklearn.model_selection import train_test_split x_train,x_test,y_train,y_test = train_test_split(x,y,test_size = .5) <strong>from sklearn.neighbors import KNeighborsClassifier</strong> <strong>my_classifier = KNeighborsClassifier()</strong> my_classifier.fit(x_train,y_train) predictions = my_classifier.predict(x_test) from sklearn.metrics import accuracy_score print(accuracy_score(y_test,predictions)) |
$python3 test6.py
結果
Leave a Reply