def train_model_ridge(dataframe): np.random.seed(0) X_train = dataframe.drop(target_variable, axis=1) y_train = dataframe[target_variable[0]] parameter_grid = {'ridge__alpha': [0.01, 0.1, 1]} custom_out("Training Ridge Regression") pipeline = Pipeline([("imputer", Imputer(strategy="median", axis=0)), ("scaler", StandardScaler()), ("ridge", linear_model.Ridge())]) grid_search = GridSearchCV(estimator=pipeline, param_grid=parameter_grid, cv=5, verbose=2, n_jobs=5, refit=True) return auto_grid(grid_search, X_train, y_train, 'RLR')
def train_random_forest(dataframe): np.random.seed(0) X_train = dataframe.drop(target_variable, axis=1) y_train = dataframe[target_variable[0]] parameter_grid = user_forest_param() custom_out("Training Random Forest") pipeline = Pipeline([("imputer", Imputer(strategy="median", axis=0)), ("scaler", StandardScaler()), ("forest", RandomForestRegressor(random_state=0, n_estimators=100))]) grid_search = GridSearchCV(estimator=pipeline, param_grid=parameter_grid, cv=cv_all, verbose=2, n_jobs=5, refit=True) return auto_grid(grid_search, X_train, y_train, 'RF')
def train_Huber(dataframe): custom_out("Training Huber Regression") np.random.seed(0) X_train = dataframe.drop(target_variable, axis=1) y_train = dataframe[target_variable[0]] pipeline = Pipeline([("imputer", Imputer(strategy="median", axis=0)), ("scaler", StandardScaler()), ("huber", linear_model.HuberRegressor())]) parameter_grid = {'huber__epsilon': [1.2, 1.35, 1.5]} grid_search = GridSearchCV(estimator=pipeline, param_grid=parameter_grid, cv=5, verbose=2, n_jobs=5, refit=True) return auto_grid(grid_search, X_train, y_train, 'HLR')
def train_elastic_model(dataframe): custom_out("Training EN Regression") np.random.seed(0) X_train = dataframe.drop(target_variable, axis=1) y_train = dataframe[target_variable[0]] pipeline = Pipeline([("imputer", Imputer(strategy="median", axis=0)), ("scaler", StandardScaler()), ("en", linear_model.ElasticNet())]) parameter_grid = user_en_param() grid_search = GridSearchCV(estimator=pipeline, param_grid=parameter_grid, cv=cv_all, verbose=2, n_jobs=5, refit=True, seed=0) return auto_grid(grid_search, X_train, y_train, 'EN')