インターフェースが統一されてるので便利
from sklearn import datasets from pylab import * import numpy as np from sklearn.naive_bayes import GaussianNB from sklearn.model_selection import train_test_split from sklearn.neighbors import KNeighborsClassifier from sklearn.svm import SVC from sklearn.tree import DecisionTreeClassifier from sklearn.ensemble import RandomForestClassifier, AdaBoostClassifier from sklearn.gaussian_process import GaussianProcessClassifier from sklearn.gaussian_process.kernels import RBF def showResult(classifier, titlestring): model = classifier.fit(X_train,y_train) y_pred = model.predict(X_test) scatter(X_test[:,0],X_test[:,1],s=20,c=np.where(y_pred==0,'red','blue')) title(titlestring) show() X,y = datasets.make_moons(600,noise=0.05) X_train,X_test,y_train,y_test = train_test_split(X,y,train_size=0.8) scatter(X[:,0],X[:,1],s=20,c=np.where(y==0,'red','blue')) title('original') show() showResult(GaussianNB(), 'Gaussian NaiveBayes') showResult(KNeighborsClassifier(), 'K-NN') showResult(SVC(), 'Support Vector Classifier') showResult(DecisionTreeClassifier(), 'Decision Tree') showResult(RandomForestClassifier(), 'Random Forest') showResult(AdaBoostClassifier(), 'AdaBoost Classifier') showResult(GaussianProcessClassifier(), 'Gaussian Process Classifier')