''' from sklearn.ensemble import RandomForestClassifier forest = RandomForestClassifier(n_estimators = 500, max_depth = None, min_samples_split=2, min_samples_leaf =1, bootstrap = True, random_state=0) forest = forest.fit(X_train, y_train) print(forest.score(X_test, y_test)) '''
1 Answer
The error message is not lying to you :) It cannot convert the string "one favourite christmas gifts year love" to a float.
RandomForestClassifier
(as most scikit-learn models) requires its inputs to be numeric. It does not know how to handle strings of text. Your training data has at least one column that contains string values. When the model tries to convert the training data to numeric values, the error is thrown when it encounters a string.
You need to either encode the string values as numbers (e.g. with a text embedding model like Word2Vec) or drop the columns containing strings prior to training.