Пример #1
0
def MedidasDiversidade(medida, x_val, y_val, ensemble):
    '''
    Metodo para calcular a diversidade de um ensemble utilizando a estatistica Q 
    :param: x_val: dados com atributos que serao usados para a poda 
    :param: y_val: dados com rotulos que serao usados para a poda
    :return: Q: diversidade do ensemble
    '''
    
    L = len(ensemble.estimators_)
    Q = 0
    
    for i in range(L-1):
        for k in range(i+1, L):
            y_pred0 = ensemble.estimators_[i].predict(x_val)
            y_pred1 = ensemble.estimators_[k].predict(x_val)
                
            if(medida == 'q'):
                Q += Q_statistic(y_val, y_pred0, y_pred1)
            elif(medida == 'disagreement'):
                Q += disagreement_measure(y_val, y_pred0, y_pred1)
            
    Q = (2/(L*(L-1)))*Q
    
    return Q
Пример #2
0
def test_q_statistic_ones():
    Q = Q_statistic(y_dsel_ex1, y_pred_ones, y_pred_ones)
    assert Q == 1.0
Пример #3
0
def test_q_statistic_zeros():
    Q = Q_statistic(y_dsel_ex1, y_pred_zeros, y_pred_zeros)
    assert Q == 1.0
Пример #4
0
def test_q_statistic_zeros(example_diversity_ones_zeros):
    y, y_pred_ones, y_pred_zeros = example_diversity_ones_zeros
    Q = Q_statistic(y, y_pred_zeros, y_pred_zeros)
    assert Q == 1.0