more irritating typos

This commit is contained in:
Morten Hjorth-Jensen
2021-09-23 09:09:42 +02:00
parent c76f1d1e5a
commit d69f43cbaf
7 changed files with 42 additions and 42 deletions
+7 -7
View File
@@ -492,11 +492,11 @@ for p in range(degree):
beta = fit_beta(X, y)
# Intercept is included in the design matrix
clf = LinearRegression(fit_intercept=False).fit(X, y)
skl = LinearRegression(fit_intercept=False).fit(X, y)
print(f"True beta: {true_beta}")
print(f"Fitted beta: {beta}")
print(f"Sklearn fitted beta: {clf.coef_}")
print(f"Sklearn fitted beta: {skl.coef_}")
ypredictOwn = X @ beta
ypredictSKL = skl.predict(X)
print(f"MSE with intercept column")
@@ -508,7 +508,7 @@ print(MSE(y,ypredictSKL))
plt.figure()
plt.scatter(x, y, label="Data")
plt.plot(x, X @ beta, label="Fit")
plt.plot(x, clf.predict(X), label="Sklearn (fit_intercept=False)")
plt.plot(x, skl.predict(X), label="Sklearn (fit_intercept=False)")
# Do not include the intercept in the design matrix
@@ -518,7 +518,7 @@ for p in range(degree - 1):
X[:, p] = x ** (p + 1)
# Intercept is not included in the design matrix
clf = LinearRegression(fit_intercept=True).fit(X, y)
skl = LinearRegression(fit_intercept=True).fit(X, y)
# Use centered values for X and y when computing coefficients
y_offset = np.average(y, axis=0)
@@ -529,8 +529,8 @@ intercept = np.mean(y_offset - X_offset @ beta)
print(f"Manual intercept: {intercept}")
print(f"Fitted beta (wiothout intercept): {beta}")
print(f"Sklearn intercept: {clf.intercept_}")
print(f"Sklearn fitted beta (without intercept): {clf.coef_}")
print(f"Sklearn intercept: {skl.intercept_}")
print(f"Sklearn fitted beta (without intercept): {skl.coef_}")
ypredictOwn = X @ beta
ypredictSKL = skl.predict(X)
print(f"MSE with Manual intercept")
@@ -539,7 +539,7 @@ print(f"MSE with Sklearn intercept")
print(MSE(y,ypredictSKL))
plt.plot(x, X @ beta + intercept, "--", label="Fit (manual intercept)")
plt.plot(x, clf.predict(X), "--", label="Sklearn (fit_intercept=True)")
plt.plot(x, skl.predict(X), "--", label="Sklearn (fit_intercept=True)")
plt.grid()
plt.legend()