Skip to content

Instantly share code, notes, and snippets.

@ChristopherDaigle
Last active June 1, 2020 01:31
Show Gist options
  • Save ChristopherDaigle/9116ff63fa2a10aece98a15b22b857b2 to your computer and use it in GitHub Desktop.
Save ChristopherDaigle/9116ff63fa2a10aece98a15b22b857b2 to your computer and use it in GitHub Desktop.
from sklearn.linear_model import LinearRegression, Ridge
from sklearn.model_selection import train_test_split
X = df_final.drop(['revenue', 'release_date'], axis=1)
y = df_final['revenue']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)
lm_model = LinearRegression(normalize=True)
r_model = Ridge(normalize=True)
lm_model.fit(X_train, y_train)
r_model.fit(X_train, y_train)
print('Linear Regression Train R2: {}'.format(round(lm_model.score(X_train, y_train),4)))
print('Ridge Train R2: {}'.format(round(r_model.score(X_train, y_train),4)))
lm_preds = lm_model.predict(X_test)
r_preds = r_model.predict(X_test)
print('Linear Regression Test R2: {}'.format(round(lm_model.score(X_test, y_test),4)))
print('Ridge Test R2: {}'.format(round(r_model.score(X_test, y_test),4)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment