I am trying to build a regression model using Randomforest. My training data shape :
X_train.shape = (8,7) # 8 is the no. of samples -- 7 is the number of features
y_train.shape = (8,100) # 8 is the no. of samples -- 100 is the output array size
After fitting the model
model = RandomForestRegressor(n_estimators = 300, random_state=30)
model.fit(X, y)
And while predicting the output for a single new sample
X_test.shape = (1,7)
I am getting an output shape of (8,100) instead of (1,100). What is the issue here?
CodePudding user response:
Maybe you are passing X_train to the predict method and not X_test, check you code for typos.
I verified this by creating a model based on random data. It is working as expected.
Here you go
from sklearn.ensemble import RandomForestRegressor
import sklearn
print(sklearn.__version__)
X_train = np.random.random((8,7))
y_train = np.random.random((8,100))
print(X_train.shape, y_train.shape)
model = RandomForestRegressor(n_estimators = 300, random_state=30)
model.fit(X_train, y_train)
X_test = np.random.random((1,7))
predictions = model.predict(X_test) # Make sure it is X_test and not X_train
print(predictions.shape)