# How to plot mean_test score and mean_train score of GridSearchCV

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

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

• Yes.. Please update on how to implement that.. – Harika M Sep 24 '18 at 0:32
• @HarikaM I added a way to implement this in python – Mnng Oct 2 '18 at 22:56