Created
January 11, 2022 17:47
-
-
Save isaacarroyov/1f8aef2fc16bd4868946f75f9b822562 to your computer and use it in GitHub Desktop.
This file contains 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.model_selection import StratifiedKFold, GridSearchCV | |
# Declare grid of hyper-parameters | |
dict_hyperparams = dict(svm__gamma=[0.001,0.01,0.1], | |
svm__C = [1,10,100,1_000]) | |
# Cross Validation for GridSearchCV | |
crossVal = StratifiedKFold(n_splits=5, shuffle=True, random_state=0) | |
model_02 = Pipeline(steps= [ | |
('hogdescriptor', DescriptorHOG()), | |
('pca', PCA(n_components=0.9, svd_solver='full')), | |
('scaler', StandardScaler()), | |
('svm', SVC(kernel='rbf')) | |
]) | |
grid = GridSearchCV( | |
estimator= model_02, # Model | |
param_grid= dict_hyperparams, # hyper-parameters | |
cv= crossVal, # Cross Validation | |
n_jobs=-1, # Use all CPU's | |
verbose= 5 # Info | |
) | |
# Train the model | |
grid.fit(X_train,y_train) | |
# Best hyper-parameters | |
gamma_02 = grid.best_params_['svm__gamma'] | |
C_02 = grid.best_params_['svm__C'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment