Esempio n. 1
0
def plot_one_univariate(ax, df, x_var_name, y_var_name, mask=None):
    """ A linear spline regression of two columns in the dataframe.
        INPUT:
            ax:
                Matplotlib axis to plot on.
                (use 'fig, ax = matplotlib.pyplot.subplots(1,1)')
            df:
                Dataframe of floats or ints.
            x_var_name:
                the column name of the x var from dataframe
            y_var_name:
                string, the column name of the dependent y variable in
                the dataframe
        OUTPUT:
            A linear regression, with light blue bootstrapped lines showing the
            instability of the regression
    """
    min_y = min(df[y_var_name])
    max_y = max(df[y_var_name])
    ax.set_ylim(min_y - .1 * np.abs(min_y), max_y + .1 * np.abs(max_y))
    if mask is None:
        plot_univariate_smooth(ax,
                               df[x_var_name].values.reshape(-1, 1),
                               df[y_var_name],
                               bootstrap=200)
    else:
        plot_univariate_smooth(ax,
                               df[x_var_name].values.reshape(-1, 1),
                               df[y_var_name],
                               mask=mask,
                               bootstrap=200)
    return None
Esempio n. 2
0
def plot_one_univariate(ax, dataframe, x_var_name, y_var_name, mask=None):
    """ A linear spline regression of two columns in the dataframe. of string 'y_var' across the named string 'xvar' in the dataframe var_name on matplotlib axis 'ax'
    INPUT:
        ax:
            matplotlib axis
            (use 'fig, ax = matplotlib.pyplot.subplots(1,1)')
        dataframe:
            dataframe of floats or ints
        x_var_name:
            the index name of the x var from dataframe
        y_var_name:
            the index name of the y var from dataframe
    OUTPUT:
        A linear regression, with light blue bootstrapped lines showing the instability of the regression
    """
    min_y = min(dataframe[y_var_name])
    max_y = max(dataframe[y_var_name])
    ax.set_ylim(min_y - .1 * np.abs(min_y), max_y + .1 * np.abs(max_y))
    if mask is None:
        plot_univariate_smooth(ax,
                               dataframe[x_var_name].values.reshape(-1, 1),
                               dataframe[y_var_name],
                               bootstrap=200)
    else:
        plot_univariate_smooth(ax,
                               dataframe[x_var_name].values.reshape(-1, 1),
                               dataframe[y_var_name],
                               mask=mask,
                               bootstrap=200)
Esempio n. 3
0
def plot_univariate_bynumeric(target_column):
    fig, axs = plt.subplots(len(numeric_predictors), figsize=(14, 14))
    for name, ax in zip(numeric_predictors, axs.flatten()):
        plot_univariate_smooth(ax,
        data_df[name].values.reshape(-1, 1),
        data_df[target_column],
        bootstrap=100)
    ax.set_title(name)
    fig.tight_layout()
    plt.show()
Esempio n. 4
0
from regression_tools.plotting_tools import (
    plot_univariate_smooth,
    bootstrap_train,
    display_coef,
    plot_bootstrap_coefs,
    plot_partial_depenence,
    plot_partial_dependences,
    predicteds_vs_actuals)

fig, axs = plt.subplots(10, 1, figsize=(14, 25))
univariate_plot_names = clean_df.columns[:-1]

for name, ax in zip(univariate_plot_names, axs.flatten()):
    plot_univariate_smooth(ax,
                           clean_df[name].values.reshape(-1, 1),
                           clean_df['SalesPrice'],
                           bootstrap=100)
    ax.set_title(name)
fig.tight_layout()


#Plotting Neural Networks
def plot_results(model, ax=None, function=np.sin, xlim=(-7, 7),  data_lim=(-5, 5)):
    x_actual = np.linspace(*xlim, 500)
    y_actual = function(x_actual)

    if ax is None:
        fig, ax = plt.subplots(figsize=(12, 5))

    y_pred = model.predict(x_actual)
    ax.plot(x_actual,y_pred, 'r-', label='model predictions')