Created
March 16, 2018 07:12
-
-
Save jamespaultg/a1b121ed3d4418f65af0973d07ff92c7 to your computer and use it in GitHub Desktop.
Linear SVC grid search in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.pipeline import Pipeline | |
from sklearn.svm import LinearSVC | |
from sklearn.model_selection import GridSearchCV | |
from sklearn.preprocessing import StandardScaler | |
SVCpipe = Pipeline([('scale', StandardScaler()), | |
('SVC',LinearSVC())]) | |
# Gridsearch to determine the value of C | |
param_grid = {'SVC__C':np.arange(0.01,100,10)} | |
linearSVC = GridSearchCV(SVCpipe,param_grid,cv=5,return_train_score=True) | |
linearSVC.fit(X_train,y_train) | |
print(linearSVC.best_params_) | |
#linearSVC.coef_ | |
#linearSVC.intercept_ | |
bestlinearSVC = linearSVC.best_estimator_ | |
bestlinearSVC.fit(X_train,y_train) | |
bestlinearSVC.coef_ = bestlinearSVC.named_steps['SVC'].coef_ | |
bestlinearSVC.score(X_train,y_train) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment