Hope this might help beginners while doing prediction on unseen data by model
Your X
and y
is a pandas dataframe. Before fitting it to Random forest classifier make it a numpy array like,
X = X.valuesy = y.values
After this do the train test split,
from sklearn.model_selection import train_test_splitX_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.3,random_state=0)
Now Fit the model (the code is same as yours below),
from sklearn.ensemble import RandomForestClassifierrandom = RandomForestClassifier()random.fit(X_train,y_train)y_pred=random.predict(X_test)
In the flask app, you are giving input in numpy array but during the training you have pandas dataframe that's why that warning was raised. Now, it should work properly!