How to use the lifetimes.plotting.plot_probability_alive_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_probability_alive_matrix_max_frequency(self, bgf):
        shape = (39, 101)
        row_idx = 35
        row = [1.0, 0.736, 0.785, 0.814, 0.833, 0.846, 0.855, 0.862, 0.866, 0.869, 0.871,
               0.872, 0.873, 0.873, 0.872, 0.871, 0.869, 0.867, 0.865, 0.862, 0.859, 0.856,
               0.852, 0.848, 0.844, 0.839, 0.834, 0.829, 0.823, 0.817, 0.811, 0.805, 0.798,
               0.791, 0.783, 0.775, 0.767, 0.759, 0.750, 0.741, 0.731, 0.721, 0.711, 0.701,
               0.690, 0.679, 0.667, 0.656, 0.644, 0.631, 0.619, 0.606, 0.593, 0.580, 0.566,
               0.552, 0.539, 0.525, 0.511, 0.496, 0.482, 0.468, 0.454, 0.439, 0.425, 0.411,
               0.397, 0.383, 0.369, 0.355, 0.342, 0.329, 0.316, 0.303, 0.290, 0.278, 0.266,
               0.254, 0.243, 0.232, 0.221, 0.211, 0.201, 0.191, 0.182, 0.173, 0.164, 0.156,
               0.148, 0.140, 0.133, 0.126, 0.119, 0.113, 0.106, 0.101, 0.095, 0.090, 0.085,
               0.080, 0.075]

        ax = plotting.plot_probability_alive_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(), "Probability Customer is Alive,\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_probability_alive_matrix_max_frequency_max_recency(self, bgf):
        shape = (101, 101)
        col_idx = 15
        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.001,
               0.001, 0.001, 0.002, 0.002, 0.003, 0.004, 0.006, 0.008, 0.010, 0.012, 0.016,
               0.020, 0.025, 0.031, 0.039, 0.048, 0.059, 0.072, 0.088, 0.106, 0.126, 0.150,
               0.178, 0.208, 0.242, 0.278, 0.318, 0.359, 0.403, 0.447, 0.492, 0.536, 0.579,
               0.621, 0.660, 0.697, 0.731, 0.763, 0.791, 0.817, 0.839, 0.860, 0.877, 0.893,
               0.907, 0.919, 0.929, 0.939, 0.947, 0.953]

        ax = plotting.plot_probability_alive_matrix(bgf, max_frequency=100, 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 column for brevity
        assert_equal(ax.title.get_text(), "Probability Customer is Alive,\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_probability_alive_matrix(self, bgf):
        shape = (39, 30)
        row_idx = 35
        row = [1.0, 0.736, 0.785, 0.814, 0.833, 0.846, 0.855, 0.862, 0.866, 0.869, 0.871,
               0.872, 0.873, 0.873, 0.872, 0.871, 0.869, 0.867, 0.865, 0.862, 0.859, 0.856,
               0.852, 0.848, 0.844, 0.839, 0.834, 0.829, 0.823, 0.817]

        ax = plotting.plot_probability_alive_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(), "Probability Customer is Alive,\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_probability_alive_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.001, 0.001, 0.002, 0.003, 0.004, 0.006,
               0.008, 0.012, 0.017, 0.023, 0.032, 0.043, 0.058, 0.078, 0.103, 0.134, 0.173,
               0.219, 0.273, 0.333, 0.399, 0.468, 0.537, 0.604, 0.667, 0.724, 0.774, 0.816,
               0.852, 0.882, 0.906, 0.925, 0.941, 0.953, 0.963, 0.970]

        ax = plotting.plot_probability_alive_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 column for brevity
        assert_equal(ax.title.get_text(), "Probability Customer is Alive,\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()