def check_log_loss(max_depth, n_splits, test_size):
model = RandomForestClassifier(max_depth=max_depth, n_jobs=-1, random_state=777)
trn_scores = []
vld_scores = []
sss = StratifiedShuffleSplit(n_splits=n_splits, test_size=test_size, random_state=777)
for i, (t_ind, v_ind) in enumerate(sss.split(feature_train, trainY)):
print('# Iter {} / {}'.format(i + 1, n_splits))
x_trn = feature_train.values[t_ind]
y_trn = trainY[t_ind]
x_vld = feature_train.values[v_ind]
y_vld = trainY[v_ind]
model.fit(x_trn, y_trn)
score = log_loss(y_trn, model.predict_proba(x_trn))
trn_scores.append(score)
score = log_loss(y_vld, model.predict_proba(x_vld))
vld_scores.append(score)
print("max_depth: %d n_splits: %d test_size: %f" % (max_depth, n_splits, test_size))
print('# TRN logloss: {}'.format(np.mean(trn_scores)))
print('# VLD logloss: {}'.format(np.mean(vld_scores)))
B_4_find_FR_with_for.py 文件源码
python
阅读 21
收藏 0
点赞 0
评论 0
评论列表
文章目录