0
$\begingroup$

This error I facing and shows for every value of my column''' 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)) '''

$\endgroup$

1 Answer 1

0
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ Thanks for helping me. $\endgroup$
    – Ibad Khan
    Sep 29, 2022 at 10:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.