diff --git a/doc/pub/week38/html/._week38-bs000.html b/doc/pub/week38/html/._week38-bs000.html index e0f7360df..f03c8cdf8 100644 --- a/doc/pub/week38/html/._week38-bs000.html +++ b/doc/pub/week38/html/._week38-bs000.html @@ -222,7 +222,7 @@ MathJax.Hub.Config({
-
diff --git a/doc/pub/week38/html/._week38-bs008.html b/doc/pub/week38/html/._week38-bs008.html
index d18be34aa..143f403fe 100644
--- a/doc/pub/week38/html/._week38-bs008.html
+++ b/doc/pub/week38/html/._week38-bs008.html
@@ -232,21 +232,21 @@ polydegree = np
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2)
for degree in range(maxdegree):
- model = make_pipeline(PolynomialFeatures(degree=degree), LinearRegression(fit_intercept=False))
+ model = make_pipeline(PolynomialFeatures(degree=degree), LinearRegression(fit_intercept=False))
y_pred = np.empty((y_test.shape[0], n_boostraps))
for i in range(n_boostraps):
x_, y_ = resample(x_train, y_train)
y_pred[:, i] = model.fit(x_, y_).predict(x_test).ravel()
polydegree[degree] = degree
- error[degree] = np.mean( np.mean((y_test - y_pred)**2, axis=1, keepdims=True) )
- bias[degree] = np.mean( (y_test - np.mean(y_pred, axis=1, keepdims=True))**2 )
- variance[degree] = np.mean( np.var(y_pred, axis=1, keepdims=True) )
- print('Polynomial degree:', degree)
- print('Error:', error[degree])
- print('Bias^2:', bias[degree])
- print('Var:', variance[degree])
- print('{} >= {} + {} = {}'.format(error[degree], bias[degree], variance[degree], bias[degree]+variance[degree]))
+ error[degree] = np.mean( np.mean((y_test - y_pred)**2, axis=1, keepdims=True) )
+ bias[degree] = np.mean( (y_test - np.mean(y_pred, axis=1, keepdims=True))**2 )
+ variance[degree] = np.mean( np.var(y_pred, axis=1, keepdims=True) )
+ print('Polynomial degree:', degree)
+ print('Error:', error[degree])
+ print('Bias^2:', bias[degree])
+ print('Var:', variance[degree])
+ print('{} >= {} + {} = {}'.format(error[degree], bias[degree], variance[degree], bias[degree]+variance[degree]))
plt.plot(polydegree, error, label='Error')
plt.plot(polydegree, bias, label='bias')
diff --git a/doc/pub/week38/html/._week38-bs009.html b/doc/pub/week38/html/._week38-bs009.html
index e3e41860a..aafd89d74 100644
--- a/doc/pub/week38/html/._week38-bs009.html
+++ b/doc/pub/week38/html/._week38-bs009.html
@@ -229,7 +229,7 @@ MathJax.Hub.Config({
training data.
"""
-print(__doc__)
+print(__doc__)
import numpy as np
import matplotlib.pyplot as plt
@@ -256,7 +256,7 @@ plt.figure(figsize.setp(ax, xticks=(), yticks=())
polynomial_features = PolynomialFeatures(degree=degrees[i],
- include_bias=False)
+ include_bias=False)
linear_regression = LinearRegression()
pipeline = Pipeline([("polynomial_features", polynomial_features),
("linear_regression", linear_regression)])
@@ -275,7 +275,7 @@ plt.figure(figsize.xlim((0, 1))
plt.ylim((-2, 2))
plt.legend(loc="best")
- plt.title("Degree {}\nMSE = {:.2e}(+/- {:.2e})".format(
+ plt.title("Degree {}\nMSE = {:.2e}(+/- {:.2e})".format(
degrees[i], -scores.mean(), scores.std()))
plt.show()
diff --git a/doc/pub/week38/html/._week38-bs011.html b/doc/pub/week38/html/._week38-bs011.html
index 708b153de..f7f17a6b6 100644
--- a/doc/pub/week38/html/._week38-bs011.html
+++ b/doc/pub/week38/html/._week38-bs011.html
@@ -236,7 +236,7 @@ with their respective energies.
import scipy.linalg as scl
from sklearn.model_selection import train_test_split
import tqdm
-sns.set(color_codes=True)
+sns.set(color_codes=True)
cmap_args=dict(vmin=-1., vmax=1., cmap='seismic')
L = 40
diff --git a/doc/pub/week38/html/._week38-bs013.html b/doc/pub/week38/html/._week38-bs013.html
index 93870ee18..52ab2937a 100644
--- a/doc/pub/week38/html/._week38-bs013.html
+++ b/doc/pub/week38/html/._week38-bs013.html
@@ -245,7 +245,7 @@ X_test_own = np
diff --git a/doc/pub/week38/html/._week38-bs014.html b/doc/pub/week38/html/._week38-bs014.html
index b4c1426de..d47ba9fac 100644
--- a/doc/pub/week38/html/._week38-bs014.html
+++ b/doc/pub/week38/html/._week38-bs014.html
@@ -247,7 +247,7 @@ linear system as an equation would reduce this down to
diff --git a/doc/pub/week38/html/._week38-bs015.html b/doc/pub/week38/html/._week38-bs015.html
index cef66a352..3e428028f 100644
--- a/doc/pub/week38/html/._week38-bs015.html
+++ b/doc/pub/week38/html/._week38-bs015.html
@@ -236,7 +236,7 @@ We will look at a system of \( L = 40 \) spins with a coupling constant of \( J
from sklearn.model_selection import train_test_split
import sklearn.linear_model as skl
import tqdm
-sns.set(color_codes=True)
+sns.set(color_codes=True)
cmap_args=dict(vmin=-1., vmax=1., cmap='seismic')
L = 40
diff --git a/doc/pub/week38/html/._week38-bs019.html b/doc/pub/week38/html/._week38-bs019.html
index ce094b57c..79f24a7a9 100644
--- a/doc/pub/week38/html/._week38-bs019.html
+++ b/doc/pub/week38/html/._week38-bs019.html
@@ -229,7 +229,7 @@ colors = {
lambdas,
train_errors[key],
colors[key],
- label="Train {0}".format(key),
+ label="Train {0}".format(key),
linewidth=4.0
)
@@ -238,7 +238,7 @@ colors = {
lambdas,
test_errors[key],
colors[key] + "--",
- label="Test {0}".format(key),
+ label="Test {0}".format(key),
linewidth=4.0
)
plt.legend(loc="best", fontsize=18)
diff --git a/doc/pub/week38/html/._week38-bs020.html b/doc/pub/week38/html/._week38-bs020.html
index 6048c5960..9b74762a1 100644
--- a/doc/pub/week38/html/._week38-bs020.html
+++ b/doc/pub/week38/html/._week38-bs020.html
@@ -206,7 +206,7 @@ MathJax.Hub.Config({
-Video of Lecture and link to handwritten notes.
+Video of Lecture and link to handwritten notes.
diff --git a/doc/pub/week38/html/._week38-bs027.html b/doc/pub/week38/html/._week38-bs027.html
index 1ba595ea8..393e72063 100644
--- a/doc/pub/week38/html/._week38-bs027.html
+++ b/doc/pub/week38/html/._week38-bs027.html
@@ -246,7 +246,7 @@ DATA_ID = "
return os.path.join(DATA_ID, dat_id)
def save_fig(fig_id):
- plt.savefig(image_path(fig_id) + ".png", format='png')
+ plt.savefig(image_path(fig_id) + ".png", format='png')
infile = open(data_path("chddata.csv"),'r')
diff --git a/doc/pub/week38/html/._week38-bs030.html b/doc/pub/week38/html/._week38-bs030.html
index d30786436..0d82b723f 100644
--- a/doc/pub/week38/html/._week38-bs030.html
+++ b/doc/pub/week38/html/._week38-bs030.html
@@ -229,7 +229,7 @@ ax = fig..plot(z, sigma)
ax.set_ylim([-0.1, 1.1])
ax.set_xlim([-5,5])
-ax.grid(True)
+ax.grid(True)
ax.set_xlabel('z')
ax.set_title('sigmoid function')
@@ -245,7 +245,7 @@ ax = fig..def ols_inv(x: np.ndarray, y: np.ndarray) -> np.ndarray:
- return scl.inv(x.T @ x) @ (x.T @ y)
+ return scl.inv(x.T @ x) @ (x.T @ y)
beta = ols_inv(X_train_own, y_train)
def ols_svd(x: np.ndarray, y: np.ndarray) -> np.ndarray:
u, s, v = scl.svd(x)
- return v.T @ scl.pinv(scl.diagsvd(s, u.shape[0], v.shape[0])) @ u.T @ y
+ return v.T @ scl.pinv(scl.diagsvd(s, u.shape[0], v.shape[0])) @ u.T @ y
Friday September 18: Intro to Logistic Regression
diff --git a/doc/pub/week38/html/._week38-bs040.html b/doc/pub/week38/html/._week38-bs040.html index 957f0bc92..c8f853e98 100644 --- a/doc/pub/week38/html/._week38-bs040.html +++ b/doc/pub/week38/html/._week38-bs040.html @@ -243,7 +243,7 @@ correlation_matrix = cancerpd# use the heatmap function from seaborn to plot the correlation matrix # annot = True to print the values inside the square plt.figure(figsize=(15,8)) -sns.heatmap(data=correlation_matrix, annot=True) +sns.heatmap(data=correlation_matrix, annot=True) plt.show()
diff --git a/doc/pub/week38/html/._week38-bs042.html b/doc/pub/week38/html/._week38-bs042.html index ea7f33026..37d57fd69 100644 --- a/doc/pub/week38/html/._week38-bs042.html +++ b/doc/pub/week38/html/._week38-bs042.html @@ -217,12 +217,12 @@ MathJax.Hub.Config({ cancer = load_breast_cancer() X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,random_state=0) -print(X_train.shape) -print(X_test.shape) +print(X_train.shape) +print(X_test.shape) # Logistic Regression logreg = LogisticRegression(solver='lbfgs') logreg.fit(X_train, y_train) -print("Test set accuracy with Logistic Regression: {:.2f}".format(logreg.score(X_test,y_test))) +print("Test set accuracy with Logistic Regression: {:.2f}".format(logreg.score(X_test,y_test))) #now scale the data from sklearn.preprocessing import StandardScaler scaler = StandardScaler() @@ -231,20 +231,20 @@ X_train_scaled = scaler= scaler.transform(X_test) # Logistic Regression logreg.fit(X_train_scaled, y_train) -print("Test set accuracy Logistic Regression with scaled data: {:.2f}".format(logreg.score(X_test_scaled,y_test))) +print("Test set accuracy Logistic Regression with scaled data: {:.2f}".format(logreg.score(X_test_scaled,y_test))) from sklearn.preprocessing import LabelEncoder from sklearn.model_selection import cross_validate #Cross validation accuracy = cross_validate(logreg,X_test_scaled,y_test,cv=10)['test_score'] -print(accuracy) -print("Test set accuracy with Logistic Regression and scaled data: {:.2f}".format(logreg.score(X_test_scaled,y_test))) +print(accuracy) +print("Test set accuracy with Logistic Regression and scaled data: {:.2f}".format(logreg.score(X_test_scaled,y_test))) import scikitplot as skplt y_pred = logreg.predict(X_test_scaled) -skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=True) +skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=True) plt.show() y_probas = logreg.predict_proba(X_test_scaled) skplt.metrics.plot_roc(y_test, y_probas) diff --git a/doc/pub/week38/html/week38-bs.html b/doc/pub/week38/html/week38-bs.html index e0f7360df..f03c8cdf8 100644 --- a/doc/pub/week38/html/week38-bs.html +++ b/doc/pub/week38/html/week38-bs.html @@ -222,7 +222,7 @@ MathJax.Hub.Config({
-
diff --git a/doc/pub/week38/html/week38-reveal.html b/doc/pub/week38/html/week38-reveal.html index 44f13e13f..6f3707bea 100644 --- a/doc/pub/week38/html/week38-reveal.html +++ b/doc/pub/week38/html/week38-reveal.html @@ -148,7 +148,7 @@ MathJax.Hub.Config({
-
@@ -456,21 +456,21 @@ polydegree = np.zeros(maxdegree) x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2) for degree in range(maxdegree): - model = make_pipeline(PolynomialFeatures(degree=degree), LinearRegression(fit_intercept=False)) + model = make_pipeline(PolynomialFeatures(degree=degree), LinearRegression(fit_intercept=False)) y_pred = np.empty((y_test.shape[0], n_boostraps)) for i in range(n_boostraps): x_, y_ = resample(x_train, y_train) y_pred[:, i] = model.fit(x_, y_).predict(x_test).ravel() polydegree[degree] = degree - error[degree] = np.mean( np.mean((y_test - y_pred)**2, axis=1, keepdims=True) ) - bias[degree] = np.mean( (y_test - np.mean(y_pred, axis=1, keepdims=True))**2 ) - variance[degree] = np.mean( np.var(y_pred, axis=1, keepdims=True) ) - print('Polynomial degree:', degree) - print('Error:', error[degree]) - print('Bias^2:', bias[degree]) - print('Var:', variance[degree]) - print('{} >= {} + {} = {}'.format(error[degree], bias[degree], variance[degree], bias[degree]+variance[degree])) + error[degree] = np.mean( np.mean((y_test - y_pred)**2, axis=1, keepdims=True) ) + bias[degree] = np.mean( (y_test - np.mean(y_pred, axis=1, keepdims=True))**2 ) + variance[degree] = np.mean( np.var(y_pred, axis=1, keepdims=True) ) + print('Polynomial degree:', degree) + print('Error:', error[degree]) + print('Bias^2:', bias[degree]) + print('Var:', variance[degree]) + print('{} >= {} + {} = {}'.format(error[degree], bias[degree], variance[degree], bias[degree]+variance[degree])) plt.plot(polydegree, error, label='Error') plt.plot(polydegree, bias, label='bias') @@ -508,7 +508,7 @@ plt.show() training data. """ -print(__doc__) +print(__doc__) import numpy as np import matplotlib.pyplot as plt @@ -535,7 +535,7 @@ plt.figure(figsize=(14, False) + include_bias=False) linear_regression = LinearRegression() pipeline = Pipeline([("polynomial_features", polynomial_features), ("linear_regression", linear_regression)]) @@ -641,7 +641,7 @@ with their respective energies. import scipy.linalg as scl from sklearn.model_selection import train_test_split import tqdm -sns.set(color_codes=True) +sns.set(color_codes=True) cmap_args=dict(vmin=-1., vmax=1., cmap='seismic') L = 40 @@ -768,7 +768,7 @@ X_test_own = np.concatenate(
def ols_inv(x: np.ndarray, y: np.ndarray) -> np.ndarray:
- return scl.inv(x.T @ x) @ (x.T @ y)
+ return scl.inv(x.T @ x) @ (x.T @ y)
beta = ols_inv(X_train_own, y_train)
def ols_svd(x: np.ndarray, y: np.ndarray) -> np.ndarray:
u, s, v = scl.svd(x)
- return v.T @ scl.pinv(scl.diagsvd(s, u.shape[0], v.shape[0])) @ u.T @ y
+ return v.T @ scl.pinv(scl.diagsvd(s, u.shape[0], v.shape[0])) @ u.T @ y
@@ -903,7 +903,7 @@ We will look at a system of \( L = 40 \) spins with a coupling constant of \( J from sklearn.model_selection import train_test_split import sklearn.linear_model as skl import tqdm -sns.set(color_codes=True) +sns.set(color_codes=True) cmap_args=dict(vmin=-1., vmax=1., cmap='seismic') L = 40 @@ -1197,7 +1197,7 @@ other models for all values of \( \lambda \).
-Video of Lecture and link to handwritten notes.
+Video of Lecture and link to handwritten notes.
@@ -1384,7 +1384,7 @@ DATA_ID = "DataFiles/"
return os.path.join(DATA_ID, dat_id)
def save_fig(fig_id):
- plt.savefig(image_path(fig_id) + ".png", format='png')
+ plt.savefig(image_path(fig_id) + ".png", format='png')
infile = open(data_path("chddata.csv"),'r')
@@ -1500,7 +1500,7 @@ ax = fig.add_subplot(111)
ax.plot(z, sigma)
ax.set_ylim([-0.1, 1.1])
ax.set_xlim([-5,5])
-ax.grid(True)
+ax.grid(True)
ax.set_xlabel('z')
ax.set_title('sigmoid function')
@@ -1516,7 +1516,7 @@ ax = fig.add_subplot(111)
ax.plot(z, step)
ax.set_ylim([-0.5, 1.5])
ax.set_xlim([-5,5])
-ax.grid(True)
+ax.grid(True)
ax.set_xlabel('z')
ax.set_title('step function')
@@ -1531,7 +1531,7 @@ ax = fig.add_subplot(111)
ax.plot(z, t)
ax.set_ylim([-1.0, 1.0])
ax.set_xlim([-2*mt.pi,2*mt.pi])
-ax.grid(True)
+ax.grid(True)
ax.set_xlabel('z')
ax.set_title('tanh function')
@@ -1793,12 +1793,12 @@ classification.
cancer = load_breast_cancer()
X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,random_state=0)
-print(X_train.shape)
-print(X_test.shape)
+print(X_train.shape)
+print(X_test.shape)
# Logistic Regression
logreg = LogisticRegression(solver='lbfgs')
logreg.fit(X_train, y_train)
-print("Test set accuracy with Logistic Regression: {:.2f}".format(logreg.score(X_test,y_test)))
+print("Test set accuracy with Logistic Regression: {:.2f}".format(logreg.score(X_test,y_test)))
#now scale the data
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
@@ -1807,7 +1807,7 @@ X_train_scaled = scaler.transform(X_train)
X_test_scaled = scaler.transform(X_test)
# Logistic Regression
logreg.fit(X_train_scaled, y_train)
-print("Test set accuracy Logistic Regression with scaled data: {:.2f}".format(logreg.score(X_test_scaled,y_test)))
+print("Test set accuracy Logistic Regression with scaled data: {:.2f}".format(logreg.score(X_test_scaled,y_test)))
@@ -1853,7 +1853,7 @@ correlation_matrix = cancerpd.corr().round(1
# use the heatmap function from seaborn to plot the correlation matrix
# annot = True to print the values inside the square
plt.figure(figsize=(15,8))
-sns.heatmap(data=correlation_matrix, annot=True)
+sns.heatmap(data=correlation_matrix, annot=True)
plt.show()
@@ -1913,12 +1913,12 @@ applications. This will be discussed later this semester (0)
-print(X_train.shape)
-print(X_test.shape)
+print(X_train.shape)
+print(X_test.shape)
# Logistic Regression
logreg = LogisticRegression(solver='lbfgs')
logreg.fit(X_train, y_train)
-print("Test set accuracy with Logistic Regression: {:.2f}".format(logreg.score(X_test,y_test)))
+print("Test set accuracy with Logistic Regression: {:.2f}".format(logreg.score(X_test,y_test)))
#now scale the data
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
@@ -1927,20 +1927,20 @@ X_train_scaled = scaler.transform(X_train)
X_test_scaled = scaler.transform(X_test)
# Logistic Regression
logreg.fit(X_train_scaled, y_train)
-print("Test set accuracy Logistic Regression with scaled data: {:.2f}".format(logreg.score(X_test_scaled,y_test)))
+print("Test set accuracy Logistic Regression with scaled data: {:.2f}".format(logreg.score(X_test_scaled,y_test)))
from sklearn.preprocessing import LabelEncoder
from sklearn.model_selection import cross_validate
#Cross validation
accuracy = cross_validate(logreg,X_test_scaled,y_test,cv=10)['test_score']
-print(accuracy)
-print("Test set accuracy with Logistic Regression and scaled data: {:.2f}".format(logreg.score(X_test_scaled,y_test)))
+print(accuracy)
+print("Test set accuracy with Logistic Regression and scaled data: {:.2f}".format(logreg.score(X_test_scaled,y_test)))
import scikitplot as skplt
y_pred = logreg.predict(X_test_scaled)
-skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=True)
+skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=True)
plt.show()
y_probas = logreg.predict_proba(X_test_scaled)
skplt.metrics.plot_roc(y_test, y_probas)
diff --git a/doc/pub/week38/html/week38-solarized.html b/doc/pub/week38/html/week38-solarized.html
index 81ca55ffa..b89fb8c97 100644
--- a/doc/pub/week38/html/week38-solarized.html
+++ b/doc/pub/week38/html/week38-solarized.html
@@ -144,7 +144,7 @@ MathJax.Hub.Config({
-
@@ -774,7 +774,7 @@ linear system as an equation would reduce this down to
@@ -850,7 +850,7 @@ We will look at a system of \( L = 40 \) spins with a coupling constant of \( J
from sklearn.model_selection import train_test_split
import sklearn.linear_model as skl
import tqdm
-sns.set(color_codes=True)
+sns.set(color_codes=True)
cmap_args=dict(vmin=-1., vmax=1., cmap='seismic')
L = 40
@@ -1133,7 +1133,7 @@ other models for all values of \( \lambda \).
-Video of Lecture and link to handwritten notes.
+Video of Lecture and link to handwritten notes.
@@ -1316,7 +1316,7 @@ DATA_ID = "DataFiles/"
return os.path.join(DATA_ID, dat_id)
def save_fig(fig_id):
- plt.savefig(image_path(fig_id) + ".png", format='png')
+ plt.savefig(image_path(fig_id) + ".png", format='png')
infile = open(data_path("chddata.csv"),'r')
@@ -1427,7 +1427,7 @@ ax = fig.add_subplot(111)
ax.plot(z, sigma)
ax.set_ylim([-0.1, 1.1])
ax.set_xlim([-5,5])
-ax.grid(True)
+ax.grid(True)
ax.set_xlabel('z')
ax.set_title('sigmoid function')
@@ -1443,7 +1443,7 @@ ax = fig.add_subplot(111)
ax.plot(z, step)
ax.set_ylim([-0.5, 1.5])
ax.set_xlim([-5,5])
-ax.grid(True)
+ax.grid(True)
ax.set_xlabel('z')
ax.set_title('step function')
@@ -1458,7 +1458,7 @@ ax = fig.add_subplot(111)
ax.plot(z, t)
ax.set_ylim([-1.0, 1.0])
ax.set_xlim([-2*mt.pi,2*mt.pi])
-ax.grid(True)
+ax.grid(True)
ax.set_xlabel('z')
ax.set_title('tanh function')
@@ -1685,12 +1685,12 @@ classification.
cancer = load_breast_cancer()
X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,random_state=0)
-print(X_train.shape)
-print(X_test.shape)
+print(X_train.shape)
+print(X_test.shape)
# Logistic Regression
logreg = LogisticRegression(solver='lbfgs')
logreg.fit(X_train, y_train)
-print("Test set accuracy with Logistic Regression: {:.2f}".format(logreg.score(X_test,y_test)))
+print("Test set accuracy with Logistic Regression: {:.2f}".format(logreg.score(X_test,y_test)))
#now scale the data
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
@@ -1699,7 +1699,7 @@ X_train_scaled = scaler.transform(X_train)
X_test_scaled = scaler.transform(X_test)
# Logistic Regression
logreg.fit(X_train_scaled, y_train)
-print("Test set accuracy Logistic Regression with scaled data: {:.2f}".format(logreg.score(X_test_scaled,y_test)))
+print("Test set accuracy Logistic Regression with scaled data: {:.2f}".format(logreg.score(X_test_scaled,y_test)))
@@ -1803,12 +1803,12 @@ applications. This will be discussed later this semester (0)
-print(X_train.shape)
-print(X_test.shape)
+print(X_train.shape)
+print(X_test.shape)
# Logistic Regression
logreg = LogisticRegression(solver='lbfgs')
logreg.fit(X_train, y_train)
-print("Test set accuracy with Logistic Regression: {:.2f}".format(logreg.score(X_test,y_test)))
+print("Test set accuracy with Logistic Regression: {:.2f}".format(logreg.score(X_test,y_test)))
#now scale the data
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
@@ -1817,20 +1817,20 @@ X_train_scaled = scaler.transform(X_train)
X_test_scaled = scaler.transform(X_test)
# Logistic Regression
logreg.fit(X_train_scaled, y_train)
-print("Test set accuracy Logistic Regression with scaled data: {:.2f}".format(logreg.score(X_test_scaled,y_test)))
+print("Test set accuracy Logistic Regression with scaled data: {:.2f}".format(logreg.score(X_test_scaled,y_test)))
from sklearn.preprocessing import LabelEncoder
from sklearn.model_selection import cross_validate
#Cross validation
accuracy = cross_validate(logreg,X_test_scaled,y_test,cv=10)['test_score']
-print(accuracy)
-print("Test set accuracy with Logistic Regression and scaled data: {:.2f}".format(logreg.score(X_test_scaled,y_test)))
+print(accuracy)
+print("Test set accuracy with Logistic Regression and scaled data: {:.2f}".format(logreg.score(X_test_scaled,y_test)))
import scikitplot as skplt
y_pred = logreg.predict(X_test_scaled)
-skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=True)
+skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=True)
plt.show()
y_probas = logreg.predict_proba(X_test_scaled)
skplt.metrics.plot_roc(y_test, y_probas)
diff --git a/doc/pub/week38/html/week38.html b/doc/pub/week38/html/week38.html
index e3e6d2912..11e3f424d 100644
--- a/doc/pub/week38/html/week38.html
+++ b/doc/pub/week38/html/week38.html
@@ -149,7 +149,7 @@ MathJax.Hub.Config({
-
@@ -779,7 +779,7 @@ linear system as an equation would reduce this down to
@@ -855,7 +855,7 @@ We will look at a system of \( L = 40 \) spins with a coupling constant of \( J
from sklearn.model_selection import train_test_split
import sklearn.linear_model as skl
import tqdm
-sns.set(color_codes=True)
+sns.set(color_codes=True)
cmap_args=dict(vmin=-1., vmax=1., cmap='seismic')
L = 40
@@ -1109,7 +1109,7 @@ colors = {
lambdas,
train_errors[key],
colors[key],
- label="Train {0}".format(key),
+ label="Train {0}".format(key),
linewidth=4.0
)
@@ -1118,7 +1118,7 @@ colors = {
lambdas,
test_errors[key],
colors[key] + "--",
- label="Test {0}".format(key),
+ label="Test {0}".format(key),
linewidth=4.0
)
plt.legend(loc="best", fontsize=18)
@@ -1138,7 +1138,7 @@ other models for all values of \( \lambda \).
-Video of Lecture and link to handwritten notes.
+Video of Lecture and link to handwritten notes.
@@ -1321,7 +1321,7 @@ DATA_ID = "
return os.path.join(DATA_ID, dat_id)
def save_fig(fig_id):
- plt.savefig(image_path(fig_id) + ".png", format='png')
+ plt.savefig(image_path(fig_id) + ".png", format='png')
infile = open(data_path("chddata.csv"),'r')
@@ -1432,7 +1432,7 @@ ax = fig..plot(z, sigma)
ax.set_ylim([-0.1, 1.1])
ax.set_xlim([-5,5])
-ax.grid(True)
+ax.grid(True)
ax.set_xlabel('z')
ax.set_title('sigmoid function')
@@ -1448,7 +1448,7 @@ ax = fig..
Sep 18, 2020
Sep 19, 2020
@@ -428,21 +428,21 @@ polydegree = np.zeros(maxdegree)
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2)
for degree in range(maxdegree):
- model = make_pipeline(PolynomialFeatures(degree=degree), LinearRegression(fit_intercept=False))
+ model = make_pipeline(PolynomialFeatures(degree=degree), LinearRegression(fit_intercept=False))
y_pred = np.empty((y_test.shape[0], n_boostraps))
for i in range(n_boostraps):
x_, y_ = resample(x_train, y_train)
y_pred[:, i] = model.fit(x_, y_).predict(x_test).ravel()
polydegree[degree] = degree
- error[degree] = np.mean( np.mean((y_test - y_pred)**2, axis=1, keepdims=True) )
- bias[degree] = np.mean( (y_test - np.mean(y_pred, axis=1, keepdims=True))**2 )
- variance[degree] = np.mean( np.var(y_pred, axis=1, keepdims=True) )
- print('Polynomial degree:', degree)
- print('Error:', error[degree])
- print('Bias^2:', bias[degree])
- print('Var:', variance[degree])
- print('{} >= {} + {} = {}'.format(error[degree], bias[degree], variance[degree], bias[degree]+variance[degree]))
+ error[degree] = np.mean( np.mean((y_test - y_pred)**2, axis=1, keepdims=True) )
+ bias[degree] = np.mean( (y_test - np.mean(y_pred, axis=1, keepdims=True))**2 )
+ variance[degree] = np.mean( np.var(y_pred, axis=1, keepdims=True) )
+ print('Polynomial degree:', degree)
+ print('Error:', error[degree])
+ print('Bias^2:', bias[degree])
+ print('Var:', variance[degree])
+ print('{} >= {} + {} = {}'.format(error[degree], bias[degree], variance[degree], bias[degree]+variance[degree]))
plt.plot(polydegree, error, label='Error')
plt.plot(polydegree, bias, label='bias')
@@ -479,7 +479,7 @@ plt.show()
training data.
"""
-print(__doc__)
+print(__doc__)
import numpy as np
import matplotlib.pyplot as plt
@@ -506,7 +506,7 @@ plt.figure(figsize=(14, False)
+ include_bias=False)
linear_regression = LinearRegression()
pipeline = Pipeline([("polynomial_features", polynomial_features),
("linear_regression", linear_regression)])
@@ -608,7 +608,7 @@ with their respective energies.
import scipy.linalg as scl
from sklearn.model_selection import train_test_split
import tqdm
-sns.set(color_codes=True)
+sns.set(color_codes=True)
cmap_args=dict(vmin=-1., vmax=1., cmap='seismic')
L = 40
@@ -724,7 +724,7 @@ X_test_own = np.concatenate(
def ols_inv(x: np.ndarray, y: np.ndarray) -> np.ndarray:
- return scl.inv(x.T @ x) @ (x.T @ y)
+ return scl.inv(x.T @ x) @ (x.T @ y)
beta = ols_inv(X_train_own, y_train)
def ols_svd(x: np.ndarray, y: np.ndarray) -> np.ndarray:
u, s, v = scl.svd(x)
- return v.T @ scl.pinv(scl.diagsvd(s, u.shape[0], v.shape[0])) @ u.T @ y
+ return v.T @ scl.pinv(scl.diagsvd(s, u.shape[0], v.shape[0])) @ u.T @ y
Friday September 18: Intro to Logistic Regression
@@ -1744,7 +1744,7 @@ correlation_matrix = cancerpd.corr().round(1
# use the heatmap function from seaborn to plot the correlation matrix
# annot = True to print the values inside the square
plt.figure(figsize=(15,8))
-sns.heatmap(data=correlation_matrix, annot=True)
+sns.heatmap(data=correlation_matrix, annot=True)
plt.show()
Sep 18, 2020
Sep 19, 2020
@@ -433,21 +433,21 @@ polydegree = np
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2)
for degree in range(maxdegree):
- model = make_pipeline(PolynomialFeatures(degree=degree), LinearRegression(fit_intercept=False))
+ model = make_pipeline(PolynomialFeatures(degree=degree), LinearRegression(fit_intercept=False))
y_pred = np.empty((y_test.shape[0], n_boostraps))
for i in range(n_boostraps):
x_, y_ = resample(x_train, y_train)
y_pred[:, i] = model.fit(x_, y_).predict(x_test).ravel()
polydegree[degree] = degree
- error[degree] = np.mean( np.mean((y_test - y_pred)**2, axis=1, keepdims=True) )
- bias[degree] = np.mean( (y_test - np.mean(y_pred, axis=1, keepdims=True))**2 )
- variance[degree] = np.mean( np.var(y_pred, axis=1, keepdims=True) )
- print('Polynomial degree:', degree)
- print('Error:', error[degree])
- print('Bias^2:', bias[degree])
- print('Var:', variance[degree])
- print('{} >= {} + {} = {}'.format(error[degree], bias[degree], variance[degree], bias[degree]+variance[degree]))
+ error[degree] = np.mean( np.mean((y_test - y_pred)**2, axis=1, keepdims=True) )
+ bias[degree] = np.mean( (y_test - np.mean(y_pred, axis=1, keepdims=True))**2 )
+ variance[degree] = np.mean( np.var(y_pred, axis=1, keepdims=True) )
+ print('Polynomial degree:', degree)
+ print('Error:', error[degree])
+ print('Bias^2:', bias[degree])
+ print('Var:', variance[degree])
+ print('{} >= {} + {} = {}'.format(error[degree], bias[degree], variance[degree], bias[degree]+variance[degree]))
plt.plot(polydegree, error, label='Error')
plt.plot(polydegree, bias, label='bias')
@@ -484,7 +484,7 @@ plt.show()
training data.
"""
-print(__doc__)
+print(__doc__)
import numpy as np
import matplotlib.pyplot as plt
@@ -511,7 +511,7 @@ plt.figure(figsize.setp(ax, xticks=(), yticks=())
polynomial_features = PolynomialFeatures(degree=degrees[i],
- include_bias=False)
+ include_bias=False)
linear_regression = LinearRegression()
pipeline = Pipeline([("polynomial_features", polynomial_features),
("linear_regression", linear_regression)])
@@ -530,7 +530,7 @@ plt.figure(figsize.xlim((0, 1))
plt.ylim((-2, 2))
plt.legend(loc="best")
- plt.title("Degree {}\nMSE = {:.2e}(+/- {:.2e})".format(
+ plt.title("Degree {}\nMSE = {:.2e}(+/- {:.2e})".format(
degrees[i], -scores.mean(), scores.std()))
plt.show()
@@ -613,7 +613,7 @@ with their respective energies.
import scipy.linalg as scl
from sklearn.model_selection import train_test_split
import tqdm
-sns.set(color_codes=True)
+sns.set(color_codes=True)
cmap_args=dict(vmin=-1., vmax=1., cmap='seismic')
L = 40
@@ -729,7 +729,7 @@ X_test_own = np
def ols_inv(x: np.ndarray, y: np.ndarray) -> np.ndarray:
- return scl.inv(x.T @ x) @ (x.T @ y)
+ return scl.inv(x.T @ x) @ (x.T @ y)
beta = ols_inv(X_train_own, y_train)
def ols_svd(x: np.ndarray, y: np.ndarray) -> np.ndarray:
u, s, v = scl.svd(x)
- return v.T @ scl.pinv(scl.diagsvd(s, u.shape[0], v.shape[0])) @ u.T @ y
+ return v.T @ scl.pinv(scl.diagsvd(s, u.shape[0], v.shape[0])) @ u.T @ y
Friday September 18: Intro to Logistic Regression
@@ -1749,7 +1749,7 @@ correlation_matrix = cancerpd# use the heatmap function from seaborn to plot the correlation matrix
# annot = True to print the values inside the square
plt.figure(figsize=(15,8))
-sns.heatmap(data=correlation_matrix, annot=True)
+sns.heatmap(data=correlation_matrix, annot=True)
plt.show()