Skip to content

Instantly share code, notes, and snippets.

@magixer
Created October 21, 2017 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magixer/3b84e91a7e6ed0c3d4257ad1ea7b6a0f to your computer and use it in GitHub Desktop.
Save magixer/3b84e91a7e6ed0c3d4257ad1ea7b6a0f to your computer and use it in GitHub Desktop.
Third program
'''
Program to evaluate iris flower into its types - setosa, versicolor, virginica
using GaussianNB and rating the accuracy of the classifer
'''
from sklearn.datasets import load_iris
from sklearn.naive_bayes import GaussianNB
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
data = load_iris() # assining data
# Organizing Data
feature_name = data['feature_names']
feature = data['data']
label_name = data['target_names']
label = data['target']
desc = data['DESCR']
# Splitting our data
train_data, test_data, train_labels, test_labels = train_test_split(feature, label, test_size=0.3, random_state=0)
# assiging gaussianNB as 'classifier'
classifier = GaussianNB()
# feeding our data to classifier and assigning 'trained_classifier' to the fed classifier
trained_classifier = classifier.fit(train_data,train_labels)
# feeding the testing data to the classifier to predict the new data
prediction = trained_classifier.predict(test_data)
# rating our classifier from predicted labels and testing labels
print(accuracy_score(test_labels, prediction))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment