TransWikia.com

Question about reshaping array size for KNN Classifiers

Data Science Asked by LeeAnn Capistran on January 31, 2021

I keep trying to run a new set of data through my KNN Classifier but would recieve the message:

 ValueError: query data dimension must match training data dimension

It then used:

x_new = pd.read_csv('NewFeaturePractice.csv' , names = attributes)    
x_new = x_new.values.reshape(52,84) 

(which is the dimensions of the training data) but would then receive:

ValueError: cannot reshape array of size 672 into shape (52,84)

The second data set doesn’t have the same amount of rows as the first meaning that even if I tried reshaping the array I would have several empty spaces. How can I run the code so that no matter the size of my new data set, I can still get results?

One Answer

Seems you are making two mistakes -
Reshaping dim. is mismatched with the size i.e. 10 != 3X3
Dim in train and test are different. Trained of 5 features and testing on 4 features.

What I will suggest -
You would be aware of your features count - let's say N
then reshape using reshape(-1,N). It will automatically decide the first dim.

x = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
N=2
x.reshape(-1,N)

Answered by 10xAI on January 31, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP