Beispiel #1
0
    X[:, :, 2, :] = allZCoordinates - meanValue
    return X


train3 = ReduceData(train3)
train4 = ReduceData(train4)
test3 = ReduceData(test3)
test4 = ReduceData(test4)

train3 = CenterData(train3)
train4 = CenterData(train4)
test3 = CenterData(test3)
test4 = CenterData(test4)

trainX, trainy = ReshapeData(train3, train4)
testX, testy = ReshapeData(test3, test4)

knn = knn.KNN()
knn.Use_K_Of(15)
knn.Fit(trainX, trainy)

correctPredictions = 0
for row in range(0, 2000):
    actualClass = testy[row]
    prediction = knn.Predict(testX[row])
    if (actualClass == prediction):
        correctPredictions = correctPredictions + 1

print(correctPredictions)
print((correctPredictions / 2000) * 100)
Beispiel #2
0
test2 = CenterData(test2)
test3 = CenterData(test3)
test4 = CenterData(test4)
test5 = CenterData(test5)
test6 = CenterData(test6)
test7 = CenterData(test7)
test8 = CenterData(test8)
test9 = CenterData(test9)
test0 = CenterData(test0)

trainX, trainY = ReshapeData(train1, train2, train3, train4, train5, train6,
                             train7, train8, train9, train0)
testX, testY = ReshapeData(test1, test2, test3, test4, test5, test6, test7,
                           test8, test9, test0)

knn = knn.KNN()
knn.Use_K_Of(15)
knn.Fit(trainX, trainY)

correct = 0
for row in range(0, 10000):
    prediction = int(knn.Predict(testX[row]))
    answer = int(testY[row])
    if prediction == answer:
        correct += 1
    print prediction, answer, correct, '/', row
print "accuracy of", (float(correct) /
                      float(10000)) * float(100), '%', "(", correct, "Right )"

pickle.dump(knn, open('userData/classifer.p', 'wb'))