0

Im getting this error: NameError: name 'train_predict' is not defined

from sklearn.neighbors  import KNeighborsClassifier
    X_train_cv, X_test_cv, y_train_cv, y_test_cv = train_test_split(X_train, y_train, test_size = 0.3, random_state=100)
    neighbors = []
    accuracy = []
    for n in range(3,10):    
        knn = KNeighborsClassifier(n_neighbors=n)
        print("Number of neighbors is: {}".format(n))
        train_predict(knn, X_train_cv, y_train_cv, X_test_cv, y_test_cv)
        clf_ = knn.fit(X_train, y_train)
        y_pred = clf_.predict(X_test)
        neighbors.append(n)
        accuracy.append( str(("%.2f" 

    %(accuracy_score(y_test,y_pred)* 100) )))
Asif
  • 9
  • 2
  • please formulate a proper question – bwright Mar 18 '20 at 14:20
  • 1
    Welcome to [so]! Unfortunately, your code actually does not show any attempt to define or import it… Please [edit] your question to explain what makes you think it should have been defined at the place where it’s used. – Melebius Mar 18 '20 at 14:23
  • 1
    please define or import `train_predict(...)` function in ur code – Jaydeep Devda Mar 19 '20 at 05:15
  • Does this answer your question? [function is not defined error in Python](https://stackoverflow.com/questions/5986860/function-is-not-defined-error-in-python) – Melebius Mar 19 '20 at 16:04

0 Answers0