Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
473 B
1
Indexable
Never
def train_and_eval_knn(x_train, y_train, x_test, y_test, k_values):
    for k in k_values:
        knn_classifier = KNeighborsClassifier(n_neighbors=k, weights='distance', metric = 'euclidean')
        knn_classifier.fit(x_train,y_train)
        y_pred_knn = knn_classifier.predict(x_test)
        print(f'\nEvaluattion for k={k}:')
        eval_classifier(y_test, y_pred_knn)
        
k_values = list(range(1,11))
train_and_eval_knn(x_train,y_train,x_test,y_test,k_values)
Leave a Comment