2
When using Kneighborsclassifier, I am getting the following error:
/Feature Extraction (Python)/KNNpy:58: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().
knn.fit(trade_conj, trade_label)
Traceback (most recent call last):
File "/Feature Extraction (Python)/KNNpy", line 61, in <module>
pred = knn.predict(features[i, :])#processo KNN
File "\Python\Python37\lib\site-packages\sklearn\neighbors\_classification.py", line 171, in predict
X = check_array(X, accept_sparse='csr')
File "\Python\Python37\lib\site-packages\sklearn\utils\validation.py", line 556, in check_array "if it contains a single sample.".format(array))
ValueError: Expected 2D array, got 1D array instead: array=[0. 0. 0. ... 0. 0. 0.].
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.
I’m working with a matrix "Features" (22x2048) from the characteristic extraction process.
and an array "Labels" 1x22 representing the labels.
trade_conj="Features" and trade_labbel="Labels"
I am not intimate with python, however, this code is a "translation"(?) of another code in Matlab that uses the same array and matrix and works normally.
that’s right, I was able to solve the problem with:
Y_training = Y_training.values.ravel()
Thank you !– David Jordão