Untitled

 avatar
unknown
plain_text
2 years ago
685 B
3
Indexable
# Let's train a random forest model

best_score = 0
best_est = 0
for est in range(10,101,10):
    model = RandomForestClassifier(random_state=1234,n_estimators=est)
    model.fit(features_train,target_train)
    score = model.score(features_valid,target_valid)
    if score>best_score:
        best_score = score
        best_est = est
print("Accuracy of the best on the validation set (n_estimators = {})".format(best_est,best_score))

RFmodel = RandomForestClassifier(random_state=1234,n_estimators=100)
RFmodel.fit(features_train,target_train)
RFpredic_valid = RFmodel.predict(features_valid)
RFprob_valid = RFmodel.predict_proba(features_valid)
RFprob_one_valid = RFprob_valid[:,1]
Editor is loading...
Leave a Comment