def calculate(X, y, threshold):
best_t, best_score = 0, -float('inf')
kf = KFold(len(y), n_folds=5, random_state=1, shuffle=True)
for t in xrange(1, 51):
clf = RandomForestRegressor(n_estimators=t, random_state=1)
score = np.mean(cross_val_score(clf, X, y, cv=kf, scoring='r2'))
if score > threshold:
return t
评论列表
文章目录