Created
January 7, 2021 21:36
-
-
Save Guidosalimbeni/484a9c0c0349f0b0e27142289dab78f4 to your computer and use it in GitHub Desktop.
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
def main(): | |
# prepare data | |
trainingSet=df.values.tolist()[:18] | |
testSet=df.values.tolist()[19:] | |
print ('Train set: ' + repr(len(trainingSet))) | |
print ('Test set: ' + repr(len(testSet))) | |
# generate predictions | |
predictions=[] | |
k = 3 | |
for x in range(len(testSet)): | |
neighbors = getNeighbors(trainingSet, testSet[x], k) | |
result = getResponse(neighbors) | |
predictions.append(result) | |
print('> predicted=' + repr(result) + ', actual=' + repr(testSet[x][-1])) | |
accuracy = getAccuracy(testSet, predictions) | |
print('Accuracy: ' + repr(accuracy) + '%') | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment