Created
November 6, 2018 04:46
-
-
Save FaisalAl-Tameemi/8ddc8080987aaa4caccb43437ed447e7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def train_test(df, response_col='price', dummy_na=False, test_size=.3, rand_state=42, plot=False): | |
#Split into explanatory and response variables | |
X = df.drop(response_col, axis=1) | |
y = df[response_col] | |
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=test_size, random_state=rand_state) | |
lm_model = LinearRegression(normalize=True) | |
lm_model.fit(X_train, y_train) | |
train_preds = lm_model.predict(X_train) | |
test_preds = lm_model.predict(X_test) | |
train_score = r2_score(y_train, train_preds) | |
test_score = r2_score(y_test, test_preds) | |
return test_score, train_score, lm_model, X_train, X_test, y_train, y_test, test_preds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment