【发布时间】:2019-03-31 09:14:55
【问题描述】:
我正在使用GridSearchCV 根据LinearRegression() 返回的MSE 找到PolynomialFeature 的最佳度数。
在 GridSearchCV 之前,我首先使用了一个循环,当 MSE >10K 时该循环停止。
为了时间优化,我如何使用GridSearchCV() 实现相同类型的“退出循环”?
skf2 = StratifiedShuffleSplit(n_splits=4, train_size = 0.8,random_state =63)
start = time.time()
poly_linear = Pipeline([('poly', PolynomialFeatures()),
('Linear', LinearRegression(fit_intercept =False))])
parameters = {'poly__degree': [1,2,3,4,5]}
grid_search_lin = GridSearchCV(poly_linear, parameters, cv=skf2, n_jobs=-1, scoring='mean_squared_error').fit(X_l, Y_l)
print('timer',time.time() - start,'s')
【问题讨论】:
-
请澄清更多。
"I first used a loop which was stopped when MSE is >10K",在 GridSearchCV 之前你好吗? -
我只是使用了
for循环和break条件,在每次迭代中,我检查我的模型的 MSE 是否 > 10K:@987654330 @
标签: python-3.x machine-learning scikit-learn grid-search