).flatten() # Read Y test and flatten it to 1D array print len(X_train), len(Y_train) # Printing Lengths of Train and Test Data print len(X_test), len(Y_test) X_dynamic_train, Y_dynamic_train = common.getDataSubset( X_train, Y_train, [1, 2, 3]) # Get Train sub data for [1,2,3] X_nondynamic_train, Y_nondynamic_train = common.getDataSubset( X_train, Y_train, [4, 5, 6]) # Get Train sub data for [4,5,6] X_dynamic_test, Y_dynamic_test = common.getDataSubset( X_test, Y_test, [1, 2, 3]) # Get Test sub data for [1,2,3] X_nondynamic_test, Y_nondynamic_test = common.getDataSubset( X_test, Y_test, [4, 5, 6]) # Get Test sub data for [4,5,6] X_nondynamic_train = common.getPowerK(X_nondynamic_train, [1, 2]) # Convert X Train to X+X^2 X_nondynamic_test = common.getPowerK(X_nondynamic_test, [1, 2]) # Convert X Test to X+X^2 #X_nondynamic_train_6, Y_nondynamic_train_6=common.getDataSubset(X_train, Y_train, [6]) # Used earlier to get Sub data for just 6th label #X_nondynamic_test_6, Y_nondynamic_test_6=common.getDataSubset(X_test, Y_test, [6]) #Y_nondynamic_train_sublabels=common.convertLabel(Y_nondynamic_train, [4,5], [6]) # Used earlier to convert [4,5] to [1] and [6] to [0] #Y_nondynamic_test_sublabels=common.convertLabel(Y_nondynamic_test, [4,5], [6]) print len(X_dynamic_train), len( Y_dynamic_train ), Y_dynamic_train # Printing lenghts and Labels extracted for verification print len(X_nondynamic_train), len(Y_nondynamic_train), Y_nondynamic_train sample_weights = common.getSampleWeights( X_nondynamic_train, Y_nondynamic_train, [4, 5, 6]) # Get sample weights for non-dynamic Data
# Hyper-parameters # #top_N = 5 ####################### # Pre-processing of data # print("Computing means and covariances") print("Get trainSubjects&noDynamic static data...") trainSubjects = [ 1, 3, 5, 6, 7, 8, 11, 14, 15, 16, 17, 19, 21, 22, 23, 25, 26, 27, 28, 29, 30 ] requiredLabels = [1, 2, 3, 4, 5, 6] # 每一行原数据用上他们的幂次形成2倍大小的特征矩阵 X_train = common.getPowerK(X_train, [1, 2]) mean_array = [] cov_array = [] label_array = [] for i in trainSubjects: for j in requiredLabels: # Get subject info X_train_new, Y_train_new, subjectInfo = common.getSubjectData( X_train, Y_train, [i]) # Get Data Subset # X_train_new, Y_train_new = common.getDataSubset( X_train, Y_train, requiredLabels)
def LDA_onData(): #Parsing Full training dataset XFull = common.parseFile('../UCI HAR Dataset/train/X_train.txt') YFull = common.parseFile('../UCI HAR Dataset/train/y_train.txt') #Parsing Full testing dataset XFullTest = common.parseFile('../UCI HAR Dataset/test/X_test.txt') YFullTest = common.parseFile('../UCI HAR Dataset/test/y_test.txt') ################################################################################################################################# #Getting the dataset associated with Dynamic Activities on training X_Dynamic, Y_Dynamic = common.getDataSubset(XFull, YFull.flatten(), [1, 2, 3, 4, 5, 6]) #Getting the dataset associated with Dynamic Activities on testing X_DynamicTest, Y_DynamicTest = common.getDataSubset( XFullTest, YFullTest.flatten(), [1, 2, 3, 4, 5, 6]) #Fitting data using LDA classifier clf = LDA() clf.fit(X_Dynamic, Y_Dynamic.flatten()) precision, recall, fscore = common.checkAccuracy( clf.predict(X_DynamicTest), Y_DynamicTest, [1, 2, 3, 4, 5, 6]) print( common.createConfusionMatrix( clf.predict(X_DynamicTest).flatten(), Y_DynamicTest.flatten(), [1, 2, 3, 4, 5, 6])) print(fscore) ################################################################################################################################# #Getting the dataset associated with Dynamic Activities on training X_Dynamic, Y_Dynamic = common.getDataSubset(XFull, YFull.flatten(), [1, 2, 3, 4, 5, 6]) #Getting the dataset associated with Dynamic Activities on testing X_DynamicTest, Y_DynamicTest = common.getDataSubset( XFullTest, YFullTest.flatten(), [1, 2, 3, 4, 5, 6]) X_Dynamic = common.getPowerK(X_Dynamic, [1, 2]) X_DynamicTest = common.getPowerK(X_DynamicTest, [1, 2]) #Fitting data using LDA classifier clf = LDA() clf.fit(X_Dynamic, Y_Dynamic.flatten()) precision, recall, fscore = common.checkAccuracy( clf.predict(X_DynamicTest), Y_DynamicTest, [1, 2, 3, 4, 5, 6]) print( common.createConfusionMatrix( clf.predict(X_DynamicTest).flatten(), Y_DynamicTest.flatten(), [1, 2, 3, 4, 5, 6])) print(fscore) ################################################################################################################################# #Getting the dataset associated with Dynamic Activities on training X_Dynamic, Y_Dynamic = common.getDataSubset(XFull, YFull.flatten(), [1, 2, 3, 4, 5, 6]) #Getting the dataset associated with Dynamic Activities on testing X_DynamicTest, Y_DynamicTest = common.getDataSubset( XFullTest, YFullTest.flatten(), [1, 2, 3, 4, 5, 6]) X_Dynamic = common.getPowerK(X_Dynamic, [1, 2, 3]) X_DynamicTest = common.getPowerK(X_DynamicTest, [1, 2, 3]) #Fitting data using LDA classifier clf = LDA() clf.fit(X_Dynamic, Y_Dynamic.flatten()) precision, recall, fscore = common.checkAccuracy( clf.predict(X_DynamicTest), Y_DynamicTest, [1, 2, 3, 4, 5, 6]) print( common.createConfusionMatrix( clf.predict(X_DynamicTest).flatten(), Y_DynamicTest.flatten(), [1, 2, 3, 4, 5, 6])) print(fscore) ################################################################################################################################# #Getting the dataset associated with Dynamic Activities on training X_Dynamic, Y_Dynamic = common.getDataSubset(XFull, YFull.flatten(), [1, 2, 3]) #Getting the dataset associated with Dynamic Activities on testing X_DynamicTest, Y_DynamicTest = common.getDataSubset( XFullTest, YFullTest.flatten(), [1, 2, 3]) print(len(X_DynamicTest), len(Y_DynamicTest)) #Fitting data using LDA classifier clf = LDA() clf.fit(X_Dynamic, Y_Dynamic.flatten()) precision, recall, fscore = common.checkAccuracy( clf.predict(X_DynamicTest), Y_DynamicTest, [1, 2, 3]) print( common.createConfusionMatrix( clf.predict(X_DynamicTest).flatten(), Y_DynamicTest.flatten(), [1, 2, 3])) print(fscore) ################################################################################################################################# #Getting the dataset associated with Dynamic Activities on training X_Dynamic, Y_Dynamic = common.getDataSubset(XFull, YFull.flatten(), [1, 2, 3]) #Getting the dataset associated with Dynamic Activities on testing X_DynamicTest, Y_DynamicTest = common.getDataSubset( XFullTest, YFullTest.flatten(), [1, 2, 3]) X_Dynamic = common.getPowerK(X_Dynamic, [1, 2]) X_DynamicTest = common.getPowerK(X_DynamicTest, [1, 2]) #Fitting data using LDA classifier clf = LDA() clf.fit(X_Dynamic, Y_Dynamic.flatten()) precision, recall, fscore = common.checkAccuracy( clf.predict(X_DynamicTest), Y_DynamicTest, [1, 2, 3]) print( common.createConfusionMatrix( clf.predict(X_DynamicTest).flatten(), Y_DynamicTest.flatten(), [1, 2, 3])) print(fscore) ################################################################################################################################# #Getting the dataset associated with Dynamic Activities on training X_Dynamic, Y_Dynamic = common.getDataSubset(XFull, YFull.flatten(), [1, 2, 3]) #Getting the dataset associated with Dynamic Activities on testing X_DynamicTest, Y_DynamicTest = common.getDataSubset( XFullTest, YFullTest.flatten(), [1, 2, 3]) X_Dynamic = common.getPowerK(X_Dynamic, [1, 2, 3]) X_DynamicTest = common.getPowerK(X_DynamicTest, [1, 2, 3]) #Fitting data using LDA classifier clf = LDA() clf.fit(X_Dynamic, Y_Dynamic.flatten()) precision, recall, fscore = common.checkAccuracy( clf.predict(X_DynamicTest), Y_DynamicTest, [1, 2, 3]) print( common.createConfusionMatrix( clf.predict(X_DynamicTest).flatten(), Y_DynamicTest.flatten(), [1, 2, 3])) print(fscore) ################################################################################################################################# #Getting the dataset associated with Non-Dynamic Activities on training X_NonDynamic, Y_NonDynamic = common.getDataSubset(XFull, YFull.flatten(), [4, 5, 6]) #Getting the dataset associated with Non-Dynamic Activities on testing X_NonDynamicTest, Y_NonDynamicTest = common.getDataSubset( XFullTest, YFullTest.flatten(), [4, 5, 6]) #Fitting data using LDA classifier clf = LDA() clf.fit(X_NonDynamic, Y_NonDynamic.flatten()) precision, recall, fscore = common.checkAccuracy( clf.predict(X_NonDynamicTest), Y_NonDynamicTest, [4, 5, 6]) print( common.createConfusionMatrix( clf.predict(X_NonDynamicTest).flatten(), Y_NonDynamicTest.flatten(), [4, 5, 6])) print(fscore) ################################################################################################################################# #Getting the dataset associated with Dynamic Activities on training X_Dynamic, Y_Dynamic = common.getDataSubset(XFull, YFull.flatten(), [4, 5, 6]) #Getting the dataset associated with Dynamic Activities on testing X_DynamicTest, Y_DynamicTest = common.getDataSubset( XFullTest, YFullTest.flatten(), [4, 5, 6]) X_Dynamic = common.getPowerK(X_Dynamic, [1, 2]) X_DynamicTest = common.getPowerK(X_DynamicTest, [1, 2]) #Fitting data using LDA classifier clf = LDA() clf.fit(X_Dynamic, Y_Dynamic.flatten()) precision, recall, fscore = common.checkAccuracy( clf.predict(X_DynamicTest), Y_DynamicTest, [4, 5, 6]) print( common.createConfusionMatrix( clf.predict(X_DynamicTest).flatten(), Y_DynamicTest.flatten(), [4, 5, 6])) print(fscore) ################################################################################################################################# #Getting the dataset associated with Dynamic Activities on training X_Dynamic, Y_Dynamic = common.getDataSubset(XFull, YFull.flatten(), [4, 5, 6]) #Getting the dataset associated with Dynamic Activities on testing X_DynamicTest, Y_DynamicTest = common.getDataSubset( XFullTest, YFullTest.flatten(), [4, 5, 6]) X_Dynamic = common.getPowerK(X_Dynamic, [1, 2, 3]) X_DynamicTest = common.getPowerK(X_DynamicTest, [1, 2, 3]) #Fitting data using LDA classifier clf = LDA() clf.fit(X_Dynamic, Y_Dynamic.flatten()) precision, recall, fscore = common.checkAccuracy( clf.predict(X_DynamicTest), Y_DynamicTest, [4, 5, 6]) print( common.createConfusionMatrix( clf.predict(X_DynamicTest).flatten(), Y_DynamicTest.flatten(), [4, 5, 6])) print(fscore)
Y_test = Y_test.flatten() ###################### # Hyper-parameters # #top_N = 5 ####################### # Pre-processing of data # print "Computing means and covariances" trainSubjects = [1,3,5,6,7,8,11,14,15,16,17,19,21,22,23,25,26,27,28,29,30] requiredLabels = [4,5,6] X_train = common.getPowerK( X_train, [1,2]) mean_array = [] cov_array = [] label_array = [] for i in trainSubjects: for j in requiredLabels: # Get subject info X_train_new , Y_train_new , subjectInfo= common.getSubjectData(X_train,Y_train,[i]) # Get Data Subset # X_train_new , Y_train_new = common.getDataSubset(X_train, Y_train, requiredLabels) mean,cov = common.getDistribution(X_train_new,Y_train_new,j)
X_train=common.parseFile(filename+'train/X_train.txt') # Read X Train Y_train=(common.parseFile(filename+'train/y_train.txt')).flatten() # Read Y Train and flatten it to 1D array X_test=common.parseFile(filename+'test/X_test.txt') # Read X Test Y_test=(common.parseFile(filename+'test/y_test.txt')).flatten() # Read Y test and flatten it to 1D array print len(X_train), len(Y_train) # Printing Lengths of Train and Test Data print len(X_test), len(Y_test) X_dynamic_train, Y_dynamic_train=common.getDataSubset(X_train, Y_train, [1,2,3]) # Get Train sub data for [1,2,3] X_nondynamic_train, Y_nondynamic_train=common.getDataSubset(X_train, Y_train, [4,5,6]) # Get Train sub data for [4,5,6] X_dynamic_test, Y_dynamic_test=common.getDataSubset(X_test, Y_test, [1,2,3]) # Get Test sub data for [1,2,3] X_nondynamic_test, Y_nondynamic_test=common.getDataSubset(X_test, Y_test, [4,5,6]) # Get Test sub data for [4,5,6] X_nondynamic_train=common.getPowerK(X_nondynamic_train, [1,2]) # Convert X Train to X+X^2 X_nondynamic_test=common.getPowerK(X_nondynamic_test, [1,2]) # Convert X Test to X+X^2 #X_nondynamic_train_6, Y_nondynamic_train_6=common.getDataSubset(X_train, Y_train, [6]) # Used earlier to get Sub data for just 6th label #X_nondynamic_test_6, Y_nondynamic_test_6=common.getDataSubset(X_test, Y_test, [6]) #Y_nondynamic_train_sublabels=common.convertLabel(Y_nondynamic_train, [4,5], [6]) # Used earlier to convert [4,5] to [1] and [6] to [0] #Y_nondynamic_test_sublabels=common.convertLabel(Y_nondynamic_test, [4,5], [6]) print len(X_dynamic_train), len(Y_dynamic_train), Y_dynamic_train # Printing lenghts and Labels extracted for verification print len(X_nondynamic_train), len(Y_nondynamic_train), Y_nondynamic_train sample_weights=common.getSampleWeights( X_nondynamic_train, Y_nondynamic_train , [4,5,6]) # Get sample weights for non-dynamic Data #print sample_weights ################################################################################################ #Code used for Dynamic Data - Commented for now
def LinearSVC_onData(): #Parsing Full training dataset XFull = common.parseFile('../UCI HAR Dataset/train/X_train.txt') YFull = common.parseFile('../UCI HAR Dataset/train/y_train.txt') #Parsing Full testing dataset XFullTest = common.parseFile('../UCI HAR Dataset/test/X_test.txt') YFullTest = common.parseFile('../UCI HAR Dataset/test/y_test.txt') ################################################################################################################################# #Getting the dataset associated with Dynamic Activities on training X_Dynamic, Y_Dynamic = common.getDataSubset(XFull, YFull.flatten(), [1, 2, 3, 4, 5, 6]) #Getting the dataset associated with Dynamic Activities on testing X_DynamicTest, Y_DynamicTest = common.getDataSubset( XFullTest, YFullTest.flatten(), [1, 2, 3, 4, 5, 6]) #Fitting data using LinearSVC classifier clf = LinearSVC(multi_class='crammer_singer') clf.fit(X_Dynamic, Y_Dynamic.flatten()) precision, recall, fscore = common.checkAccuracy(clf.predict(X_Dynamic), Y_Dynamic, [1, 2, 3, 4, 5, 6]) print common.createConfusionMatrix( clf.predict(X_Dynamic).flatten(), Y_Dynamic.flatten(), [1, 2, 3, 4, 5, 6]) #Fitting data using LinearSVC classifier clf = SVC(kernel="linear") clf.fit(X_Dynamic, Y_Dynamic.flatten()) precision, recall, fscore = common.checkAccuracy(clf.predict(X_Dynamic), Y_Dynamic, [1, 2, 3, 4, 5, 6]) print common.createConfusionMatrix( clf.predict(X_Dynamic).flatten(), Y_Dynamic.flatten(), [1, 2, 3, 4, 5, 6]) precision, recall, fscore = common.checkAccuracy( clf.predict(X_DynamicTest), Y_DynamicTest, [1, 2, 3, 4, 5, 6]) print common.createConfusionMatrix( clf.predict(X_DynamicTest).flatten(), Y_DynamicTest.flatten(), [1, 2, 3, 4, 5, 6]) print fscore ################################################################################################################################# #Getting the dataset associated with Dynamic Activities on training X_Dynamic, Y_Dynamic = common.getDataSubset(XFull, YFull.flatten(), [1, 2, 3, 4, 5, 6]) #Getting the dataset associated with Dynamic Activities on testing X_DynamicTest, Y_DynamicTest = common.getDataSubset( XFullTest, YFullTest.flatten(), [1, 2, 3, 4, 5, 6]) X_Dynamic = common.getPowerK(X_Dynamic, [1, 2]) X_DynamicTest = common.getPowerK(X_DynamicTest, [1, 2]) #Fitting data using LinearSVC classifier clf = SVC(kernel="linear") clf.fit(X_Dynamic, Y_Dynamic.flatten()) precision, recall, fscore = common.checkAccuracy( clf.predict(X_DynamicTest), Y_DynamicTest, [1, 2, 3, 4, 5, 6]) print common.createConfusionMatrix( clf.predict(X_DynamicTest).flatten(), Y_DynamicTest.flatten(), [1, 2, 3, 4, 5, 6]) print fscore ################################################################################################################################# #Getting the dataset associated with Dynamic Activities on training X_Dynamic, Y_Dynamic = common.getDataSubset(XFull, YFull.flatten(), [1, 2, 3, 4, 5, 6]) #Getting the dataset associated with Dynamic Activities on testing X_DynamicTest, Y_DynamicTest = common.getDataSubset( XFullTest, YFullTest.flatten(), [1, 2, 3, 4, 5, 6]) X_Dynamic = common.getPowerK(X_Dynamic, [1, 2, 3]) X_DynamicTest = common.getPowerK(X_DynamicTest, [1, 2, 3]) #Fitting data using LinearSVC classifier clf = SVC(kernel="linear") clf.fit(X_Dynamic, Y_Dynamic.flatten()) precision, recall, fscore = common.checkAccuracy( clf.predict(X_DynamicTest), Y_DynamicTest, [1, 2, 3, 4, 5, 6]) print common.createConfusionMatrix( clf.predict(X_DynamicTest).flatten(), Y_DynamicTest.flatten(), [1, 2, 3, 4, 5, 6]) print fscore ################################################################################################################################# #Getting the dataset associated with Dynamic Activities on training X_Dynamic, Y_Dynamic = common.getDataSubset(XFull, YFull.flatten(), [1, 2, 3]) #Getting the dataset associated with Dynamic Activities on testing X_DynamicTest, Y_DynamicTest = common.getDataSubset( XFullTest, YFullTest.flatten(), [1, 2, 3]) print len(X_DynamicTest), len(Y_DynamicTest) #Fitting data using LinearSVC classifier clf = SVC(kernel="linear") clf.fit(X_Dynamic, Y_Dynamic.flatten()) precision, recall, fscore = common.checkAccuracy( clf.predict(X_DynamicTest), Y_DynamicTest, [1, 2, 3]) print common.createConfusionMatrix( clf.predict(X_DynamicTest).flatten(), Y_DynamicTest.flatten(), [1, 2, 3]) print fscore ################################################################################################################################# #Getting the dataset associated with Dynamic Activities on training X_Dynamic, Y_Dynamic = common.getDataSubset(XFull, YFull.flatten(), [1, 2, 3]) #Getting the dataset associated with Dynamic Activities on testing X_DynamicTest, Y_DynamicTest = common.getDataSubset( XFullTest, YFullTest.flatten(), [1, 2, 3]) X_Dynamic = common.getPowerK(X_Dynamic, [1, 2]) X_DynamicTest = common.getPowerK(X_DynamicTest, [1, 2]) #Fitting data using LinearSVC classifier clf = SVC(kernel="linear") clf.fit(X_Dynamic, Y_Dynamic.flatten()) precision, recall, fscore = common.checkAccuracy( clf.predict(X_DynamicTest), Y_DynamicTest, [1, 2, 3]) print common.createConfusionMatrix( clf.predict(X_DynamicTest).flatten(), Y_DynamicTest.flatten(), [1, 2, 3]) print fscore ################################################################################################################################# #Getting the dataset associated with Dynamic Activities on training X_Dynamic, Y_Dynamic = common.getDataSubset(XFull, YFull.flatten(), [1, 2, 3]) #Getting the dataset associated with Dynamic Activities on testing X_DynamicTest, Y_DynamicTest = common.getDataSubset( XFullTest, YFullTest.flatten(), [1, 2, 3]) X_Dynamic = common.getPowerK(X_Dynamic, [1, 2, 3]) X_DynamicTest = common.getPowerK(X_DynamicTest, [1, 2, 3]) #Fitting data using LinearSVC classifier clf = SVC(kernel="linear") clf.fit(X_Dynamic, Y_Dynamic.flatten()) precision, recall, fscore = common.checkAccuracy( clf.predict(X_DynamicTest), Y_DynamicTest, [1, 2, 3]) print common.createConfusionMatrix( clf.predict(X_DynamicTest).flatten(), Y_DynamicTest.flatten(), [1, 2, 3]) print fscore ################################################################################################################################# #Getting the dataset associated with Non-Dynamic Activities on training X_NonDynamic, Y_NonDynamic = common.getDataSubset(XFull, YFull.flatten(), [4, 5, 6]) #Getting the dataset associated with Non-Dynamic Activities on testing X_NonDynamicTest, Y_NonDynamicTest = common.getDataSubset( XFullTest, YFullTest.flatten(), [4, 5, 6]) #Fitting data using LinearSVC classifier clf = SVC(kernel="linear") clf.fit(X_NonDynamic, Y_NonDynamic.flatten()) precision, recall, fscore = common.checkAccuracy( clf.predict(X_NonDynamicTest), Y_NonDynamicTest, [4, 5, 6]) print common.createConfusionMatrix( clf.predict(X_NonDynamicTest).flatten(), Y_NonDynamicTest.flatten(), [4, 5, 6]) print fscore ################################################################################################################################# #Getting the dataset associated with Dynamic Activities on training X_Dynamic, Y_Dynamic = common.getDataSubset(XFull, YFull.flatten(), [4, 5, 6]) #Getting the dataset associated with Dynamic Activities on testing X_DynamicTest, Y_DynamicTest = common.getDataSubset( XFullTest, YFullTest.flatten(), [4, 5, 6]) X_Dynamic = common.getPowerK(X_Dynamic, [1, 2]) X_DynamicTest = common.getPowerK(X_DynamicTest, [1, 2]) #Fitting data using LinearSVC classifier clf = SVC(kernel="linear") clf.fit(X_Dynamic, Y_Dynamic.flatten()) precision, recall, fscore = common.checkAccuracy( clf.predict(X_DynamicTest), Y_DynamicTest, [4, 5, 6]) print common.createConfusionMatrix( clf.predict(X_DynamicTest).flatten(), Y_DynamicTest.flatten(), [4, 5, 6]) print fscore ################################################################################################################################# #Getting the dataset associated with Dynamic Activities on training X_Dynamic, Y_Dynamic = common.getDataSubset(XFull, YFull.flatten(), [4, 5, 6]) #Getting the dataset associated with Dynamic Activities on testing X_DynamicTest, Y_DynamicTest = common.getDataSubset( XFullTest, YFullTest.flatten(), [4, 5, 6]) X_Dynamic = common.getPowerK(X_Dynamic, [1, 2, 3]) X_DynamicTest = common.getPowerK(X_DynamicTest, [1, 2, 3]) #Fitting data using LinearSVC classifier clf = SVC(kernel="linear") clf.fit(X_Dynamic, Y_Dynamic.flatten()) precision, recall, fscore = common.checkAccuracy( clf.predict(X_DynamicTest), Y_DynamicTest, [4, 5, 6]) print common.createConfusionMatrix( clf.predict(X_DynamicTest).flatten(), Y_DynamicTest.flatten(), [4, 5, 6]) print fscore
def LDA_onData(): #Parsing Full training dataset XFull = common.parseFile('../UCI HAR Dataset/train/X_train.txt') YFull = common.parseFile('../UCI HAR Dataset/train/y_train.txt') #Parsing Full testing dataset XFullTest = common.parseFile('../UCI HAR Dataset/test/X_test.txt') YFullTest = common.parseFile('../UCI HAR Dataset/test/y_test.txt') ################################################################################################################################# #Getting the dataset associated with Dynamic Activities on training X_Dynamic,Y_Dynamic = common.getDataSubset(XFull,YFull.flatten(),[1,2,3,4,5,6]) #Getting the dataset associated with Dynamic Activities on testing X_DynamicTest,Y_DynamicTest = common.getDataSubset(XFullTest,YFullTest.flatten(),[1,2,3,4,5,6]) #Fitting data using LDA classifier clf = LDA() clf.fit(X_Dynamic, Y_Dynamic.flatten()) precision,recall,fscore = common.checkAccuracy(clf.predict(X_DynamicTest),Y_DynamicTest,[1,2,3,4,5,6]) print common.createConfusionMatrix(clf.predict(X_DynamicTest).flatten(),Y_DynamicTest.flatten(),[1,2,3,4,5,6]) print fscore ################################################################################################################################# #Getting the dataset associated with Dynamic Activities on training X_Dynamic,Y_Dynamic = common.getDataSubset(XFull,YFull.flatten(),[1,2,3,4,5,6]) #Getting the dataset associated with Dynamic Activities on testing X_DynamicTest,Y_DynamicTest = common.getDataSubset(XFullTest,YFullTest.flatten(),[1,2,3,4,5,6]) X_Dynamic = common.getPowerK(X_Dynamic,[1,2]) X_DynamicTest = common.getPowerK(X_DynamicTest,[1,2]) #Fitting data using LDA classifier clf = LDA() clf.fit(X_Dynamic, Y_Dynamic.flatten()) precision,recall,fscore = common.checkAccuracy(clf.predict(X_DynamicTest),Y_DynamicTest,[1,2,3,4,5,6]) print common.createConfusionMatrix(clf.predict(X_DynamicTest).flatten(),Y_DynamicTest.flatten(),[1,2,3,4,5,6]) print fscore ################################################################################################################################# #Getting the dataset associated with Dynamic Activities on training X_Dynamic,Y_Dynamic = common.getDataSubset(XFull,YFull.flatten(),[1,2,3,4,5,6]) #Getting the dataset associated with Dynamic Activities on testing X_DynamicTest,Y_DynamicTest = common.getDataSubset(XFullTest,YFullTest.flatten(),[1,2,3,4,5,6]) X_Dynamic = common.getPowerK(X_Dynamic,[1,2,3]) X_DynamicTest = common.getPowerK(X_DynamicTest,[1,2,3]) #Fitting data using LDA classifier clf = LDA() clf.fit(X_Dynamic, Y_Dynamic.flatten()) precision,recall,fscore = common.checkAccuracy(clf.predict(X_DynamicTest),Y_DynamicTest,[1,2,3,4,5,6]) print common.createConfusionMatrix(clf.predict(X_DynamicTest).flatten(),Y_DynamicTest.flatten(),[1,2,3,4,5,6]) print fscore ################################################################################################################################# #Getting the dataset associated with Dynamic Activities on training X_Dynamic,Y_Dynamic = common.getDataSubset(XFull,YFull.flatten(),[1,2,3]) #Getting the dataset associated with Dynamic Activities on testing X_DynamicTest,Y_DynamicTest = common.getDataSubset(XFullTest,YFullTest.flatten(),[1,2,3]) print len(X_DynamicTest),len(Y_DynamicTest) #Fitting data using LDA classifier clf = LDA() clf.fit(X_Dynamic, Y_Dynamic.flatten()) precision,recall,fscore = common.checkAccuracy(clf.predict(X_DynamicTest),Y_DynamicTest,[1,2,3]) print common.createConfusionMatrix(clf.predict(X_DynamicTest).flatten(),Y_DynamicTest.flatten(),[1,2,3]) print fscore ################################################################################################################################# #Getting the dataset associated with Dynamic Activities on training X_Dynamic,Y_Dynamic = common.getDataSubset(XFull,YFull.flatten(),[1,2,3]) #Getting the dataset associated with Dynamic Activities on testing X_DynamicTest,Y_DynamicTest = common.getDataSubset(XFullTest,YFullTest.flatten(),[1,2,3]) X_Dynamic = common.getPowerK(X_Dynamic,[1,2]) X_DynamicTest = common.getPowerK(X_DynamicTest,[1,2]) #Fitting data using LDA classifier clf = LDA() clf.fit(X_Dynamic, Y_Dynamic.flatten()) precision,recall,fscore = common.checkAccuracy(clf.predict(X_DynamicTest),Y_DynamicTest,[1,2,3]) print common.createConfusionMatrix(clf.predict(X_DynamicTest).flatten(),Y_DynamicTest.flatten(),[1,2,3]) print fscore ################################################################################################################################# #Getting the dataset associated with Dynamic Activities on training X_Dynamic,Y_Dynamic = common.getDataSubset(XFull,YFull.flatten(),[1,2,3]) #Getting the dataset associated with Dynamic Activities on testing X_DynamicTest,Y_DynamicTest = common.getDataSubset(XFullTest,YFullTest.flatten(),[1,2,3]) X_Dynamic = common.getPowerK(X_Dynamic,[1,2,3]) X_DynamicTest = common.getPowerK(X_DynamicTest,[1,2,3]) #Fitting data using LDA classifier clf = LDA() clf.fit(X_Dynamic, Y_Dynamic.flatten()) precision,recall,fscore = common.checkAccuracy(clf.predict(X_DynamicTest),Y_DynamicTest,[1,2,3]) print common.createConfusionMatrix(clf.predict(X_DynamicTest).flatten(),Y_DynamicTest.flatten(),[1,2,3]) print fscore ################################################################################################################################# #Getting the dataset associated with Non-Dynamic Activities on training X_NonDynamic,Y_NonDynamic = common.getDataSubset(XFull,YFull.flatten(),[4,5,6]) #Getting the dataset associated with Non-Dynamic Activities on testing X_NonDynamicTest,Y_NonDynamicTest = common.getDataSubset(XFullTest,YFullTest.flatten(),[4,5,6]) #Fitting data using LDA classifier clf = LDA() clf.fit(X_NonDynamic, Y_NonDynamic.flatten()) precision,recall,fscore = common.checkAccuracy(clf.predict(X_NonDynamicTest),Y_NonDynamicTest,[4,5,6]) print common.createConfusionMatrix(clf.predict(X_NonDynamicTest).flatten(),Y_NonDynamicTest.flatten(),[4,5,6]) print fscore ################################################################################################################################# #Getting the dataset associated with Dynamic Activities on training X_Dynamic,Y_Dynamic = common.getDataSubset(XFull,YFull.flatten(),[4,5,6]) #Getting the dataset associated with Dynamic Activities on testing X_DynamicTest,Y_DynamicTest = common.getDataSubset(XFullTest,YFullTest.flatten(),[4,5,6]) X_Dynamic = common.getPowerK(X_Dynamic,[1,2]) X_DynamicTest = common.getPowerK(X_DynamicTest,[1,2]) #Fitting data using LDA classifier clf = LDA() clf.fit(X_Dynamic, Y_Dynamic.flatten()) precision,recall,fscore = common.checkAccuracy(clf.predict(X_DynamicTest),Y_DynamicTest,[4,5,6]) print common.createConfusionMatrix(clf.predict(X_DynamicTest).flatten(),Y_DynamicTest.flatten(),[4,5,6]) print fscore ################################################################################################################################# #Getting the dataset associated with Dynamic Activities on training X_Dynamic,Y_Dynamic = common.getDataSubset(XFull,YFull.flatten(),[4,5,6]) #Getting the dataset associated with Dynamic Activities on testing X_DynamicTest,Y_DynamicTest = common.getDataSubset(XFullTest,YFullTest.flatten(),[4,5,6]) X_Dynamic = common.getPowerK(X_Dynamic,[1,2,3]) X_DynamicTest = common.getPowerK(X_DynamicTest,[1,2,3]) #Fitting data using LDA classifier clf = LDA() clf.fit(X_Dynamic, Y_Dynamic.flatten()) precision,recall,fscore = common.checkAccuracy(clf.predict(X_DynamicTest),Y_DynamicTest,[4,5,6]) print common.createConfusionMatrix(clf.predict(X_DynamicTest).flatten(),Y_DynamicTest.flatten(),[4,5,6]) print fscore