Implementation Example

from sklearn.ensemble import RandomForestClassifier
 
# Initialize model
rf = RandomForestClassifier(
    n_estimators=200,
    max_depth=10,
    min_samples_split=5,
    max_features='sqrt',
    oob_score=True,
    random_state=42,
    n_jobs=-1
)
 
# Train
rf.fit(X_train, y_train)
 
# Evaluate
train_score = rf.score(X_train, y_train)
test_score = rf.score(X_test, y_test)
oob_score = rf.oob_score_
 
# Feature importance
importances = rf.feature_importances_