Im new to python and sklearn and im still trying to figure out What exactly does lambda do and how would I go about getting the scores from my test data set, if anyone has any helpful tips that would be great, thank you!
Question: Now we will write a function that will initialize, fit and return score on test data for given values of k and Plot result Use values from 1 to 25(inclusive) and get score and plot as a bar graph Hint : you can use map or you can use simple loops
import matplotlib.pyplot as plt
from sklearn.metrics import confusion_matrix
def returnScore(k, xtrain, xtest, ytrain, ytest):
knn = KNeighborsClassifier(n_neighbors=k)
knn.fit(xtrain, ytrain)
return knn.score(xtest, ytest)
result = [*map(lambda i:returnScore(i,?,?,?,?), range(1,25))]
print(result)
plt.plot(result)