Untitled

mail@pastecode.io avatar
unknown
plain_text
6 months ago
628 B
2
Indexable
Never
# Let's see if repeat number we have chosen is the best if we are looking to repeat between 1-20 times
best_f1 = 0
best_repeat = 1

for repeat in range(1, 20):
    features_upsampled, target_upsampled = upsample(features_train, target_train, repeat)
    model = RandomForestClassifier(random_state=1234, n_estimators=100)
    model.fit(features_upsampled, target_upsampled)
    predicted_valid = model.predict(features_valid)
    f1 = f1_score(target_valid, predicted_valid)
    
    if f1 > best_f1:
        best_f1 = f1
        best_repeat = repeat

print("Best F1 Score:", best_f1)
print("Optimal Repeat Value:", best_repeat)
Leave a Comment