Created
September 29, 2018 02:56
-
-
Save dubkov/eeca1044a4c473aa19f4ee6d36322d1d to your computer and use it in GitHub Desktop.
isitmaglab1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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