Created
September 29, 2018 06:19
-
-
Save dubkov/a828cdb1f695dfae95ef140b817738c2 to your computer and use it in GitHub Desktop.
amm2-lab1
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 as ms | |
from sklearn import tree | |
imported_data = [] | |
for line in open("transfusion.data","r"): | |
line = line.split(",") | |
line = map(int,line) | |
imported_data.append(line) | |
#print imported_data | |
npdata = np.array(imported_data) | |
X = npdata[:,:4] | |
y = npdata[:,4] | |
print "TOTAL DATA LENGTH: ", len(y) | |
X_train, X_test, y_train, y_test = ms.train_test_split(X, y, train_size=0.9) | |
print "TRAIN DATA SIZE: ", len(y_train) | |
clf = tree.DecisionTreeClassifier().fit(X_train,y_train) | |
y_predicted = clf.predict(X_test) | |
guessed = 0 | |
for ind in range(0,len(y_test)): | |
if y_predicted[ind] == y_test[ind]: | |
guessed += 1 | |
print "GUESSED 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