text_plain_output_1.png
from sklearn.model_selection import GridSearchCV

from sklearn.model_selection import KFold

from sklearn.svm import SVC

import matplotlib.pyplot as plt

import pandas as pd

df = pd.read_csv('train.csv')

folds = KFold(n_splits=5, shuffle=True, random_state=101)
hyper_params = [{'gamma': [0.01, 0.001, 0.0001], 'C': [1, 10, 100, 1000]}]
model = SVC(kernel='rbf')
model_cv = GridSearchCV(estimator=model, param_grid=hyper_params, scoring='accuracy', cv=folds, verbose=1, return_train_score=True)
model_cv.fit(X_train, y_train)

cv_results = pd.DataFrame(model_cv.cv_results_)
cv_results

cv_results['param_C'] = cv_results['param_C'].astype('int')
plt.figure(figsize=(16, 6))
plt.subplot(131)
gamma_01 = cv_results[cv_results['param_gamma'] == 0.01]
plt.plot(gamma_01['param_C'], gamma_01['mean_test_score'])
plt.plot(gamma_01['param_C'], gamma_01['mean_train_score'])
plt.xlabel('C')
plt.ylabel('Accuracy')
plt.title('Gamma=0.01')
plt.ylim([0.6, 1])
plt.legend(['test accuracy', 'train accuracy'], loc='upper left')
plt.xscale('log')
plt.subplot(132)
gamma_001 = cv_results[cv_results['param_gamma'] == 0.001]
plt.plot(gamma_001['param_C'], gamma_001['mean_test_score'])
plt.plot(gamma_001['param_C'], gamma_001['mean_train_score'])
plt.xlabel('C')
plt.ylabel('Accuracy')
plt.title('Gamma=0.001')
plt.ylim([0.6, 1])
plt.legend(['test accuracy', 'train accuracy'], loc='upper left')
plt.xscale('log')
plt.subplot(133)
gamma_0001 = cv_results[cv_results['param_gamma'] == 0.0001]
plt.plot(gamma_0001['param_C'], gamma_0001['mean_test_score'])
plt.plot(gamma_0001['param_C'], gamma_0001['mean_train_score'])
plt.xlabel('C')
plt.ylabel('Accuracy')
plt.title('Gamma=0.0001')
plt.ylim([0.6, 1])
plt.legend(['test accuracy', 'train accuracy'], loc='upper left')
plt.xscale('log')