我想使用KNN进行图像泥浆化。我使用制作模型。我有20张狗类别中的10张图像,而猫类类别有10张图像。我很难将模型进入KNN算法,我的编码存在问题。这是我的代码:
knn_model=KNeighborsClassifier(n_neighbors=3) #define K=3
X_train, X_test, y_train, y_test = train_test_split(X,y, test_size=0.3, random_state=0)
predict_knn=knn_model.predict(X_test)
print(predict_knn)
有一个错误:找到的输入变量,示例数量不一致:[60,20]
我需要您的意见如何修复此代码。谢谢。
I want to make image clasification using KNN. i use https://pythonprogramming.net/loading-custom-data-deep-learning-python-tensorflow-keras/ to make a model. i have 20 image which 10 image in dog category and 10 image in cat category. I'm having trouble entering the model into the KNN algorithm,there is a problem in my coding. this is my code:
knn_model=KNeighborsClassifier(n_neighbors=3) #define K=3
X_train, X_test, y_train, y_test = train_test_split(X,y, test_size=0.3, random_state=0)
predict_knn=knn_model.predict(X_test)
print(predict_knn)
there is an error : found input variables with inconsistent numbers of samples: [60, 20]
I need your opinion how to fix this code. thank you.
发布评论
评论(1)
问题可能是由于
x
和y
的不一致的样本尺寸。1。
len(y)== 20
2。
len(y)== 60
第二个脚本会产生以下错误。
The problem could be due to the inconsistent sample size of
X
andy
.1.
len(y) == 20
2.
len(y) == 60
The second script produces the below error.