text_html_output_2.png text_plain_output_2.png text_plain_output_1.png
from sklearn.ensemble import RandomForestClassifier

from sklearn.metrics import precision_score

from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import precision_score
import xgboost as xgb
def build_random_forest(x_train, y_train, x_test, y_test, n_estimators):
    rndforest = RandomForestClassifier(n_estimators=n_estimators, n_jobs=-1)
    rndforest.fit(x_train, y_train)
    print('Cantidad de estimadores:', n_estimators)
    print('TRAINING ACCURACY:', rndforest.score(x_train, y_train))
    mean_score = rndforest.score(x_test, y_test)
    print('Accuracy: ', mean_score)
    print('-------------------------------------')
    precision = precision_score(y_test, rndforest.predict(x_test), average='macro')
    print('Precisión del Random Forest: ', precision)
build_random_forest(x_train, y_train.values.ravel(), x_test, y_test.values.ravel(), n_estimators=250)