text_plain_output_1.png
from sklearn.ensemble import RandomForestClassifier

from sklearn.metrics import accuracy_score

from sklearn.metrics import confusion_matrix, precision_score, plot_confusion_matrix

from sklearn.metrics import precision_recall_curve, plot_precision_recall_curve

import matplotlib.pyplot as plt

import matplotlib.pyplot as plt

best_score = -1
best_estimators = 0
for i in range(10, 250):
    model = RandomForestClassifier(n_estimators=i, random_state=0)
    model.fit(train_x, train_y)
    pred = model.predict(test_x)
    score = accuracy_score(pred, test_y)
    if score > best_score:
        best_score = score
        best_estimators = i

model = RandomForestClassifier(n_estimators=best_estimators, random_state=0)

model.fit(train_x, train_y)

pred = model.predict(test_x)
score = accuracy_score(pred, test_y)

from sklearn.metrics import confusion_matrix, precision_score, plot_confusion_matrix
import matplotlib.pyplot as plt

from sklearn.metrics import precision_recall_curve, plot_precision_recall_curve
y_pred_prob = model.predict_proba(val_x)[:, 1]
precision, recall, thresholds = precision_recall_curve(val_y, y_pred_prob)
plt.plot(recall, precision, label='Random Forest')
plt.xlabel('Recall')
plt.ylabel('Precision')
plt.plot([0, 1], [0.68837209, 0.68837209], label='Baseline')
plt.legend()
plt.show()