<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 There is a lot of room for feature engineering the 8 qualitative features, but we'll reserve it for later
Step1:  From now we try a range of estimators and use GridSearch to iteratively tune their hyperparameters
<ASSISTANT_TASK:>
Python Code:
#Drop quantitative features for which most samples take 0 or 1
for cols in quan:
    if train_c[cols].mean() < 0.01 or train_c[cols].mean() > 0.99:
        train_c.drop(cols, inplace=True, axis=1)
        test_c.drop(cols, inplace=True, axis=1)
#For now we only use the quantitative features left to make predictions
quan_features = train_c.columns[8:-1]
from sklearn.metrics import r2_score
from sklearn.model_selection import GridSearchCV
import warnings
warnings.filterwarnings('ignore')
Explanation: There is a lot of room for feature engineering the 8 qualitative features, but we'll reserve it for later
End of explanation
from sklearn.linear_model import Ridge
ridge = Ridge()
ridge_cv = GridSearchCV(estimator=ridge, param_grid={'alpha':np.arange(1, 50, 1)}, cv=5)
ridge_cv.fit(train_c[quan_features], train_c.label)
ridge_cv.best_score_
from sklearn.linear_model import Lasso
lasso = Lasso()
lasso_cv = GridSearchCV(estimator=lasso, param_grid={'alpha':np.arange(0, 0.05, 0.005)}, cv=5)
lasso_cv.fit(train_c[quan_features], train_c.label)
lasso_cv.best_score_
from sklearn.ensemble import RandomForestRegressor
rf = RandomForestRegressor()
params = {'max_depth':np.arange(5,8),
          'min_samples_split':np.arange(3, 6)}
rf_cv = GridSearchCV(estimator=rf, param_grid=params, cv=5)
rf_cv.fit(train_c[quan_features], train_c.label)
rf_cv.best_score_
from sklearn.linear_model import ElasticNet
en = ElasticNet()
params = {'alpha':np.arange(0.01, 0.05, 0.005),
          'l1_ratio': np.arange(0.1, 0.9, 0.1)}
en_cv = GridSearchCV(estimator=en, param_grid=params, cv=5)
en_cv.fit(train_c[quan_features], train_c.label)
en_cv.best_score_
from mlxtend.regressor import StackingRegressor
from sklearn.linear_model import LinearRegression
lin=LinearRegression()
basic_regressors= [ridge_cv.best_estimator_, lasso_cv.best_estimator_, 
                   rf_cv.best_estimator_, en_cv.best_estimator_]
stacker=StackingRegressor(regressors=basic_regressors, meta_regressor=lin)
stacker.fit(train_c[quan_features], train_c.label)
pred = stacker.predict(train_c[quan_features])
r2_score(train_c.label, pred)
result = pd.DataFrame()
result['ID']=test.ID
result['y']=stacker.predict(test_c[quan_features])
result.to_csv('./stackedprediction.csv', index=False)
Explanation: From now we try a range of estimators and use GridSearch to iteratively tune their hyperparameters
End of explanation
<END_TASK>