Skip to content

Instantly share code, notes, and snippets.

@Guidosalimbeni
Created January 7, 2021 21:36
Show Gist options
  • Save Guidosalimbeni/484a9c0c0349f0b0e27142289dab78f4 to your computer and use it in GitHub Desktop.
Save Guidosalimbeni/484a9c0c0349f0b0e27142289dab78f4 to your computer and use it in GitHub Desktop.
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