[Tutor] ValueError: Unable to coerce to DataFrame, shape must be (842, 1): given (3367, 1); ValueError: cannot reshape array of size 1 into shape (4)
Alan Gauld
alan.gauld at yahoo.co.uk
Mon Mar 29 04:47:46 EDT 2021
On 29/03/2021 08:04, Anosh Kaniskar wrote:
Hi Anosh,
The tutor list is focused on the Python language and its standard
library. This question seems to be entirely about sklearn and Pandas
so you might get a better result asking on the SciPy forum which
supports Pandas.
However, there are some pandas users here so you may get lucky...
> So, before using any model, i performed pca technique to deal with the
> curse of dimensionality, and I started with the multiple linear regression
> model and Im not satisfied with the outcome, so I started using Random
> Forest and I successfully fitted the data on to the random forest model
> for eg:
> from sklearn.ensemble import RandomForestRegressor
> RFReg = RandomForestRegressor(n_estimators=500,max_depth=4, random_state =
> 50)
> RFReg.fit(X_train, y_train)
>
> y_pred_train = RFReg.predict(X_train)
> y_pred_train
> ____________________________________________
> errors = abs(y_test - y_pred_train)
> errors
> This code gave me an error
>
> ~/Desktop/Desktop/anaconda3/lib/python3.8/site-packages/pandas/core/ops/__init__.py
> in _align_method_FRAME(left, right, axis) 661 662
> else:--> 663 raise ValueError( 664
> "Unable to coerce to DataFrame, shape " 665
> f"must be {left.shape}: given {right.shape}"
>
>
> ValueError: Unable to coerce to DataFrame, shape must be (842, 1):
> given (3367, 1)
>
> _______________________________________________
>
>
> So later I tried
>
> y_pred_train = y_pred_train.reshape(3367, 1)
>
>
> Here I'm looking for explanation for what is going wrong..
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list