Please excuse my coding experience. I am trying to make a bunch of the regressions with GridSearch. I am trying to loop the whole to make the process faster but my code is not good enough and would not mind something to making even more efficient. Here is my code for it:
classifiers=[Lasso(max_iter=700,random_state=42), Ridge(max_iter=700,random_state=42), ElasticNet(max_iter=700,random_state=42)]
for clf in range(len(classifiers)):
grd=GridSearchCV(clf,parameters)
name = clf.__class__.__name__
print("="*25)
print(name)
if clf==0:
parameters={'alpha':[0.0005,0.0006,0.06,0.5,0.0001,0.01,1,2,3,4,4.4,4]}
elif clf==1:
parameters = {'alpha':[1,2,3,5,10,11,2,13,14,15]}
else:
parameters ={'alpha':[0.06,0.5,0.0001,0.01,1,2,3,4,4.4,4,5]}
grd.fit(X_train,y_train)
pred=grid.predict(X_test)
Rs = r2_score(y_test, pred)
rmse=np.sqrt(mean_squared_error(y_test,pred))
print('The R-squared is {:.4}'.format(Rs))
print('The root mean squared is {:.4}'.format(rmse))
The exact error I am having is the following:
estimator should be an estimator implementing 'fit' method, 0 was passed. An explanation would also be highly appreciated.