Esempio n. 1
0
 def test_pearson(self):
     data = {
         'C01': [1, 2, 3, 4],
         'C02': [1, 2, 3, 4],
         'C03': [4, 3, 2, 1],
         'C04': [4, 3, 2, 1],
         'C05': [1, 2, 3, 4],
         'C06': [4, 3, 2, 1]
     }
     df = pandas.DataFrame(
         data, columns=['C01', 'C02', 'C03', 'C04', 'C05', 'C06'])
     corr, sign, columns, nominal_columns, inf_nan, single_value_columns = compute_correlations(
         df)
     print(corr)
     print(sign)
     # assert diagonal = 1.0
     self.assertEqual(corr.at['C01', 'C01'], 1.0)
     self.assertEqual(corr.at['C02', 'C02'], 1.0)
     self.assertEqual(corr.at['C03', 'C03'], 1.0)
     self.assertEqual(corr.at['C04', 'C04'], 1.0)
     # assert some others also = 1.0
     self.assertEqual(corr.at['C01', 'C02'], 1.0)
     self.assertEqual(corr.at['C02', 'C01'], 1.0)
     self.assertEqual(corr.at['C02', 'C03'], 1.0)
     self.assertEqual(corr.at['C03', 'C02'], 1.0)
     self.assertEqual(corr.at['C03', 'C04'], 1.0)
     self.assertEqual(corr.at['C03', 'C04'], 1.0)
            "SpatMax": "SMax",
            "SpatAvg": "SAvg",
            "Coverage": "Cov",
            "TempDist": "TDist",
            "SpatDist": "SDist",
            'Strasse': "Str"
        })

    baysis_encoded = baysis_encoded.drop(
        columns=["TempGL", "SpatGL", "TempIL", "SpatIL"])

    # Calculate with Cramers 's V
    results = None  # To make sure that no old data is reused
    results = compute_correlations(baysis_encoded,
                                   columns_nominal=nominal_columns,
                                   columns_dichotomous=dichotomous_columns,
                                   columns_ordinal=ordinal_columns,
                                   bias_correction=False)

    # Plot correlation matrix
    plot_correlation(results.get('correlation'),
                     results.get('columns'),
                     nominal_columns,
                     dichotomous_columns,
                     ordinal_columns,
                     results.get('inf_nan_corr'),
                     results.get('columns_single_value'),
                     save=save_plot,
                     filepath=plot_path + file_prefix + '_corr_cramers.pdf',
                     show=show_plot,
                     figsize=(18, 15))