Beispiel #1
0
from sklearn.model_selection import cross_val_score

scores = cross_val_score(clftree, d_train_att, d_train_label, cv=5)

skor_rata2 = scores.mean()
skoresd = scores.std()

#%%soal 8

max_features_opts = range(
    5, 50, 5)  #max_features_opts sebagai variabel untuk membuat range 5,50,5
n_estimators_opts = range(
    10, 200,
    20)  #n_estimators_opts sebagai variabel untuk membuat range 10,200,20
rf_params = oni.empty(
    (len(max_features_opts) * len(n_estimators_opts), 4), float
)  #rf_params sebagai variabel untuk menjumlahkan yang sudah di tentukan sebelumnya
i = 0
for max_features in max_features_opts:  #pengulangan
    for n_estimators in n_estimators_opts:  #pengulangan
        clftree = RandomForestClassifier(
            max_features=max_features,
            n_estimators=n_estimators)  #menampilkan variabel csf
        scores = cross_val_score(clf, df_train_att, df_train_label,
                                 cv=5)  #scores sebagai variabel training
        rf_params[i, 0] = max_features  #index 0
        rf_params[i, 1] = n_estimators  #index 1
        rf_params[i, 2] = scores.mean()  #index 2
        rf_params[i, 3] = scores.std() * 2  #index 3
        i += 1  #dengan ketentuan i += 1
        print(
Beispiel #2
0
#%%soal 7

from sklearn.model_selection import cross_val_score

scores = cross_val_score(clftree, d_train_att, d_train_label, cv=5)

skor_rata2 = scores.mean()
skoresd = scores.std()

#%%soal 8 /

max_features_opts = range(5, 50, 5)
#membuat max_features_opts sebagai variabel untuk membuat range 5,50,5
n_estimators_opts = range(10, 200, 20)
#membuat n_estimators_opts sebagai variabel untuk membuat range 10,200,20
rf_params = gani.empty((len(max_features_opts) * len(n_estimators_opts), 4),
                       float)
#membuat rf_params sebagai variabel untuk menjumlahkan yang sudah di tentukan sebelumnya
i = 0
for max_features in max_features_opts:
    #sebagai pengulangan
    for n_estimators in n_estimators_opts:
        #sebagai pengulangan
        clftree = RandomForestClassifier(
            max_features=max_features,
            n_estimators=n_estimators)  #menampilkan variabel csf
        scores = cross_val_score(clf, df_train_att, df_train_label, cv=5)
        #membuat scores sebagai variabel training
        rf_params[i, 0] = max_features  #index 0
        rf_params[i, 1] = n_estimators  #index 1
        rf_params[i, 2] = scores.mean()  #index 2
        rf_params[i, 3] = scores.std() * 2  #index 3