Skip to content

Instantly share code, notes, and snippets.

@aiscool
Created November 26, 2016 01:30
Show Gist options
  • Save aiscool/0f7c59d5d3dbcfe2ae1ad455d0d53c5a to your computer and use it in GitHub Desktop.
Save aiscool/0f7c59d5d3dbcfe2ae1ad455d0d53c5a to your computer and use it in GitHub Desktop.
import matplotlib.pyplot as plt
from sklearn import svm,metrics
import pandas as pd
df = pd.read_csv('training-test.csv')
df = df.iloc[:,1:]
train = df.sample(frac=0.9, random_state=255)
test = df.drop(train.index)
train_in = train.drop(['class'], axis=1).values
train_out = train['class'].values
test_in = test.drop(['class'], axis=1).values
test_out = test['class'].values
cls = svm.SVC(gamma=0.001)
cls.fit(train_in,train_out)
expected = test_out
predicted = cls.predict(test_in)
print("Classification report for classifier %s:\n%s\n"
% (cls, metrics.classification_report(expected, predicted)))
print("Confusion matrix:\n%s" % metrics.confusion_matrix(expected, predicted))
print("\nThe accuracy is : {:.2f}%".format(metrics.accuracy_score(expected,predicted)*100))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment