0
fruit_prediction = knn.predict([[20, 4.3, 5.5]])

lookup_fruit_name[fruit_prediction[0]]

I am not able to run above two lines. I am getting this kind of error

ValueError: query data dimension must match training data dimension

1 Answers1

0

Checking the inputs of knn classifier would be good option to analysed what is wrong in the dimensions of knn.predict. As you have nested list in your predict as inputs that can be just a list.

deepak sen
  • 437
  • 4
  • 13
  • for knn.predit first I am doing fit for it which is `knn.fit(X_train, y_train)` and fruit_prediction is just a temp variable I am assigning it too. – Anshu Goyal Jun 08 '20 at 14:34
  • can you try this knn.predict([[20], [4.3], [5.5]]) – deepak sen Jun 08 '20 at 14:38
  • can you tell me the X_train dimensions as from the documentation x_train looks like this X = [[0], [1], [2], [3]] and they are using predict function as this knn.predict([[1.1]]), so you can need to look at X_train sample once. – deepak sen Jun 08 '20 at 14:54
  • My x values looks like `X = fruits[['mass', 'width', 'height']]` so in order my 20g is my mass, 4.3cm width and 5.5cm height – Anshu Goyal Jun 08 '20 at 14:57
  • it kind of getting complicated here, what is fruits here. if it possible to upload the complete code please update the question – deepak sen Jun 08 '20 at 15:00
  • It's long and plus I am doing it on Jupyter Notebook. If you feel like we communicate via discord or any other platform in order that I can screen share and you can look at my code? – Anshu Goyal Jun 08 '20 at 15:06
  • just print x train and observe the data that will resolve the problem – deepak sen Jun 08 '20 at 15:10
  • That's the whole output I am getting, I trying to find out the fruit label after passing those parameters – Anshu Goyal Jun 08 '20 at 15:15
  • according to what you have told fruit_prediction = knn.predict([[20, 4.3, 5.5], [20, 4.4, 5.6]]) sholud have worked – deepak sen Jun 08 '20 at 16:10
  • Yes, maybe the issue is with the version I guess – Anshu Goyal Jun 08 '20 at 16:12