Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
511 views
in Technique[技术] by (71.8m points)

python - Fit best estimator on all data (X_train, X_test) after pipeline

I created a pipeline for imputing nan values, SelectPercentile for feature selection and GridSearchCV to find best parameters. I am okey with mean absolute error X_test, y_test and I decided to use this best estimator which pipeline gives me on new dataset (production dataset). But I think for to use it on production it is better to fit all data (X_train + X_test) rather than only X_train which pipeline does. How can i achieve fitting all data using the pipeline results ?

regr = make_pipeline(SimpleImputer(missing_values=np.nan, strategy='median'),
                 SelectPercentile(f_regression),
                 GradientBoostingRegressor())

param_grid = {"selectpercentile__percentile": [50, 60, 70],
        "gradientboostingregressor__max_depth": [1, 2, 3],
        "gradientboostingregressor__subsample": [0.7,0.8],
        "gradientboostingregressor__learning_rate": [0.005, 0.008, 0.012],
        "gradientboostingregressor__n_estimators": [1000, 1500]}
         
grid = GridSearchCV(regr, param_grid, cv = 5)
grid.fit(X_train, y_train.values.ravel())
print("Best cross-validation score : {:.2f}".format(grid.best_score_))
print("Best parameters :", grid.best_params_)

best_model = gridsearch.best_estimator_

mean_absolute_error(y_test,grid.predict(X_test))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...