def test_plot_incremental_transactions(self): """Test plotting incremental transactions with CDNOW example.""" transactions = load_dataset('CDNOW_sample.txt', header=None, sep='\s+') transactions.columns = [ 'id_total', 'id_sample', 'date', 'num_cd_purc', 'total_value' ] t = 39 freq = 'W' transactions_summary = utils.summary_data_from_transaction_data( transactions, 'id_sample', 'date', datetime_format='%Y%m%d', observation_period_end='19970930', freq=freq) bgf = BetaGeoFitter(penalizer_coef=0.01) bgf.fit(transactions_summary['frequency'], transactions_summary['recency'], transactions_summary['T']) plt.figure() plotting.plot_incremental_transactions(bgf, transactions, 'date', 'id_sample', 2 * t, t, freq=freq, xlabel='week', datetime_format='%Y%m%d') return plt.gcf()
def cdnow_transactions(): transactions = load_dataset('CDNOW_sample.txt', header=None, sep=r'\s+') transactions.columns = ['id_total', 'id_sample', 'date', 'num_cd_purc', 'total_value'] return transactions[['id_sample', 'date']]
def cdnow_transactions(): transactions = load_dataset("CDNOW_sample.txt", header=None, sep=r"\s+") transactions.columns = [ "id_total", "id_sample", "date", "num_cd_purc", "total_value" ] return transactions[["id_sample", "date"]]