Skip to content

Instantly share code, notes, and snippets.

@dubkov
Created September 22, 2018 03:20
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 dubkov/11b1bf32862fad338862601fa8a4f62c to your computer and use it in GitHub Desktop.
Save dubkov/11b1bf32862fad338862601fa8a4f62c to your computer and use it in GitHub Desktop.
isitlab1
import numpy as np
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
imported_data = []
for line in open('transfusion.data', 'r'):
line = line.split(",")
line = map(int,line)
imported_data.append(line)
all_data = np.array(imported_data)
X = all_data[:,:4]
y = all_data[:,4]
X_train, X_test, y_train, y_test = train_test_split(X,y, train_size=0.8)
clf = DecisionTreeClassifier().fit(X_train, y_train)
y_predicted = clf.predict(X_test)
print y_predicted
guessed_num = 0
for ind in range(0,len(y_predicted)):
if y_predicted[ind] == y_test[ind]:
guessed_num += 1
print "TOTAL:", len(y_test)
print "guessed:", guessed_num
print "accuracy:", 1.0*guessed_num/len(y_test)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment