Redratz
Redratz

Reputation: 136

Is Cross Validation necessary when using SKlearn SVC probability True

I'm currently tuning hyperparameters of my SVM classifier. My current implementation uses the SKlearn gridsearchCV with the brier_score_loss scoring metric.

From reading the documentation, the brier_score_loss takes a probability as input, and implementing probability = True for SKlearn SVC internally conducts a 5-fold cross validation.

Is it necessary to conduct cross-validation on the gridsearch, or is the internal 5-fold cross validation sufficient?

For example, below I have two implementations one using a 5-fold gridsearchCV and one using only 1 fold.

params = {
    "C": np.logspace(-3, 17, 21),
    "gamma": np.logspace(-20, 1, 21)
    }

grid_search_5_fold = GridSearchCV(estimator = SVC(probability = True), 
                           param_grid = params, 
                           scoring = 'neg_brier_score',
                           n_jobs = -1, 
                           verbose = 2)

grid_search_1_fold = GridSearchCV(estimator = SVC(probability = True), 
                           param_grid = params, 
                           scoring = 'neg_brier_score',
                           n_jobs = -1, 
                           verbose = 2,
                           cv = 1)

grid_search_5_fold.fit(x_train, y_train)

grid_search_1_fold.fit(x_train, y_train)

Upvotes: 0

Views: 613

Answers (1)

user16207687
user16207687

Reputation:

you can do this

# parameter space for SVM
# ------------------------
parameter_space = {'kernel':('linear', 'rbf'), 'C':[0.1,1,10]}


# SVM
clf = GridSearchCV(svm.SVC(gamma='auto'), parameter_space, n_jobs = -1, refit = True, 
verbose = 10, cv = 5) 

Upvotes: 0

Related Questions