Created
January 21, 2019 01:56
-
-
Save bgweber/de662707b93b2ae6e1978d2ebe7fdd23 to your computer and use it in GitHub Desktop.
This file contains 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
from sklearn.linear_model import LinearRegression | |
from scipy.stats.stats import pearsonr | |
# split into data and label arrays | |
y = boston_pd['target'] | |
X = boston_pd.drop(['target'], axis=1) | |
# create training (~80%) and test data sets | |
X_train = X[:400] | |
X_test = X[400:] | |
y_train = y[:400] | |
y_test = y[400:] | |
# train a classifier | |
lr = LinearRegression() | |
model = lr.fit(X_train, y_train) | |
# make predictions | |
y_pred = model.predict(X_test) | |
# error metrics | |
r = pearsonr(y_pred, y_test) | |
mae = sum(abs(y_pred - y_test))/len(y_test | |
print("R-sqaured: " + str(r[0]**2)) | |
print("MAE: " + str(mae)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
mae = sum(abs(y_pred - y_test))/len(y_test
=> needs trailing parenthesis.
Too lazy to do a PR.