How to use the lifetimes.plotting.plot_frequency_recency_matrix function in Lifetimes

To help you get started, we’ve selected a few Lifetimes examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CamDavidsonPilon / lifetimes / tests / test_plotting.py View on Github external
def test_plot_frequency_recency_matrix_max_recency(self, bgf):
        shape = (101, 30)
        col_idx = 25
        col = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
               0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
               0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.001, 0.001, 0.002,
               0.002, 0.004, 0.005, 0.007, 0.010, 0.014, 0.018, 0.024, 0.032, 0.041, 0.052,
               0.065, 0.080, 0.096, 0.112, 0.129, 0.145, 0.160, 0.174, 0.186, 0.196, 0.205,
               0.212, 0.218, 0.222, 0.226, 0.229, 0.232, 0.233]

        ax = plotting.plot_frequency_recency_matrix(bgf, max_recency=100)
        ar = ax.get_images()[0].get_array()
        assert_array_equal(ar.shape, shape)
        assert_allclose(ar[:, col_idx].data, col, atol=0.01)  # only test one row for brevity
        assert_equal(ax.title.get_text(), "Expected Number of Future Purchases for 1 Unit of Time,\nby Frequency and Recency of a Customer")
        assert_equal(ax.xaxis.get_label().get_text(), "Customer's Historical Frequency")
        assert_equal(ax.yaxis.get_label().get_text(), "Customer's Recency")
        plt.close()
github CamDavidsonPilon / lifetimes / tests / test_plotting.py View on Github external
def test_plot_frequency_recency_matrix_max_frequency_max_recency(self, bgf):
        shape = (101, 101)
        row_idx = 95
        row = [0.002, 0.008, 0.017, 0.025, 0.034, 0.043, 0.052, 0.060, 0.069, 0.078, 0.087,
               0.096, 0.105, 0.114, 0.123, 0.132, 0.140, 0.149, 0.158, 0.166, 0.175, 0.184,
               0.192, 0.201, 0.209, 0.218, 0.226, 0.235, 0.243, 0.251, 0.259, 0.267, 0.275,
               0.283, 0.291, 0.299, 0.307, 0.314, 0.322, 0.330, 0.337, 0.344, 0.352, 0.359,
               0.366, 0.373, 0.379, 0.386, 0.393, 0.399, 0.405, 0.411, 0.417, 0.423, 0.429,
               0.435, 0.440, 0.445, 0.450, 0.455, 0.460, 0.465, 0.469, 0.473, 0.477, 0.481,
               0.484, 0.488, 0.491, 0.494, 0.497, 0.499, 0.501, 0.503, 0.505, 0.506, 0.508,
               0.509, 0.509, 0.510, 0.510, 0.510, 0.510, 0.509, 0.508, 0.507, 0.506, 0.504,
               0.503, 0.501, 0.498, 0.496, 0.493, 0.490, 0.486, 0.483, 0.479, 0.475, 0.471,
               0.466, 0.462]

        ax = plotting.plot_frequency_recency_matrix(bgf, max_frequency=100, max_recency=100)
        ar = ax.get_images()[0].get_array()
        assert_array_equal(ar.shape, shape)
        assert_allclose(ar[row_idx, :].data, row, atol=0.01)  # only test one row for brevity
        assert_equal(ax.title.get_text(), "Expected Number of Future Purchases for 1 Unit of Time,\nby Frequency and Recency of a Customer")
        assert_equal(ax.xaxis.get_label().get_text(), "Customer's Historical Frequency")
        assert_equal(ax.yaxis.get_label().get_text(), "Customer's Recency")
        plt.close()
github CamDavidsonPilon / lifetimes / tests / test_plotting.py View on Github external
def test_plot_frequency_recency_matrix(self, bgf):
        shape = (39, 30)
        row_idx = 29
        row = [0.005, 0.020, 0.037, 0.054, 0.070, 0.085, 0.099, 0.110, 0.120, 0.127, 0.133,
               0.136, 0.136, 0.135, 0.131, 0.125, 0.119, 0.111, 0.102, 0.093, 0.084, 0.075,
               0.066, 0.058, 0.050, 0.044, 0.038, 0.032, 0.027, 0.023]

        ax = plotting.plot_frequency_recency_matrix(bgf)
        ar = ax.get_images()[0].get_array()
        assert_array_equal(ar.shape, shape)
        assert_allclose(ar[row_idx, :].data, row, atol=0.01)  # only test one row for brevity
        assert_equal(ax.title.get_text(), "Expected Number of Future Purchases for 1 Unit of Time,\nby Frequency and Recency of a Customer")
        assert_equal(ax.xaxis.get_label().get_text(), "Customer's Historical Frequency")
        assert_equal(ax.yaxis.get_label().get_text(), "Customer's Recency")
        plt.close()
github CamDavidsonPilon / lifetimes / tests / test_plotting.py View on Github external
def test_plot_frequency_recency_matrix_max_frequency(self, bgf):
        shape = (39, 101)
        row_idx = 35
        row = [0.005, 0.021, 0.041, 0.061, 0.082, 0.103, 0.125, 0.146, 0.167, 0.188, 0.208,
               0.229, 0.250, 0.270, 0.290, 0.310, 0.330, 0.349, 0.369, 0.388, 0.406, 0.425,
               0.443, 0.460, 0.478, 0.495, 0.511, 0.528, 0.543, 0.559, 0.573, 0.587, 0.601,
               0.614, 0.627, 0.639, 0.650, 0.660, 0.670, 0.679, 0.688, 0.695, 0.702, 0.708,
               0.713, 0.718, 0.721, 0.724, 0.726, 0.727, 0.727, 0.726, 0.724, 0.721, 0.718,
               0.713, 0.708, 0.702, 0.695, 0.687, 0.679, 0.670, 0.660, 0.649, 0.638, 0.627,
               0.615, 0.602, 0.589, 0.575, 0.562, 0.548, 0.533, 0.519, 0.504, 0.489, 0.475,
               0.460, 0.445, 0.430, 0.416, 0.401, 0.387, 0.372, 0.359, 0.345, 0.331, 0.318,
               0.305, 0.293, 0.280, 0.269, 0.257, 0.246, 0.235, 0.224, 0.214, 0.204, 0.195,
               0.186, 0.177]

        ax = plotting.plot_frequency_recency_matrix(bgf, max_frequency=100)
        ar = ax.get_images()[0].get_array()
        assert_array_equal(ar.shape, shape)
        assert_allclose(ar[row_idx, :].data, row, atol=0.01)  # only test one row for brevity
        assert_equal(ax.title.get_text(), "Expected Number of Future Purchases for 1 Unit of Time,\nby Frequency and Recency of a Customer")
        assert_equal(ax.xaxis.get_label().get_text(), "Customer's Historical Frequency")
        assert_equal(ax.yaxis.get_label().get_text(), "Customer's Recency")
        plt.close()