[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)

Anosh Kaniskar akrocks889 at gmail.com
Mon Mar 29 03:04:31 EDT 2021


Hi
Everyone,

Mercedes Benz Project, where  you need to cut the time a Mercedes Benz
spends on the test bench..
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..



Regards

Anosh K


More information about the Tutor mailing list