GridSeachCV not performing well on ML models
from sklearn.model_selection import GridSearchCV
svm2=SVC()
grid={
'C': [0.1, 1, 10, 100, 1000],
'kernel': ['linear', 'poly', 'rbf', 'sigmoid'],
'gamma': [1, 0.1, 0.01, 0.001, 0.0001]
}
svm_grid=GridSearchCV(estimator=svm2,param_grid=grid,cv=3,n_jobs=-1)
svm_grid.fit(xtrain,ytrain)
svm_grid.best_params_
OUTPUT
{'C': 1, 'gamma': 1, 'kernel': 'rbf'}
CODE
svm_grid.score(xtrain,ytrain)
0.9884434814012278
svm_grid.score(xtest,ytest)
0.8513708513708513
My question is even after performing GridSearch why the model is still overfitting and how can I further increase the accuracy and combat overfitting .
I am facing same issues with RandomForest in Gridsearch
grid = {
'n_estimators': [10, 20, 40, 50, 100, 150, 200, 500],
'max_features': ['auto', 'sqrt'],
'max_depth': [3, 5, 7, 9, 11, 15],
'bootstrap': [True, False],
}
rf = RandomForestClassifier()
rf_random = GridSearchCV(estimator = rf, param_grid = grid, cv = 3, verbose=2, n_jobs = -1)
rf_random.fit(xtrain, ytrain)
rf_random.score(xtrain,ytrain)
1.0
rf_random.score(xtest,ytest)
0.8427128427128427
I am not able to understand why is GridSearch not helping
Topic grid-search overfitting decision-trees random-forest svm
Category Data Science