@@ -0,0 +1,2013 @@
+#Copyright (c) 2016 Vidhya, Nandini%0A#Following code is available for use under MIT license. Please see the LICENSE file for details.%0A%0A#This file implements the scikit version of decision tree classification for our data set. It calls the GetData function of the BalanceData module to obtain the training features and labels and testing features, labels and keys. It then calls the fit method on the DecisionTree model (which does not take any paramaters) to fit the model to the training features and labels available. The test features are tested on the fitted model to predict the labels for test features which are later used to obtain the test accuracy and confusion matrix. This module also calls the predict_proba method of the Decision Tree model to get per track, the probability of it being in a particular class. This predicted probability per track is stored in teh file DecisionTreeOut which shall be later be used by the combine method.  %0A%0A%0A%0Afrom sklearn import tree%0Afrom BalanceData import *%0Afrom sklearn.metrics import *%0A%0A%0Aootdir = os.getcwd()%0Aif not os.path.exists('sklearnTry'):%0A        os.makedirs('sklearnTry')%0Anewdir = os.path.join(rootdir,'sklearnTry')%0Afout = open(os.path.join(newdir,'DecisionTreeOut.txt'),'w+')%0A%0Atrain_features, train_labels, test_features, test_labels, test_keys = GetData()%0Amodel = tree.DecisionTreeClassifier()%0Amodel = model.fit(train_features, train_labels)%0Apred = model.predict(test_features)%0A%0ApredictProb = model.predict_proba(test_features)%0Atrain_acc = (model.score(train_features, train_labels))%0Aline = str(train_acc )+%22%5Cn%22%0Aprint train_acc%0Afout.write(line)%0A%0A%0A%0Afor key in range(len(test_keys)):%0A    line = test_keys%5Bkey%5D+%22%5Ct%22%0A    for f in range(len(predictProb%5Bkey%5D)):%0A      line +=%22%25i:%25f%5Ct%22 %25 (f+1 , predictProb%5Bkey%5D%5Bf%5D)%0A    line += %22%5Cn%22%0A    fout.write(line)%0Afout.close()%0A %0Afout = open(os.path.join(newdir,'LogisticRegressionMat.txt'),'w+')     %0Aaccuracy = accuracy_score(test_labels, pred)%0AconfMat= confusion_matrix(test_labels, pred)%0Aprint confMat%0Aprint accuracy%0A

Create DecisionTree.py