[Python] Random Forest Strategy for Imbalanced Data

Discussão em 'Python' iniciado por Stack, Abril 17, 2025.

  1. Stack

    Stack Membro Participativo

    Basically this is my code, but my accuracy score is around 50%. There are 565 positives and around 13000 negatives in my dataset. How would I fix the accuracy without undergoing possible bias?

    import matplotlib.pyplot as plt
    from sklearn.ensemble import RandomForestClassifier
    from imblearn.over_sampling import SMOTE

    #Build SMOTE SRF model
    SMOTE_SRF = RandomForestClassifier(n_estimators=150, random_state=0)

    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.1, stratify=y)

    SMOTE_SRF.fit(X_train,y_train)
    #SMOTE SRF prediction result
    y_pred = SMOTE_SRF.predict(X_test)

    Continue reading...

Compartilhe esta Página