Issue
What are the drawbacks which can arise from adding hyperparameters through Gridsearchcv,
Suppose I'm having this pipeline
pipe_svm = Pipeline([
('clf', svm.SVC()])
And I'm also using Gridsearchcv,
param_range =[1]
gs_svm = GridSearchCV(estimator=pipe_svm,
param_grid={'clf__C':param_range})
For the sake of simplicity I've used only one hyperparameter which is C (error term penalty parameter)
Functionally the scheme of using Gridsearchcv is to find the best hyperparameters from the given set of values, but in this case being provided with only one value that is 1, definitely it will be the best hyperparameter.
Does this cause any problems?
on execution what does Gridsearchcv do with this value?
can this cause any delays in getting results (when done on large scale)?
Solution
- Does this cause any problems?
Definitely it will not cause any problem. Just make sure that you feed those single values as a list.
- on execution what does Gridsearchcv do with this value?
It will execute k-fold CV for that one combination of hyper-parameters only.
- can this cause any delays in getting results (when done on large scale)?
It might have some overhead when you set n_jobs>1, hence set it to 1, when you think that number of combinations of hyper-parameters are going to be small.
Update:
If you want to avoid Cross validation for some reason, then you can define your way of train and test spliting. Then feed that splitting as an iterator.
Example:
from sklearn import svm, datasets
from sklearn.model_selection import GridSearchCV
iris = datasets.load_iris()
parameters = {'C':[1]}
svc = svm.SVC()
train_ind = np.random.choice(np.arange(150), size=100, replace=False)
cv_split_iter = [(train_ind, np.setdiff1d(np.arange(150), train_ind)),]
clf = GridSearchCV(svc, parameters, cv=cv_split_iter)
clf.fit(iris.data, iris.target)
pd.DataFrame(clf.cv_results_)
# mean_fit_time std_fit_time mean_score_time std_score_time param_C params split0_test_score mean_test_score std_test_score rank_test_score
#0 0.00 0.00 0.00 0.00 1 {'C': 1} 0.92 0.92 0.00 1
Answered By - Venkatachalam
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.