def draw_distribution_graph(column, name, mean, median, mode):
        column.sort()
        graph.hist(column, bins=100, density=True, alpha=constant.SCATTER_ALPHA, color=constant.SCATTER_COLOUR)
        x = np.linspace(graph.xlim()[0], graph.xlim()[1], 100)
        graph.xlabel(name)

        # distributions
        p = norm.pdf(x, mean, MathsUtil.arr_standard_deviation(column, mean))
        graph.plot(x, p, color=constant.DISTRIBUTION_MEAN_COLOUR)
        p = norm.pdf(x, median, MathsUtil.arr_standard_deviation(column, median))
        graph.plot(x, p, color=constant.DISTRIBUTION_MEDIAN_COLOUR)
        p = norm.pdf(x, mode, MathsUtil.arr_standard_deviation(column, mode))
        graph.plot(x, p, color=constant.DISTRIBUTION_MODE_COLOUR)

        # averages
        graph.axvline(mean, color=constant.DISTRIBUTION_MEAN_COLOUR,
                      linestyle=constant.DISTRIBUTION_MEAN_LINE_STYLE)
        graph.axvline(median, color=constant.DISTRIBUTION_MEDIAN_COLOUR,
                      linestyle=constant.DISTRIBUTION_MEDIAN_LINE_STYLE)
        graph.axvline(mode, color=constant.DISTRIBUTION_MODE_COLOUR,
                      linestyle=constant.DISTRIBUTION_MODE_LINE_STYLE)

        # title
        graph.legend({"Mean": mean, "Median": median, "Mode": mode})
        mean_title = f"mean={mean:.2f}, variance={MathsUtil.arr_variance(column, mean):.2f} std={MathsUtil.arr_standard_deviation(column, mean):.2f}"
        median_title = f"median={median:.2f}, variance={MathsUtil.arr_variance(column, median):.2f} std={MathsUtil.arr_standard_deviation(column, median):.2f}"
        mode_title = f"mode={mode:.2f}, variance={MathsUtil.arr_variance(column, mode):.2f} std={MathsUtil.arr_standard_deviation(column, mode):.2f}"
        graph.title(f"Distribution: {mean_title}\n{median_title}\n{mode_title}")
Esempio n. 2
0
 def print_deviation_calculation(average_type, rows, average):
     variance = MathsUtil.arr_variance(rows, average)
     standard_deviation = MathsUtil.arr_standard_deviation(rows, average)
     print(f"For {average_type}: The Standard Deviation is {standard_deviation:.2f}, The Variance is {variance:.2f} and the {average_type} in {average:.2f}")
 def test_arr_standard_deviation(self):
     self.assertEqual(MathsUtil.arr_standard_deviation([3, 9], MathsUtil.arr_mean([3, 9])), 3)