Code example of implementing random forest in python

Answer: Python can be used to build random forests. For example, you can use the RandomForestClassifier class in the scikit-learn library, as shown in the following code: from sklearn.ensemble import RandomForestClassifier # Initialize the rf model clf = RandomForestClassifier(n_estimators=100, random_state=0) # Training model clf.fit(X_train, y_train) # Prediction result y_pred = clf.predict(X_test)

Guess you like

Origin blog.csdn.net/weixin_42605397/article/details/129577739
Recommended