Scikit-learnでよく使う分類モデルまとめ
モデルの評価
from sklearn.metrics import accuracy_score accuracy_score(pred, val_y)
sklearnの分類モデル
ロジスティック回帰
from sklearn.linear_model import LogisticRegression logreg = LogisticRegression() logreg.fit(train_X, train_y) pred = logreg.predict(val_X)
SVC
from sklearn.svm import SVC svc = SVC() svc.fit(train_X, train_y) pred = svc.predict(val_X)
LinearSVC
from sklearn.svm import LinearSVC linear_svc = LinearSVC() linear_svc.fit(train_X, train_y) pred = linear_svc.predict(val_X)
決定木
from sklearn.tree import DecisionTreeClassifier decisiontree = DecisionTreeClassifier() decisiontree.fit(train_X, train_y) y_pred = decisiontree.predict(val_X)
ランダムフォレスト
from sklearn.ensemble import RandomForestClassifier randomforest = RandomForestClassifier() randomforest.fit(train_X, train_y) pred = randomforest.predict(val_X)
KNeighborsClassifier
from sklearn.neighbors import KNeighborsClassifier knn = KNeighborsClassifier() knn.fit(train_X, train_y) pred = knn.predict(val_X)
ナイーブベイズ
from sklearn.naive_bayes import GaussianNB gaussian = GaussianNB() gaussian.fit(train_X, train_y) pred = gaussian.predict(val_X)
GradientBoostingClassifier
from sklearn.ensemble import GradientBoostingClassifier gbk = GradientBoostingClassifier() gbk.fit(train_X, train_y) pred = gbk.predict(val_X)
Stochastic Gradient Descent
from sklearn.linear_model import SGDClassifier sgd = SGDClassifier() sgd.fit(train_X, train_y) pred = sgd.predict(val_X)
参考
1. Supervised learning
...