Created
January 23, 2019 18:25
-
-
Save WittmannF/02060b45ce3ec9239898a5b91df2564e to your computer and use it in GitHub Desktop.
Very simple code for comparing different R2 scores
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
from sklearn.datasets import make_regression | |
from sklearn.metrics import r2_score | |
import matplotlib.pyplot as plt | |
#%matplotlib inline | |
# Generate toy data | |
X, y, w_true = make_regression(n_samples=20, n_features=1, random_state=0, noise=1.0, coef=True) | |
w_bad = 0.5*w_true | |
w_verybad = -0.3*w_true | |
# Plot true data | |
plt.figure(figsize=(8,5)) | |
plt.plot(X, y, '.') | |
# Plot a good, a bad and a very model with R2 scores | |
for w in [w_true, w_bad, w_verybad]: | |
plt.plot(X, w*X, label="R2 Score = {:.3f}".format(r2_score(y, w*X))) | |
plt.legend(loc=0) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output:
