Heart Disease Using K-NN

0 votes
error = []

# calculation error for K values between 1 and 30

for i in range(1,30):
    
    knn = KNeighborsClassifier(n_neighbors=i)
    
    knn.fit(x_train, y_train)
    
    pred_i = knn.predict(x_test)
    
    error.append(np.mean(pred_i !=y_test))
    
plt.figure(figsize=(12,6))

plt.plot(range(1,30),error,color='red',linestyle='dashed',marker='o',marker_size=102)

plt.xlable('K value')

plt.ylable('Mean Error')

print("Minimumerror:-",min(error),"at K",error.index(min(error))+1)
Sep 15, 2022 in Data Science by Himanshu

edited Mar 4 38 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP