def test_plot_expected_repeat_purchases(self): from matplotlib import pyplot as plt plt.figure() plotting.plot_expected_repeat_purchases(bgf) plt.figure() plotting.plot_expected_repeat_purchases(bgf, label='test label') plt.show()
def viz_bgf(self, t): #visualize customer frequency and recency matrix plot_frequency_recency_matrix(self.bgf, T=t, cmap='coolwarm') plt.savefig('sales_frequency_recency_matrix.png') plt.close() #visualize customer alive probability plot_probability_alive_matrix(self.bgf, cmap='coolwarm') plt.savefig('probability_alive_matrix.png') plt.close() #visualize expected repeat Purchases plot_expected_repeat_purchases(self.bgf) plt.savefig('ProbabilityExpectedRepeatPurchases.png') plt.close() #visualize the expected number of period transactions plot_period_transactions(self.bgf) plt.savefig('period_transactions.png') plt.close()
def test_plot_expected_repeat_purchases_with_label(self, bgf): solid_x_expected = [0.0, 0.39, 0.79, 1.18, 1.57, 1.96, 2.36, 2.75, 3.14, 3.53, 3.93, 4.32, 4.71, 5.1, 5.5, 5.89, 6.28, 6.67, 7.07, 7.46, 7.85, 8.24, 8.64, 9.03, 9.42, 9.81, 10.21, 10.6, 10.99, 11.38, 11.78, 12.17, 12.56, 12.95, 13.35, 13.74, 14.13, 14.52, 14.92, 15.31, 15.7, 16.09, 16.49, 16.88, 17.27, 17.66, 18.06, 18.45, 18.84, 19.23, 19.63, 20.02, 20.41, 20.8, 21.2, 21.59, 21.98, 22.37, 22.77, 23.16, 23.55, 23.94, 24.34, 24.73, 25.12, 25.51, 25.91, 26.3, 26.69, 27.08, 27.48, 27.87, 28.26, 28.65, 29.05, 29.44, 29.83, 30.22, 30.62, 31.01, 31.4, 31.79, 32.19, 32.58, 32.97, 33.36, 33.76, 34.15, 34.54, 34.93, 35.33, 35.72, 36.11, 36.5, 36.9, 37.29, 37.68, 38.07, 38.47, 38.86] solid_y_expected = [-0.0, 0.02, 0.04, 0.06, 0.08, 0.1, 0.12, 0.14, 0.16, 0.17, 0.19, 0.21, 0.23, 0.24, 0.26, 0.28, 0.29, 0.31, 0.32, 0.34, 0.35, 0.37, 0.38, 0.4, 0.41, 0.43, 0.44, 0.45, 0.47, 0.48, 0.49, 0.51, 0.52, 0.53, 0.54, 0.56, 0.57, 0.58, 0.59, 0.61, 0.62, 0.63, 0.64, 0.65, 0.67, 0.68, 0.69, 0.7, 0.71, 0.72, 0.73, 0.74, 0.76, 0.77, 0.78, 0.79, 0.8, 0.81, 0.82, 0.83, 0.84, 0.85, 0.86, 0.87, 0.88, 0.89, 0.9, 0.91, 0.92, 0.93, 0.94, 0.95, 0.96, 0.97, 0.98, 0.98, 0.99, 1.0, 1.01, 1.02, 1.03, 1.04, 1.05, 1.06, 1.07, 1.07, 1.08, 1.09, 1.1, 1.11, 1.12, 1.13, 1.13, 1.14, 1.15, 1.16, 1.17, 1.18, 1.18, 1.19] dashed_x_expected = [38.86, 39.06, 39.25, 39.45, 39.65, 39.84, 40.04, 40.23, 40.43, 40.63, 40.82, 41.02, 41.22, 41.41, 41.61, 41.8, 42.0, 42.2, 42.39, 42.59, 42.79, 42.98, 43.18, 43.37, 43.57, 43.77, 43.96, 44.16, 44.36, 44.55, 44.75, 44.94, 45.14, 45.34, 45.53, 45.73, 45.93, 46.12, 46.32, 46.51, 46.71, 46.91, 47.1, 47.3, 47.5, 47.69, 47.89, 48.08, 48.28, 48.48, 48.67, 48.87, 49.07, 49.26, 49.46, 49.65, 49.85, 50.05, 50.24, 50.44, 50.64, 50.83, 51.03, 51.22, 51.42, 51.62, 51.81, 52.01, 52.21, 52.4, 52.6, 52.79, 52.99, 53.19, 53.38, 53.58, 53.78, 53.97, 54.17, 54.36, 54.56, 54.76, 54.95, 55.15, 55.35, 55.54, 55.74, 55.93, 56.13, 56.33, 56.52, 56.72, 56.92, 57.11, 57.31, 57.5, 57.7, 57.9, 58.09, 58.29] dashed_y_expected = [1.19, 1.2, 1.2, 1.2, 1.21, 1.21, 1.22, 1.22, 1.22, 1.23, 1.23, 1.24, 1.24, 1.24, 1.25, 1.25, 1.26, 1.26, 1.26, 1.27, 1.27, 1.28, 1.28, 1.28, 1.29, 1.29, 1.29, 1.3, 1.3, 1.31, 1.31, 1.31, 1.32, 1.32, 1.32, 1.33, 1.33, 1.34, 1.34, 1.34, 1.35, 1.35, 1.35, 1.36, 1.36, 1.37, 1.37, 1.37, 1.38, 1.38, 1.38, 1.39, 1.39, 1.39, 1.4, 1.4, 1.41, 1.41, 1.41, 1.42, 1.42, 1.42, 1.43, 1.43, 1.43, 1.44, 1.44, 1.44, 1.45, 1.45, 1.45, 1.46, 1.46, 1.47, 1.47, 1.47, 1.48, 1.48, 1.48, 1.49, 1.49, 1.49, 1.5, 1.5, 1.5, 1.51, 1.51, 1.51, 1.52, 1.52, 1.52, 1.53, 1.53, 1.53, 1.54, 1.54, 1.54, 1.55, 1.55, 1.55] label = 'test label' ax = plotting.plot_expected_repeat_purchases(bgf, label=label) solid, dashed = ax.lines legend = plt.gca().legend_ solid_x, solid_y = solid.get_data() dashed_x, dashed_y = dashed.get_data() # compare the coordinates in the matplotlib axes objects to expected values assert_allclose(solid_x, solid_x_expected, atol=0.01) assert_allclose(solid_y, solid_y_expected, atol=0.01) assert_allclose(dashed_x, dashed_x_expected, atol=0.01) assert_allclose(dashed_y, dashed_y_expected, atol=0.01) assert_equal(legend.get_texts()[0].get_text(), label) assert_equal(ax.title.get_text(), "Expected Number of Repeat Purchases per Customer") assert_equal(ax.xaxis.get_label().get_text(), "Time Since First Purchase") assert_equal(ax.yaxis.get_label().get_text(), "") plt.close()
def test_plot_expected_repeat_purchases(self): plt.figure() plotting.plot_expected_repeat_purchases(bgf, label='test label') return plt.gcf()
def test_plot_expected_repeat_purchases(self, bgf): plt.figure() plotting.plot_expected_repeat_purchases(bgf) return plt.gcf()