在运行此代码部分时,我收到此错误

时间:2020-03-18 14:09:28

标签: python scikit-learn

出现此错误:NameError:未定义名称'train_predict'

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) )))

0 个答案:

没有答案