sample/sample.py
def plot_grid_search_results(grid, C_range, gamma_range):
    """
    Plot heatmap resulting from Grid Search.
    Plotting taken from http://scikit-learn.org/stable/auto_examples/svm/plot_rbf_parameters.html
    :param grid: Grid Search obj
    :param C_range: 
    :param gamma_range: 
    :return: 
    """
    from matplotlib.colors import Normalize

    class MidpointNormalize(Normalize):
        """
        Utility function to move the midpoint of a colormap to be around
        the values of interest.
        """

        def __init__(self, vmin=None, vmax=None, midpoint=None, clip=False):
            self.midpoint = midpoint
            Normalize.__init__(self, vmin, vmax, clip)

        def __call__(self, value, clip=None):
            x, y = [self.vmin, self.midpoint, self.vmax], [0, 0.5, 1]
            return np.ma.masked_array(np.interp(value, x, y))

    scores = grid.cv_results_['mean_test_score'].reshape(len(C_range),
                                                         len(gamma_range))
    plt.figure(figsize=(8, 6))
    # plt.subplots_adjust(left=.2, right=0.95, bottom=0.15, top=0.95)
    plt.imshow(scores, interpolation='nearest', cmap=plt.get_cmap("hot"),
               norm=MidpointNormalize(vmin=0.2, midpoint=0.92))
    plt.xlabel('gamma')
    plt.ylabel('C')
    plt.colorbar()
    plt.xticks(np.arange(len(gamma_range)), gamma_range, rotation=45)
    plt.yticks(np.arange(len(C_range)), C_range)
    plt.title('Validation accuracy')
    plt.show()

    Plot heatmap resulting from Grid Search.
    Plotting taken from http://scikit-learn.org/stable/auto_examples/svm/plot_rbf_parameters.html
    :param grid: Grid Search obj
    :param C_range: 
    :param gamma_range: 
    :return: 
    
Plot heatmap resulting from Grid Search.
Plot heatmap resulting from Grid Search .
def plot_grid_search_results(grid, C_range, gamma_range):
    from matplotlib.colors import Normalize
    class MidpointNormalize(Normalize):
        def __init__(self, vmin=None, vmax=None, midpoint=None, clip=False):
            self.midpoint = midpoint
            Normalize.__init__(self, vmin, vmax, clip)
        def __call__(self, value, clip=None):
            x, y = [self.vmin, self.midpoint, self.vmax], [0, 0.5, 1]
            return np.ma.masked_array(np.interp(value, x, y))
    scores = grid.cv_results_['mean_test_score'].reshape(len(C_range),
                                                         len(gamma_range))
    plt.figure(figsize=(8, 6))
    plt.imshow(scores, interpolation='nearest', cmap=plt.get_cmap("hot"),
               norm=MidpointNormalize(vmin=0.2, midpoint=0.92))
    plt.xlabel('gamma')
    plt.ylabel('C')
    plt.colorbar()
    plt.xticks(np.arange(len(gamma_range)), gamma_range, rotation=45)
    plt.yticks(np.arange(len(C_range)), C_range)
    plt.title('Validation accuracy')
    plt.show()
def plot_grid_search_results ( grid , C_range , gamma_range ) : from matplotlib . colors import Normalize class MidpointNormalize ( Normalize ) : """
        Utility function to move the midpoint of a colormap to be around
        the values of interest.
        """ def __init__ ( self , vmin = None , vmax = None , midpoint = None , clip = False ) : self . midpoint = midpoint Normalize . __init__ ( self , vmin , vmax , clip ) def __call__ ( self , value , clip = None ) : x , y = [ self . vmin , self . midpoint , self . vmax ] , [ 0 , 0.5 , 1 ] return np . ma . masked_array ( np . interp ( value , x , y ) ) scores = grid . cv_results_ [ 'mean_test_score' ] . reshape ( len ( C_range ) , len ( gamma_range ) ) plt . figure ( figsize = ( 8 , 6 ) ) plt . imshow ( scores , interpolation = 'nearest' , cmap = plt . get_cmap ( "hot" ) , norm = MidpointNormalize ( vmin = 0.2 , midpoint = 0.92 ) ) plt . xlabel ( 'gamma' ) plt . ylabel ( 'C' ) plt . colorbar ( ) plt . xticks ( np . arange ( len ( gamma_range ) ) , gamma_range , rotation = 45 ) plt . yticks ( np . arange ( len ( C_range ) ) , C_range ) plt . title ( 'Validation accuracy' ) plt . show ( )
Plot heatmap resulting from Grid Search.
Plot heatmap resulting from Grid Search .
"""
    Plot heatmap resulting from Grid Search.
    Plotting taken from http://scikit-learn.org/stable/auto_examples/svm/plot_rbf_parameters.html
    :param grid: Grid Search obj
    :param C_range: 
    :param gamma_range: 
    :return: 
    """ """
        Utility function to move the midpoint of a colormap to be around
        the values of interest.
        """ # plt.subplots_adjust(left=.2, right=0.95, bottom=0.15, top=0.95)
None
grid
Grid Search obj
Grid Search obj
C_range
None
gamma_range
None