Skip to content

Instantly share code, notes, and snippets.

@magixer
Last active October 22, 2017 17:57
Show Gist options
  • Save magixer/cd51082f32b4d3505e64275afc287151 to your computer and use it in GitHub Desktop.
Save magixer/cd51082f32b4d3505e64275afc287151 to your computer and use it in GitHub Desktop.
Rating accuracy of 6 different classifiers
from sklearn.datasets import load_wine
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
#Classifiers
from sklearn.naive_bayes import GaussianNB
from sklearn.neighbors import KNeighborsClassifier
from sklearn.svm import SVC
from sklearn.gaussian_process import GaussianProcessClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis
# Preparing Data
d = load_wine()
f = d['data']
l = d['target']
# Splitting Data
train_f, test_f, train_l, test_l = train_test_split(f,l, test_size=0.5, random_state=0)
# Classifiers
c1 = GaussianNB().fit(train_f,train_l)
c2 = DecisionTreeClassifier().fit(train_f, train_l)
c3 = KNeighborsClassifier().fit(train_f, train_l)
c4 = SVC().fit(train_f, train_l)
c5 = GaussianProcessClassifier().fit(train_f,train_l)
c6 = QuadraticDiscriminantAnalysis().fit(train_f,train_l)
# Predictions
p1 = c1.predict(test_f)
p2 = c2.predict(test_f)
p3 = c3.predict(test_f)
p4 = c4.predict(test_f)
p5 = c5.predict(test_f)
p6 = c6.predict(test_f)
# Accuracies
print ("GaussianNB " + str(accuracy_score(p1,test_l)))
print ("DecisionTreeClassifier " + str(accuracy_score(p2,test_l)))
print ("KNeighboursClassifier " + str(accuracy_score(p3,test_l)))
print ("SVC " + str(accuracy_score(p4,test_l)))
print ("GaussianProcessClassifier " + str(accuracy_score(p5,test_l)))
print ("QuadraticDiscriminantAnalysis " + str(accuracy_score(p6,test_l)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment