Posts

Showing posts with the label SVM

Machine learning : GridSearch with Cross Validation , Sklearn

Grid Search Method : 


This function helps you to get the best Kernel, gamma, C hyperparam to have a good prediction with the SVM algorithm.

from sklearn import svm,grid_search
def svc_param_selection(X,y,nfolds=6):
    Cs= [0.001,0.01,1,10]
    gammas=[0.001,0.01,0.1,1,10]
    kernels=['linear','rbf']
    param_grid={'C':cs,'gamma':gammas,'kernel':kernels}
    model = svm.SVC()
    gs= grid_search.GridSearch(model,parm_grid,cv=nfolds)
    gs.fit(X,y)
    gs.best_params_
    return gs.best_params_,gs.best_score_