Skip to content

Instantly share code, notes, and snippets.

@magixer
Last active October 21, 2017 23:30
Show Gist options
  • Save magixer/2ccd283f90bb0b83c9010fc20e5f4aba to your computer and use it in GitHub Desktop.
Save magixer/2ccd283f90bb0b83c9010fc20e5f4aba to your computer and use it in GitHub Desktop.
Evaluating accuracy of 2 diff classifiers from same prepared dataset
'''
Evaluating accuracy of two different classifiers - Decision Tree and GaussianNB
from same prepared dataset
'''
from sklearn.datasets import load_digits
from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import GaussianNB
from sklearn.metrics import accuracy_score
from sklearn.tree import tree
#########################################################
# 1. Importing Data
data = load_digits()
# 2. Organizing data
l = data['target']
f = data['data']
# 3. Splitting Data
train_f, test_f, train_l, test_l = train_test_split(f, l, test_size=0.5, random_state=4)
# 4. Feeding data to classifiers
c = GaussianNB().fit(train_f, train_l)
c2 = tree.DecisionTreeClassifier().fit(train_f,train_l)
# Testing classifiers
p = c.predict(test_f)
p2 = c2.predict(test_f)
# Evaluating Accuracies
a = accuracy_score(p,test_l)
a2 = accuracy_score(p2, test_l)
# Output - Accuracy of Classifiers
print (a)
print (a2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment