複数の分類器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
import pandas as pd from sklearn.model_selection import train_test_split df = pd.read_csv('train.csv') df = df.drop(['Cabin','Name','PassengerId','Ticket'],axis=1) train_X = df.drop('Survived', axis=1) train_y = df.Survived (train_X, test_X ,train_y, test_y) = train_test_split(train_X, train_y, test_size = 0.3, random_state = 666) #決定木 from sklearn.tree import DecisionTreeClassifier ki = DecisionTreeClassifier(random_state=0).fit(train_X, train_y) print(ki.score(train_X,train_y)) #ランダムフォレスト from sklearn.ensemble import RandomForestClassifier mori = RandomForestClassifier(random_state=0).fit(train_X,train_y) print(mori.score(train_X,train_y)) #ロジスティック回帰 from sklearn.linear_model import LogisticRegression logi = LogisticRegression(C=100).fit(train_X,train_y) print(logi.score(train_X,train_y)) #KNN from sklearn.neighbors import KNeighborsClassifier KNN = KNeighborsClassifier(4).fit(train_X,train_y) print(KNN.score(train_X,train_y)) #SVC from sklearn.svm import SVC svc = SVC(probability=True).fit(train_X,train_y) print(svc.score(train_X,train_y)) #AdaBoostClassifier from sklearn.ensemble import AdaBoostClassifier ada = AdaBoostClassifier().fit(train_X,train_y) print(ada.score(train_X,train_y)) #GradientBoostingClassifier from sklearn.ensemble import GradientBoostingClassifier gra = GradientBoostingClassifier().fit(train_X,train_y) print(gra.score(train_X,train_y)) #GaussianNB from sklearn.naive_bayes import GaussianNB gaus = GaussianNB().fit(train_X,train_y) print(gaus.score(train_X,train_y)) #LinearDiscriminantAnalysis from sklearn.discriminant_analysis import LinearDiscriminantAnalysis lda = LinearDiscriminantAnalysis().fit(train_X,train_y) print(lda.score(train_X,train_y)) #QuadraticDiscriminantAnalysis from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis qua = QuadraticDiscriminantAnalysis().fit(train_X,train_y) print(qua.score(train_X,train_y)) |
Out[]:
0.982343499197
0.967897271268
0.807383627608
0.796147672552
0.886035313002
0.837881219904
0.898876404494
0.796147672552
0.799357945425
0.813804173355
コメントを残す