7

How to plot mean_train_score and mean_test_score values in GridSearchCV for C and gamma values of SVM?

Stephen Rauch
  • 1,783
  • 11
  • 21
  • 34
Harika M
  • 345
  • 1
  • 4
  • 7

1 Answers1

7

You could visualize them as a heatmap.

For example you could use the C values as the rows, the gamma values as the columns and the color intensity of each element in the heatmap array would correspond to the mean_test_score.

To implement this you first need to create a pandas.DataFrame like this:

$$ \begin{array}{c | c c c} & C & gamma & mean\_test\_score \\ \hline 1 & 0.1 & 0.001 & 0.798 \\ 2 & 1 & 0.001 & 0.813 \\ 3 & 1 & 0.01 & 0.801 \\ 4 & 10 & 0.001 & 0.787 \\ \end{array} $$

To do this you need to store each run you make in a different line, which will contain all necessary hyper-parameters and the result. Then you will need to make a pivot table which will use C as the rows, gamma as the columns and mean_test_score as the values.

pivot = pd.pivot_table(df, values=df['mean_test_score'])

This pivot will be the array that will form your heatmap. Now you should select your aesthetic parameters (e.g. colormap) and proceed to make the heatmap.

sns.heatmap(pivot) # plus any other aesthetic parameters you wish
Mnng
  • 311
  • 1
  • 3