model.py
def visualize_model(y_predictions, y_actual, baseline_predictions, model_name):

    '''
    Plot a model's predictions versus what the perfect model would perform and versus the baseline.
    Needs a series of the models predictions, the actual values, and the baseline. The model name
    is used in the legend of the plot.
    '''
    
    # first, a gray line representing the baseline prediction, 
    # a horizontal line because it only predicts the average
    plt.figure(figsize=(16,8))
    plt.axhline(baseline_predictions, alpha=.95, color="gray", linestyle=':', label='Baseline Prediction: Average')

    # next, straight line for the actual values
    # y = x, i.e. when the value is 10 it would be predicted 10, when 60 it would be 60, etc.
    plt.plot(y_actual, y_actual, alpha=.9, color="blue", label='The Ideal Line: Actual Values')

    # next, a scatter plot representing each observation (song popularity) as the actual value vs. the predicted value
    plt.scatter(y_actual, y_predictions, 
            alpha=.3, color='red', s=30, label=f'Model: {model_name}')

    # adding plot labels
    plt.legend()
    plt.xlabel("Actual Song Popularity", size=13)
    plt.ylabel("Predicted Song Popularity", size=13)
    plt.title("How Does the Final Model Compare to Baseline? And to Actual Values?", size=15)
    plt.show()

    Plot a model's predictions versus what the perfect model would perform and versus the baseline.
    Needs a series of the models predictions, the actual values, and the baseline. The model name
    is used in the legend of the plot.
    
Plot a model's predictions versus what the perfect model would perform and versus the baseline.
Needs a series of the models predictions, the actual values, and the baseline. The model name
is used in the legend of the plot.
Plot a model ' s predictions versus what the perfect model would perform and versus the baseline . Needs a series of the models predictions the actual values and the baseline . The model name is used in the legend of the plot .
def visualize_model(y_predictions, y_actual, baseline_predictions, model_name):
    plt.figure(figsize=(16,8))
    plt.axhline(baseline_predictions, alpha=.95, color="gray", linestyle=':', label='Baseline Prediction: Average')
    plt.plot(y_actual, y_actual, alpha=.9, color="blue", label='The Ideal Line: Actual Values')
    plt.scatter(y_actual, y_predictions, 
            alpha=.3, color='red', s=30, label=f'Model: {model_name}')
    plt.legend()
    plt.xlabel("Actual Song Popularity", size=13)
    plt.ylabel("Predicted Song Popularity", size=13)
    plt.title("How Does the Final Model Compare to Baseline? And to Actual Values?", size=15)
    plt.show()
def visualize_model ( y_predictions , y_actual , baseline_predictions , model_name ) : plt . figure ( figsize = ( 16 , 8 ) ) plt . axhline ( baseline_predictions , alpha = .95 , color = "gray" , linestyle = ':' , label = 'Baseline Prediction: Average' ) plt . plot ( y_actual , y_actual , alpha = .9 , color = "blue" , label = 'The Ideal Line: Actual Values' ) plt . scatter ( y_actual , y_predictions , alpha = .3 , color = 'red' , s = 30 , label = f'Model: {model_name}' ) plt . legend ( ) plt . xlabel ( "Actual Song Popularity" , size = 13 ) plt . ylabel ( "Predicted Song Popularity" , size = 13 ) plt . title ( "How Does the Final Model Compare to Baseline? And to Actual Values?" , size = 15 ) plt . show ( )
Plot a model's predictions versus what the perfect model would perform and versus the baseline.
Plot a model ' s predictions versus what the perfect model would perform and versus the baseline .
'''
    Plot a model's predictions versus what the perfect model would perform and versus the baseline.
    Needs a series of the models predictions, the actual values, and the baseline. The model name
    is used in the legend of the plot.
    ''' # first, a gray line representing the baseline prediction,  # a horizontal line because it only predicts the average # next, straight line for the actual values # y = x, i.e. when the value is 10 it would be predicted 10, when 60 it would be 60, etc. # next, a scatter plot representing each observation (song popularity) as the actual value vs. the predicted value # adding plot labels
y_predictions
y_actual
baseline_predictions
model_name