'How to fix ValueError: Found array with 0 sample(s)
I am really new to python trying to run a linear regression using sklearn, when I try to train the model:
regressIt.fit(X_train, Y_train)
It throws the following exception:
ValueError: Found array with 0 sample(s) (shape=(0, 546)) while a minimum of 1 is required.
What am I doing wrong?
Thanks in Advance.
Solution 1:[1]
Ok I think I figured it out
X=np.array(X).reshape((-1,1)) Should be this instead of ((1,-1)) Not sure why yet?
Y=np.array(Y).reshape((-1,1))
#Also this
print(str(regr.predict(X_test)))
Solution 2:[2]
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.3)
# don't keep the testing data 0 i gave 30% for example,
# for this add the next line in import
from sklearn.model_selection import train_test_split
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | RobD |
Solution 2 | Kadir ?ahbaz |