brew.metrics.diversity package

Submodules

brew.metrics.diversity.base module

class brew.metrics.diversity.base.Diversity(metric='')[source]

Bases: object

Ensemble Diversity Calculator.

The class calculates the diversity of ensemble of classifiers.

`metric`

function, receives the oracle output and returns float – Function used to calculate the metric.

Parameters:metric ({'e', 'kw', 'q', 'p', 'disagreement', 'agreement', 'df'}, optional) –

Metric used to compute the ensemble diversity:

  • ’e’ (Entropy Measure e) will use kuncheva_entropy_measure()
  • ’kw’ (Kohavi Wolpert Variance) will use kuncheva_kw()
  • ’q’ (Q Statistics) will use kuncheva_q_statistics()
  • ’p’ (Correlation Coefficient p) will use kuncheva_correlation_coefficient_p() # noqa
  • ’disagreement’ (Disagreement Measure) will use kuncheva_disagreement_measure() # noqa
  • ’agreement’ (Agreement Measure) will use kuncheva_agreement_measure() # noqa
  • ’df’ (Double Fault Measure) will use kuncheva_double_fault_measure() # noqa

Examples

>>> from brew.metrics.diversity.base import Diversity
>>> from brew.generation.bagging import Bagging
>>>
>>> from sklearn.tree import DecisionTreeClassifier
>>> import numpy as np
>>>
>>> X = np.array([[-1, 0], [-0.8, 1], [-0.8, -1], [-0.5, 0],
                  [0.5, 0], [1, 0], [0.8, 1], [0.8, -1]])
>>> y = np.array([1, 1, 1, 2, 1, 2, 2, 2])
>>> tree = DecisionTreeClassifier(max_depth=1, min_samples_leaf=1)
>>> bag = Bagging(base_classifier=tree, n_classifiers=10)
>>> bag.fit(X, y)
>>>
>>> div = Diversity(metric='q')
>>> q = div.calculate(bag.ensemble, Xtst, ytst)
>>> q < 1.01 and q > -1.01
True

See also

brew.metrics.diversity.paired
Paired diversity metrics.
brew.metrics.diversity.non_paired
Non-paired diversity metrics.

References

Brown, Gavin, et al. “Diversity creation methods: a survey and categorisation.” Information Fusion 6.1 (2005): 5-20.

Kuncheva, Ludmila I., and Christopher J. Whitaker. “Measures of diversity in classifier ensembles and their relationship with the ensemble accuracy.” Machine learning 51.2 (2003): 181-207.

Tang, E. Ke, Ponnuthurai N. Suganthan, and Xin Yao. “An analysis of diversity measures.” Machine Learning 65.1 (2006): 247-271.

calculate(ensemble, X, y)[source]

brew.metrics.diversity.non_paired module

brew.metrics.diversity.non_paired.entropy_measure_e(ensemble, X, y)[source]
brew.metrics.diversity.non_paired.kohavi_wolpert_variance(ensemble, X, y)[source]
brew.metrics.diversity.non_paired.kuncheva_entropy_measure(oracle)[source]
brew.metrics.diversity.non_paired.kuncheva_kw(oracle)[source]
brew.metrics.diversity.non_paired.new_entropy(ensemble, X, y)[source]

brew.metrics.diversity.paired module

brew.metrics.diversity.paired.agreement_measure(y_true, y_pred_a, y_pred_b)[source]
brew.metrics.diversity.paired.correlation_coefficient_p(y_true, y_pred_a, y_pred_b)[source]
brew.metrics.diversity.paired.disagreement_measure(y_true, y_pred_a, y_pred_b)[source]
brew.metrics.diversity.paired.double_fault_measure(y_true, y_pred_a, y_pred_b)[source]
brew.metrics.diversity.paired.kuncheva_agreement_measure(oracle)[source]
brew.metrics.diversity.paired.kuncheva_correlation_coefficient_p(oracle)[source]
brew.metrics.diversity.paired.kuncheva_disagreement_measure(oracle)[source]
brew.metrics.diversity.paired.kuncheva_double_fault_measure(oracle)[source]
brew.metrics.diversity.paired.kuncheva_q_statistics(oracle)[source]
brew.metrics.diversity.paired.paired_metric_ensemble(ensemble, X, y, paired_metric=<function q_statistics>)[source]
brew.metrics.diversity.paired.q_statistics(y_true, y_pred_a, y_pred_b)[source]

Module contents

class brew.metrics.diversity.Diversity(metric='')[source]

Bases: object

Ensemble Diversity Calculator.

The class calculates the diversity of ensemble of classifiers.

`metric`

function, receives the oracle output and returns float – Function used to calculate the metric.

Parameters:metric ({'e', 'kw', 'q', 'p', 'disagreement', 'agreement', 'df'}, optional) –

Metric used to compute the ensemble diversity:

  • ’e’ (Entropy Measure e) will use kuncheva_entropy_measure()
  • ’kw’ (Kohavi Wolpert Variance) will use kuncheva_kw()
  • ’q’ (Q Statistics) will use kuncheva_q_statistics()
  • ’p’ (Correlation Coefficient p) will use kuncheva_correlation_coefficient_p() # noqa
  • ’disagreement’ (Disagreement Measure) will use kuncheva_disagreement_measure() # noqa
  • ’agreement’ (Agreement Measure) will use kuncheva_agreement_measure() # noqa
  • ’df’ (Double Fault Measure) will use kuncheva_double_fault_measure() # noqa

Examples

>>> from brew.metrics.diversity.base import Diversity
>>> from brew.generation.bagging import Bagging
>>>
>>> from sklearn.tree import DecisionTreeClassifier
>>> import numpy as np
>>>
>>> X = np.array([[-1, 0], [-0.8, 1], [-0.8, -1], [-0.5, 0],
                  [0.5, 0], [1, 0], [0.8, 1], [0.8, -1]])
>>> y = np.array([1, 1, 1, 2, 1, 2, 2, 2])
>>> tree = DecisionTreeClassifier(max_depth=1, min_samples_leaf=1)
>>> bag = Bagging(base_classifier=tree, n_classifiers=10)
>>> bag.fit(X, y)
>>>
>>> div = Diversity(metric='q')
>>> q = div.calculate(bag.ensemble, Xtst, ytst)
>>> q < 1.01 and q > -1.01
True

See also

brew.metrics.diversity.paired
Paired diversity metrics.
brew.metrics.diversity.non_paired
Non-paired diversity metrics.

References

Brown, Gavin, et al. “Diversity creation methods: a survey and categorisation.” Information Fusion 6.1 (2005): 5-20.

Kuncheva, Ludmila I., and Christopher J. Whitaker. “Measures of diversity in classifier ensembles and their relationship with the ensemble accuracy.” Machine learning 51.2 (2003): 181-207.

Tang, E. Ke, Ponnuthurai N. Suganthan, and Xin Yao. “An analysis of diversity measures.” Machine Learning 65.1 (2006): 247-271.

calculate(ensemble, X, y)[source]