Beispiel #1
0
def test_pairwise_mutual_information():
    from pandas import DataFrame
    from .testdata import adults01
    frame = DataFrame(adults01)
    mi = pairwise_mutual_information(frame)
    from numpy import allclose, alltrue
    assert allclose(mi, mi.T)
    assert alltrue(mi >= 0.0)
    assert alltrue(mi <= 1.0)
def test_plot_figures_output_show():
    from pandas import DataFrame
    plot_confusion_matrix(DataFrame({
        'True': [2, 3],
        'False': [5, 0]
    }),
                          otype='show')
    plot_confusion_matrix(DataFrame({
        '7th-8th': [2, 3, 5, 0],
        'Masters': [0, 4, 1, 0],
        '11th': [0, 1, 5, 2],
        'Bachelors': [2, 0, 0, 6]
    }),
                          otype='show')

    bins = np.array([
        28., 29.25, 30.5, 31.75, 33., 34.25, 35.5, 36.75, 38., 39.25, 40.5,
        41.75, 43., 44.25, 45.5, 46.75, 48., 49.25, 50.5
    ])
    counts = np.array(
        [[1, 0, 1, 0, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0],
         [1, 0, 1, 0, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1]])
    plot_histogram(bins, counts, otype='show')

    bins = np.array(['Private', 'Self-emp-not-inc', 'State-gov'])
    counts = np.array([[6, 2, 1], [6, 2, 1]])
    plot_histogram(bins, counts, otype='show')

    bins = np.array(['11th', '9th', 'Bachelors', 'HS-grad', 'Masters'])
    counts = np.array([[3, 2, 2, 1, 1], [3, 2, 2, 1, 1]])
    plot_histogram(bins, counts, otype='show')

    bins = np.array([
        5., 5.45, 5.9, 6.35, 6.8, 7.25, 7.7, 8.15, 8.6, 9.05, 9.5, 9.95, 10.4,
        10.85, 11.3, 11.75, 12.2, 12.65, 13.1
    ])
    counts = np.array(
        [[1, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0],
         [1, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0]])
    plot_histogram(bins, counts, otype='show')

    bins = np.array(['Female', 'Male'])
    counts = np.array([[5, 4], [5, 4]])
    plot_histogram(bins, counts, otype='show')

    from .testdata import adults01
    from ds4ml.metrics import pairwise_mutual_information
    data = pairwise_mutual_information(DataFrame(adults01))
    plot_heatmap(data, otype='show')
 def mi(self):
     """ Return mutual information of pairwise attributes. """
     from ds4ml.metrics import pairwise_mutual_information
     return pairwise_mutual_information(self)