Example #1
0
def generate_grid_search(hash_model_selection, kernel):

    c1 = hash_model_selection['soft_margin1']
    c2 = hash_model_selection['soft_margin2']
    step_c = hash_model_selection['step_soft_margin']

    if c1 >= c2:
        raise Exception(
            'ERROR',
            'run_svm.generate_grid_search: The limit points of soft_margin parameter are not properly configured'
        )

    if step_c <= 0:
        raise Exception(
            'ERROR',
            'run_svm.generate_grid_search: The incremental amount for soft_margin scanning is not properly configured'
        )

    grid_soft_margin = frange(c1, c2, step_c)

    if len(grid_soft_margin) <= 1:
        raise Exception(
            'ERROR',
            'run_svm.generate_grid_search: The list of soft_margin parameter has one element or is empty'
        )

    if kernel == 'linear':

        return grid_soft_margin, []

    g1 = hash_model_selection['gamma1']
    g2 = hash_model_selection['gamma2']
    step_g = hash_model_selection['step_gamma']

    if g1 >= g2:
        raise Exception(
            'ERROR',
            'run_svm.generate_grid_search: The limit points of gamma parameter are not properly configured'
        )

    if step_g <= 0:
        raise Exception(
            'ERROR',
            'run_svm.generate_grid_search: The incremental amount for gamma scanning is not properly configured'
        )

    grid_gamma = frange(g1, g2, step_g)

    if len(grid_gamma) <= 1:
        raise Exception(
            'ERROR',
            'run_svm.generate_grid_search: The list of gamma parameter has one element or is empty'
        )

    return grid_soft_margin, grid_gamma
Example #2
0
def generate_grid_search(hash_model_selection,kernel):

    c1     = hash_model_selection['soft_margin1']
    c2     = hash_model_selection['soft_margin2']
    step_c = hash_model_selection['step_soft_margin']
    
    if c1 >= c2:
        raise Exception('ERROR','run_svm.generate_grid_search: The limit points of soft_margin parameter are not properly configured')
    
    if step_c <= 0:
        raise Exception('ERROR','run_svm.generate_grid_search: The incremental amount for soft_margin scanning is not properly configured')
    
    grid_soft_margin = frange(c1,c2,step_c)
            
    if len(grid_soft_margin) <= 1:
        raise Exception('ERROR','run_svm.generate_grid_search: The list of soft_margin parameter has one element or is empty') 

    if kernel == 'linear':    
        
        return grid_soft_margin,[]
    
    g1     = hash_model_selection['gamma1']
    g2     = hash_model_selection['gamma2']
    step_g = hash_model_selection['step_gamma']
    
    if g1 >= g2:
        raise Exception('ERROR','run_svm.generate_grid_search: The limit points of gamma parameter are not properly configured')
    
    if step_g <= 0:
        raise Exception('ERROR','run_svm.generate_grid_search: The incremental amount for gamma scanning is not properly configured')
    
    grid_gamma = frange(g1,g2,step_g)
            
    if len(grid_gamma) <= 1:
        raise Exception('ERROR','run_svm.generate_grid_search: The list of gamma parameter has one element or is empty') 
             
    return grid_soft_margin,grid_gamma
Example #3
0
	def calculate_roc_values(self,l_scores,l_labels):
		
		"""
			Bibliography:
			ROC Graphs: Notes and Practical Considerations for Researchers
			Tom Fawcett ([email protected])
			HP Laboratories, MS 1143, 1501 Page Mill Road, Palo Alto, CA 94304
		"""
		
		if len(l_scores) <= 1:
			return []
				
		l_scores_sort = sorted(l_scores)
		mini = l_scores_sort[0]
		maxi = l_scores_sort[-1]
		increment  = max(l_scores_sort[1]-l_scores_sort[0],min_increment)
				
		l_margin_thres = frange(mini,maxi,increment) 
		l_margin_thres.append(1)
		
		num_cpu = 2
		
		if cpu_count() > 1:
			num_cpu = cpu_count() 
		
		pool = Pool(num_cpu-1)
		
		result = pool.map_async(get_confusion_matrix, map(lambda x: (l_scores,l_labels,x) , l_margin_thres))
		
		result.wait()
		
		l_results = result.get()
		
		l_roc_fpr = map(lambda x: self.__get_FPR(x['FP'],x['N']),l_results)
		l_roc_tpr = map(lambda x: self.__get_TPR(x['TP'],x['P']),l_results)
				
		return sorted(zip(l_roc_fpr,l_roc_tpr))