model.py
def polynomial_regression(X_tr, y_tr, X_v, y_v, X_te, y_te, dstring, **kwargs):
    '''
    This function runs the polynomial features algorithm with a 
    linear regression model on train, validate, and test data 
    with the option to include key word arguments.
    '''
    # create polynomial features object
    pf = PolynomialFeatures(**kwargs)
    
    # fit and transform the train data
    X_train_sq = pf.fit_transform(X_tr)
    # transform the validate data
    X_validate_sq = pf.transform(X_v)
    # transform the validate data
    X_test_sq = pf.transform(X_te)
    
    # create the linear regression model
    lm_sq = LinearRegression()
    # fit the model to the training data
    lm_sq.fit(X_train_sq, y_tr)
    
    # predict the popularity on the train data
    lm_sq_pred = lm_sq.predict(X_train_sq)
    # calculate the rmse of the train data
    lm_sq_rmse = sqrt(mean_squared_error(y_tr, lm_sq_pred))
    
    # predict the popularity on the validate data
    lm_sq_pred_v = lm_sq.predict(X_validate_sq)
    # calculate the rmse of the validate data
    lm_sq_rmse_v = sqrt(mean_squared_error(y_v, lm_sq_pred_v))
    
    # predict the popularity on the test data
    lm_sq_pred_t = lm_sq.predict(X_test_sq)
    # calculate the rmse of the test data
    lm_sq_rmse_t = sqrt(mean_squared_error(y_te, lm_sq_pred_t))
    
    # print the train rmse
    print(f'RMSE for Polynomial {dstring} + Linear Regression \n')
    print('On train data:\n', round(lm_sq_rmse, 6), '\n')
    return lm_sq_rmse, lm_sq_rmse_v, lm_sq_rmse_t, lm_sq_pred_t

    This function runs the polynomial features algorithm with a 
    linear regression model on train, validate, and test data 
    with the option to include key word arguments.
    
This function runs the polynomial features algorithm with a
linear regression model on train, validate, and test data
with the option to include key word arguments.
This function runs the polynomial features algorithm with a linear regression model on train validate and test data with the option to include key word arguments .
def polynomial_regression(X_tr, y_tr, X_v, y_v, X_te, y_te, dstring, **kwargs):
    pf = PolynomialFeatures(**kwargs)
    X_train_sq = pf.fit_transform(X_tr)
    X_validate_sq = pf.transform(X_v)
    X_test_sq = pf.transform(X_te)
    lm_sq = LinearRegression()
    lm_sq.fit(X_train_sq, y_tr)
    lm_sq_pred = lm_sq.predict(X_train_sq)
    lm_sq_rmse = sqrt(mean_squared_error(y_tr, lm_sq_pred))
    lm_sq_pred_v = lm_sq.predict(X_validate_sq)
    lm_sq_rmse_v = sqrt(mean_squared_error(y_v, lm_sq_pred_v))
    lm_sq_pred_t = lm_sq.predict(X_test_sq)
    lm_sq_rmse_t = sqrt(mean_squared_error(y_te, lm_sq_pred_t))
    print(f'RMSE for Polynomial {dstring} + Linear Regression \n')
    print('On train data:\n', round(lm_sq_rmse, 6), '\n')
    return lm_sq_rmse, lm_sq_rmse_v, lm_sq_rmse_t, lm_sq_pred_t
def polynomial_regression ( X_tr , y_tr , X_v , y_v , X_te , y_te , dstring , ** kwargs ) : pf = PolynomialFeatures ( ** kwargs ) X_train_sq = pf . fit_transform ( X_tr ) X_validate_sq = pf . transform ( X_v ) X_test_sq = pf . transform ( X_te ) lm_sq = LinearRegression ( ) lm_sq . fit ( X_train_sq , y_tr ) lm_sq_pred = lm_sq . predict ( X_train_sq ) lm_sq_rmse = sqrt ( mean_squared_error ( y_tr , lm_sq_pred ) ) lm_sq_pred_v = lm_sq . predict ( X_validate_sq ) lm_sq_rmse_v = sqrt ( mean_squared_error ( y_v , lm_sq_pred_v ) ) lm_sq_pred_t = lm_sq . predict ( X_test_sq ) lm_sq_rmse_t = sqrt ( mean_squared_error ( y_te , lm_sq_pred_t ) ) print ( f'RMSE for Polynomial {dstring} + Linear Regression \n' ) print ( 'On train data:\n' , round ( lm_sq_rmse , 6 ) , '\n' ) return lm_sq_rmse , lm_sq_rmse_v , lm_sq_rmse_t , lm_sq_pred_t
This function runs the polynomial features algorithm with a
linear regression model on train, validate, and test data
with the option to include key word arguments.
This function runs the polynomial features algorithm with a linear regression model on train validate and test data with the option to include key word arguments .
'''
    This function runs the polynomial features algorithm with a 
    linear regression model on train, validate, and test data 
    with the option to include key word arguments.
    ''' # create polynomial features object # fit and transform the train data # transform the validate data # transform the validate data # create the linear regression model # fit the model to the training data # predict the popularity on the train data # calculate the rmse of the train data # predict the popularity on the validate data # calculate the rmse of the validate data # predict the popularity on the test data # calculate the rmse of the test data # print the train rmse
X_tr
y_tr
X_v
y_v
X_te
y_te
dstring