Python random forest

Assume the data is in two arrays for X (independent variables) and Y (dependent variable).

Training #

from sklearn.ensemble import RandomForestClassifier

rf=RandomForestClassifier(n_estimators=100)

rf.fit(X_train, y_train)

Assessment #

Accuracy:

from sklearn import metrics

print(metrics.accuracy_score(y_test, y_pred))

Feature Importance #

rf.feature_importances_

Resources #