Skip to content

Instantly share code, notes, and snippets.

@dubkov
Created September 29, 2018 02:56
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/eeca1044a4c473aa19f4ee6d36322d1d to your computer and use it in GitHub Desktop.
Save dubkov/eeca1044a4c473aa19f4ee6d36322d1d to your computer and use it in GitHub Desktop.
isitmaglab1
import numpy as np
from sklearn import model_selection
from sklearn import tree
imported_data = []
for line in open('transfusion.data','r'):
line = line.split(",")
line = map(int,line)
imported_data.append(line)
npdata = np.array(imported_data)
X = npdata[:,:4]
y = npdata[:,4]
X_train, X_test, y_train, y_test = model_selection.train_test_split(X,y,train_size=0.9,shuffle=True)
print "TOTAL: ", len(X), "TRAIN: ", len(X_train)
clf = tree.DecisionTreeClassifier(max_depth=4).fit(X_train,y_train)
y_predicted = clf.predict(X_test)
guessed = 0
for ind in range(0,len(y_test)):
if y_test[ind] == y_predicted[ind]:
guessed+=1
print "GESSED RIGHT: ", guessed, "OUT OF: ", len(y_test)
print "ACCURACY: ", 1.0*guessed/len(y_test)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment