text_plain_output_1.png
from sklearn.ensemble import BaggingRegressor

from sklearn.ensemble import RandomForestRegressor

from sklearn.feature_selection import SelectKBest, f_classif

from sklearn.linear_model import LinearRegression

from sklearn.metrics import mean_squared_error

from sklearn.pipeline import make_pipeline

from sklearn.preprocessing import PolynomialFeatures, StandardScaler

from sklearn.tree import DecisionTreeRegressor

from xgboost import XGBRegressor

preprocessor = make_pipeline(PolynomialFeatures(2, include_bias=False), SelectKBest(f_classif, k=10))

LR_model = make_pipeline(preprocessor, LinearRegression())
RandomForest_model = make_pipeline(preprocessor, RandomForestRegressor())
DecisionTreeRegressor_model = make_pipeline(preprocessor, DecisionTreeRegressor())

from sklearn.ensemble import BaggingRegressor
regr = BaggingRegressor(base_estimator=XGBRegressor(), n_estimators=10, random_state=0).fit(X_train, y_train)
preds_valid = regr.predict(X_valid)

def evaluation(model):
    model.fit(X_train, y_train)
    preds_valid = model.predict(X_valid)

list_models = {'LR_model': LR_model, 'RandomForest_model': RandomForest_model, 'DecisionTreeRegressor_model': DecisionTreeRegressor_model}

for name, model in list_models.items():
    print(name)
    evaluation(model)