Exemple #1
0
def plot_expected_repeat_purchases(model, **kwargs):
    from matplotlib import pyplot as plt

    ax = kwargs.pop('ax', None) or plt.subplot(111)
    label = kwargs.pop('label', None)

    if plt.matplotlib.__version__ >= "1.5":
        color_cycle = ax._get_lines.prop_cycler
        color = coalesce(kwargs.pop('c', None), kwargs.pop('color', None), next(color_cycle)['color'])
    else:
        color_cycle = ax._get_lines.color_cycle
        color = coalesce(kwargs.pop('c', None), kwargs.pop('color', None), next(color_cycle))

    max_T = model.data['T'].max()

    times = np.linspace(0, max_T, 100)
    ax = plt.plot(times, model.expected_number_of_purchases_up_to_time(times), color=color, label=label, **kwargs)

    times = np.linspace(max_T, 1.5 * max_T, 100)
    plt.plot(times, model.expected_number_of_purchases_up_to_time(times), color=color, ls='--', **kwargs)

    plt.title('Expected Number of Repeat Purchases per Customer')
    plt.xlabel('Time Since First Purchase')
    plt.legend(loc='lower right')
    return ax
Exemple #2
0
def plot_expected_repeat_purchases(model, **kwargs):
    from matplotlib import pyplot as plt

    ax = kwargs.pop('ax', None) or plt.subplot(111)
    label = kwargs.pop('label', None)

    if plt.matplotlib.__version__ >= "1.5":
        color_cycle = ax._get_lines.prop_cycler
        color = coalesce(kwargs.pop('c', None), kwargs.pop('color', None), next(color_cycle)['color'])
    else:
        color_cycle = ax._get_lines.color_cycle
        color = coalesce(kwargs.pop('c', None), kwargs.pop('color', None), next(color_cycle))

    max_T = model.data['T'].max()

    times = np.linspace(0, max_T, 100)
    ax = plt.plot(times, model.expected_number_of_sessions_up_to_time(times), color=color, label=label, **kwargs)

    times = np.linspace(max_T, 1.5 * max_T, 100)
    plt.plot(times, model.expected_number_of_sessions_up_to_time(times), color=color, ls='--', **kwargs)

    plt.title('Expected Number of Repeat Purchases per Customer')
    plt.xlabel('Time Since First Purchase')
    plt.legend(loc='lower right')
    return ax
Exemple #3
0
def plot_expected_repeat_purchases(
        model,
        title='Expected Number of Repeat Purchases per Customer',
        xlabel='Time Since First Purchase',
        **kwargs):
    """
    Plot expected repeat purchases on calibration period .

    Parameters:
        model: a fitted lifetimes model.
        title: figure title
        xlabel: figure xlabel
        ylabel: figure ylabel
        kwargs: passed into the matplotlib.pyplot.plot command.

    """
    from matplotlib import pyplot as plt

    ax = kwargs.pop('ax', None) or plt.subplot(111)
    label = kwargs.pop('label', None)

    if plt.matplotlib.__version__ >= "1.5":
        color_cycle = ax._get_lines.prop_cycler
        color = coalesce(kwargs.pop('c', None), kwargs.pop('color', None),
                         next(color_cycle)['color'])
    else:
        color_cycle = ax._get_lines.color_cycle
        color = coalesce(kwargs.pop('c', None), kwargs.pop('color', None),
                         next(color_cycle))

    max_T = model.data['T'].max()

    times = np.linspace(0, max_T, 100)
    ax = plt.plot(times,
                  model.expected_number_of_purchases_up_to_time(times),
                  color=color,
                  label=label,
                  **kwargs)

    times = np.linspace(max_T, 1.5 * max_T, 100)
    plt.plot(times,
             model.expected_number_of_purchases_up_to_time(times),
             color=color,
             ls='--',
             **kwargs)

    plt.title(title)
    plt.xlabel(xlabel)
    plt.legend(loc='lower right')
    return ax