diff --git a/doc/pub/week45/html/._week45-bs001.html b/doc/pub/week45/html/._week45-bs001.html index 0fb9f6bc0..af30ca85d 100644 --- a/doc/pub/week45/html/._week45-bs001.html +++ b/doc/pub/week45/html/._week45-bs001.html @@ -173,7 +173,7 @@ MathJax.Hub.Config({
# Common imports
+ %matplotlib inline
+
+# Common imports
from IPython.display import Image
from pydot import graph_from_dot_data
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
-from sklearn.tree import DecisionTreeClassifier
-from sklearn.tree import DecisionTreeRegressor
from sklearn.model_selection import train_test_split
from sklearn.tree import export_graphviz
from sklearn.preprocessing import StandardScaler, OneHotEncoder
from sklearn.compose import ColumnTransformer
-from IPython.display import Image
from pydot import graph_from_dot_data
from sklearn.datasets import load_breast_cancer
from sklearn.svm import SVC
from sklearn.linear_model import LogisticRegression
-from sklearn.ensemble import BaggingClassifier
-
+from sklearn.ensemble import RandomForestClassifier
+from sklearn.preprocessing import LabelEncoder
+from sklearn.model_selection import cross_validate
+import scikitplot as skplt
+from sklearn.preprocessing import StandardScaler
import os
# Where to save the figures and data files
@@ -229,37 +231,31 @@ X_train, X_test, y_train, y_test = train_tes
print(X_train.shape)
print(X_test.shape)
#Scale the data
-from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
scaler.fit(X_train)
X_train_scaled = scaler.transform(X_train)
X_test_scaled = scaler.transform(X_test)
#define methods
# Logistic Regression
+logreg = LogisticRegression(solver='lbfgs')
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)))
-# Support Vector Machine
-svm.fit(X_train_scaled, y_train)
-print("Test set accuracy SVM with scaled data: {:.2f}".format(logreg.score(X_test_scaled,y_test)))
# Decision Trees
+deep_tree_clf = DecisionTreeClassifier(max_depth=None)
deep_tree_clf.fit(X_train_scaled, y_train)
print("Test set accuracy with Decision Trees and scaled data: {:.2f}".format(deep_tree_clf.score(X_test_scaled,y_test)))
-
-
-from sklearn.ensemble import RandomForestClassifier
-from sklearn.preprocessing import LabelEncoder
-from sklearn.model_selection import cross_validate
-# Data set not specificied
+# Support Vector Machine
+svm = SVC(gamma='auto', C=100)
+svm.fit(X_train_scaled, y_train)
+print("Test set accuracy SVM with scaled data: {:.2f}".format(logreg.score(X_test_scaled,y_test)))
+# Random forests
#Instantiate the model with 500 trees and entropy as splitting criteria
Random_Forest_model = RandomForestClassifier(n_estimators=500,criterion="entropy")
Random_Forest_model.fit(X_train_scaled, y_train)
-#Cross validation
-accuracy = cross_validate(Random_Forest_model,X_test_scaled,y_test,cv=10)['test_score']
-print(accuracy)
print("Test set accuracy with Random Forests and scaled data: {:.2f}".format(Random_Forest_model.score(X_test_scaled,y_test)))
-import scikitplot as skplt
+
y_pred = Random_Forest_model.predict(X_test_scaled)
skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=True)
plt.show()
diff --git a/doc/pub/week45/html/week45-reveal.html b/doc/pub/week45/html/week45-reveal.html
index 3f8253074..6cc7c9a20 100644
--- a/doc/pub/week45/html/week45-reveal.html
+++ b/doc/pub/week45/html/week45-reveal.html
@@ -199,7 +199,7 @@ MathJax.Hub.Config({
# Common imports
+ %matplotlib inline
+
+# Common imports
from IPython.display import Image
from pydot import graph_from_dot_data
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
-from sklearn.tree import DecisionTreeClassifier
-from sklearn.tree import DecisionTreeRegressor
from sklearn.model_selection import train_test_split
from sklearn.tree import export_graphviz
from sklearn.preprocessing import StandardScaler, OneHotEncoder
from sklearn.compose import ColumnTransformer
-from IPython.display import Image
from pydot import graph_from_dot_data
from sklearn.datasets import load_breast_cancer
from sklearn.svm import SVC
from sklearn.linear_model import LogisticRegression
-from sklearn.ensemble import BaggingClassifier
-
+from sklearn.ensemble import RandomForestClassifier
+from sklearn.preprocessing import LabelEncoder
+from sklearn.model_selection import cross_validate
+import scikitplot as skplt
+from sklearn.preprocessing import StandardScaler
import os
# Where to save the figures and data files
@@ -282,37 +286,31 @@ X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,ra
print(X_train.shape)
print(X_test.shape)
#Scale the data
-from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
scaler.fit(X_train)
X_train_scaled = scaler.transform(X_train)
X_test_scaled = scaler.transform(X_test)
#define methods
# Logistic Regression
+logreg = LogisticRegression(solver='lbfgs')
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)))
-# Support Vector Machine
-svm.fit(X_train_scaled, y_train)
-print("Test set accuracy SVM with scaled data: {:.2f}".format(logreg.score(X_test_scaled,y_test)))
# Decision Trees
+deep_tree_clf = DecisionTreeClassifier(max_depth=None)
deep_tree_clf.fit(X_train_scaled, y_train)
print("Test set accuracy with Decision Trees and scaled data: {:.2f}".format(deep_tree_clf.score(X_test_scaled,y_test)))
-
-
-from sklearn.ensemble import RandomForestClassifier
-from sklearn.preprocessing import LabelEncoder
-from sklearn.model_selection import cross_validate
-# Data set not specificied
+# Support Vector Machine
+svm = SVC(gamma='auto', C=100)
+svm.fit(X_train_scaled, y_train)
+print("Test set accuracy SVM with scaled data: {:.2f}".format(logreg.score(X_test_scaled,y_test)))
+# Random forests
#Instantiate the model with 500 trees and entropy as splitting criteria
Random_Forest_model = RandomForestClassifier(n_estimators=500,criterion="entropy")
Random_Forest_model.fit(X_train_scaled, y_train)
-#Cross validation
-accuracy = cross_validate(Random_Forest_model,X_test_scaled,y_test,cv=10)['test_score']
-print(accuracy)
print("Test set accuracy with Random Forests and scaled data: {:.2f}".format(Random_Forest_model.score(X_test_scaled,y_test)))
-import scikitplot as skplt
+
y_pred = Random_Forest_model.predict(X_test_scaled)
skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=True)
plt.show()
diff --git a/doc/pub/week45/html/week45-solarized.html b/doc/pub/week45/html/week45-solarized.html
index 227923c39..55970f5e3 100644
--- a/doc/pub/week45/html/week45-solarized.html
+++ b/doc/pub/week45/html/week45-solarized.html
@@ -176,7 +176,7 @@ MathJax.Hub.Config({
# Common imports
+ %matplotlib inline
+
+# Common imports
from IPython.display import Image
from pydot import graph_from_dot_data
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
-from sklearn.tree import DecisionTreeClassifier
-from sklearn.tree import DecisionTreeRegressor
from sklearn.model_selection import train_test_split
from sklearn.tree import export_graphviz
from sklearn.preprocessing import StandardScaler, OneHotEncoder
from sklearn.compose import ColumnTransformer
-from IPython.display import Image
from pydot import graph_from_dot_data
from sklearn.datasets import load_breast_cancer
from sklearn.svm import SVC
from sklearn.linear_model import LogisticRegression
-from sklearn.ensemble import BaggingClassifier
-
+from sklearn.ensemble import RandomForestClassifier
+from sklearn.preprocessing import LabelEncoder
+from sklearn.model_selection import cross_validate
+import scikitplot as skplt
+from sklearn.preprocessing import StandardScaler
import os
# Where to save the figures and data files
@@ -258,37 +262,31 @@ X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,ra
print(X_train.shape)
print(X_test.shape)
#Scale the data
-from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
scaler.fit(X_train)
X_train_scaled = scaler.transform(X_train)
X_test_scaled = scaler.transform(X_test)
#define methods
# Logistic Regression
+logreg = LogisticRegression(solver='lbfgs')
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)))
-# Support Vector Machine
-svm.fit(X_train_scaled, y_train)
-print("Test set accuracy SVM with scaled data: {:.2f}".format(logreg.score(X_test_scaled,y_test)))
# Decision Trees
+deep_tree_clf = DecisionTreeClassifier(max_depth=None)
deep_tree_clf.fit(X_train_scaled, y_train)
print("Test set accuracy with Decision Trees and scaled data: {:.2f}".format(deep_tree_clf.score(X_test_scaled,y_test)))
-
-
-from sklearn.ensemble import RandomForestClassifier
-from sklearn.preprocessing import LabelEncoder
-from sklearn.model_selection import cross_validate
-# Data set not specificied
+# Support Vector Machine
+svm = SVC(gamma='auto', C=100)
+svm.fit(X_train_scaled, y_train)
+print("Test set accuracy SVM with scaled data: {:.2f}".format(logreg.score(X_test_scaled,y_test)))
+# Random forests
#Instantiate the model with 500 trees and entropy as splitting criteria
Random_Forest_model = RandomForestClassifier(n_estimators=500,criterion="entropy")
Random_Forest_model.fit(X_train_scaled, y_train)
-#Cross validation
-accuracy = cross_validate(Random_Forest_model,X_test_scaled,y_test,cv=10)['test_score']
-print(accuracy)
print("Test set accuracy with Random Forests and scaled data: {:.2f}".format(Random_Forest_model.score(X_test_scaled,y_test)))
-import scikitplot as skplt
+
y_pred = Random_Forest_model.predict(X_test_scaled)
skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=True)
plt.show()
diff --git a/doc/pub/week45/html/week45.html b/doc/pub/week45/html/week45.html
index cb9dfef72..3127dc949 100644
--- a/doc/pub/week45/html/week45.html
+++ b/doc/pub/week45/html/week45.html
@@ -253,7 +253,7 @@ MathJax.Hub.Config({
# Common imports
+ %matplotlib inline
+
+# Common imports
from IPython.display import Image
from pydot import graph_from_dot_data
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
-from sklearn.tree import DecisionTreeClassifier
-from sklearn.tree import DecisionTreeRegressor
from sklearn.model_selection import train_test_split
from sklearn.tree import export_graphviz
from sklearn.preprocessing import StandardScaler, OneHotEncoder
from sklearn.compose import ColumnTransformer
-from IPython.display import Image
from pydot import graph_from_dot_data
from sklearn.datasets import load_breast_cancer
from sklearn.svm import SVC
from sklearn.linear_model import LogisticRegression
-from sklearn.ensemble import BaggingClassifier
-
+from sklearn.ensemble import RandomForestClassifier
+from sklearn.preprocessing import LabelEncoder
+from sklearn.model_selection import cross_validate
+import scikitplot as skplt
+from sklearn.preprocessing import StandardScaler
import os
# Where to save the figures and data files
@@ -335,37 +339,31 @@ X_train, X_test, y_train, y_test = train_tes
print(X_train.shape)
print(X_test.shape)
#Scale the data
-from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
scaler.fit(X_train)
X_train_scaled = scaler.transform(X_train)
X_test_scaled = scaler.transform(X_test)
#define methods
# Logistic Regression
+logreg = LogisticRegression(solver='lbfgs')
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)))
-# Support Vector Machine
-svm.fit(X_train_scaled, y_train)
-print("Test set accuracy SVM with scaled data: {:.2f}".format(logreg.score(X_test_scaled,y_test)))
# Decision Trees
+deep_tree_clf = DecisionTreeClassifier(max_depth=None)
deep_tree_clf.fit(X_train_scaled, y_train)
print("Test set accuracy with Decision Trees and scaled data: {:.2f}".format(deep_tree_clf.score(X_test_scaled,y_test)))
-
-
-from sklearn.ensemble import RandomForestClassifier
-from sklearn.preprocessing import LabelEncoder
-from sklearn.model_selection import cross_validate
-# Data set not specificied
+# Support Vector Machine
+svm = SVC(gamma='auto', C=100)
+svm.fit(X_train_scaled, y_train)
+print("Test set accuracy SVM with scaled data: {:.2f}".format(logreg.score(X_test_scaled,y_test)))
+# Random forests
#Instantiate the model with 500 trees and entropy as splitting criteria
Random_Forest_model = RandomForestClassifier(n_estimators=500,criterion="entropy")
Random_Forest_model.fit(X_train_scaled, y_train)
-#Cross validation
-accuracy = cross_validate(Random_Forest_model,X_test_scaled,y_test,cv=10)['test_score']
-print(accuracy)
print("Test set accuracy with Random Forests and scaled data: {:.2f}".format(Random_Forest_model.score(X_test_scaled,y_test)))
-import scikitplot as skplt
+
y_pred = Random_Forest_model.predict(X_test_scaled)
skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=True)
plt.show()
diff --git a/doc/pub/week45/ipynb/Results/FigureFiles/gdclassiffiercgain.png b/doc/pub/week45/ipynb/Results/FigureFiles/gdclassiffiercgain.png
index 455369c77..ffba89938 100644
Binary files a/doc/pub/week45/ipynb/Results/FigureFiles/gdclassiffiercgain.png and b/doc/pub/week45/ipynb/Results/FigureFiles/gdclassiffiercgain.png differ
diff --git a/doc/pub/week45/ipynb/Results/FigureFiles/gdclassiffierconfusion.png b/doc/pub/week45/ipynb/Results/FigureFiles/gdclassiffierconfusion.png
index bd2dd5adf..4722b4d78 100644
Binary files a/doc/pub/week45/ipynb/Results/FigureFiles/gdclassiffierconfusion.png and b/doc/pub/week45/ipynb/Results/FigureFiles/gdclassiffierconfusion.png differ
diff --git a/doc/pub/week45/ipynb/Results/FigureFiles/gdclassiffierroc.png b/doc/pub/week45/ipynb/Results/FigureFiles/gdclassiffierroc.png
index 458ffab47..459a202f8 100644
Binary files a/doc/pub/week45/ipynb/Results/FigureFiles/gdclassiffierroc.png and b/doc/pub/week45/ipynb/Results/FigureFiles/gdclassiffierroc.png differ
diff --git a/doc/pub/week45/ipynb/Results/FigureFiles/gdregression.png b/doc/pub/week45/ipynb/Results/FigureFiles/gdregression.png
index 87fe1263d..1ed660285 100644
Binary files a/doc/pub/week45/ipynb/Results/FigureFiles/gdregression.png and b/doc/pub/week45/ipynb/Results/FigureFiles/gdregression.png differ
diff --git a/doc/pub/week45/ipynb/Results/FigureFiles/xdclassiffierconfusion.png b/doc/pub/week45/ipynb/Results/FigureFiles/xdclassiffierconfusion.png
index 3ab2f6024..7ce4eb554 100644
Binary files a/doc/pub/week45/ipynb/Results/FigureFiles/xdclassiffierconfusion.png and b/doc/pub/week45/ipynb/Results/FigureFiles/xdclassiffierconfusion.png differ
diff --git a/doc/pub/week45/ipynb/Results/FigureFiles/xdclassiffierroc.png b/doc/pub/week45/ipynb/Results/FigureFiles/xdclassiffierroc.png
index a9d37df15..9bcef7025 100644
Binary files a/doc/pub/week45/ipynb/Results/FigureFiles/xdclassiffierroc.png and b/doc/pub/week45/ipynb/Results/FigureFiles/xdclassiffierroc.png differ
diff --git a/doc/pub/week45/ipynb/ipynb-week45-src.tar.gz b/doc/pub/week45/ipynb/ipynb-week45-src.tar.gz
index 84265531f..5106caaf3 100644
Binary files a/doc/pub/week45/ipynb/ipynb-week45-src.tar.gz and b/doc/pub/week45/ipynb/ipynb-week45-src.tar.gz differ
diff --git a/doc/pub/week45/ipynb/week45.ipynb b/doc/pub/week45/ipynb/week45.ipynb
index 6ea3e6a01..ec1733e0d 100644
--- a/doc/pub/week45/ipynb/week45.ipynb
+++ b/doc/pub/week45/ipynb/week45.ipynb
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "markdown",
- "id": "06bf33a6",
+ "id": "5d0f5baa",
"metadata": {
"editable": true
},
@@ -14,7 +14,7 @@
},
{
"cell_type": "markdown",
- "id": "b1777bc2",
+ "id": "a1cc809f",
"metadata": {
"editable": true
},
@@ -29,7 +29,7 @@
},
{
"cell_type": "markdown",
- "id": "f97929b1",
+ "id": "71a0b699",
"metadata": {
"editable": true
},
@@ -38,7 +38,7 @@
"\n",
"* Thursday: Boosting methods, froma AdaBoost to Gradient boosting\n",
"\n",
- "* Friday: Gradient boosting and discussion of Decision trees and ensemble methods\n",
+ "* Friday: Gradient boosting and discussion of Decision trees and ensemble methods. Wrapping up trees and start discussing Support Vector Machines\n",
"\n",
"**Videos.**\n",
"\n",
@@ -46,14 +46,18 @@
"\n",
"2. [Video on boosting methods by Hastie](https://www.youtube.com/watch?v=wPqtzj5VZus&ab_channel=H2O.ai).\n",
"\n",
+ "3. [Video on AdaBoost](https://www.youtube.com/watch?v=LsK-xG1cLYA)\n",
+ "\n",
+ "4. [Video on Gradient boost, part 1, parts 2-4 follows](https://www.youtube.com/watch?v=3CC4N4z3GJc)\n",
+ "\n",
"**Reading.**\n",
"\n",
- "1. Add material about AdaBoost and Gradient boosting"
+ "1. [Hastie et al, chapter 10.1-10.10](https://github.com/CompPhysics/MachineLearning/blob/master/doc/Textbooks/elementsstat.pdf)"
]
},
{
"cell_type": "markdown",
- "id": "da2cba17",
+ "id": "39e049b0",
"metadata": {
"editable": true
},
@@ -64,13 +68,15 @@
{
"cell_type": "code",
"execution_count": 1,
- "id": "1054a91d",
+ "id": "ebd16dd3",
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
+ "%matplotlib inline\n",
+ "\n",
"%matplotlib inline\n",
"\n",
"# Common imports\n",
@@ -79,19 +85,19 @@
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
- "from sklearn.tree import DecisionTreeClassifier\n",
- "from sklearn.tree import DecisionTreeRegressor\n",
"from sklearn.model_selection import train_test_split\n",
"from sklearn.tree import export_graphviz\n",
"from sklearn.preprocessing import StandardScaler, OneHotEncoder\n",
"from sklearn.compose import ColumnTransformer\n",
- "from IPython.display import Image \n",
"from pydot import graph_from_dot_data\n",
"from sklearn.datasets import load_breast_cancer\n",
"from sklearn.svm import SVC\n",
"from sklearn.linear_model import LogisticRegression\n",
- "from sklearn.ensemble import BaggingClassifier\n",
- "\n",
+ "from sklearn.ensemble import RandomForestClassifier\n",
+ "from sklearn.preprocessing import LabelEncoder\n",
+ "from sklearn.model_selection import cross_validate\n",
+ "import scikitplot as skplt\n",
+ "from sklearn.preprocessing import StandardScaler\n",
"import os\n",
"\n",
"# Where to save the figures and data files\n",
@@ -124,37 +130,31 @@
"print(X_train.shape)\n",
"print(X_test.shape)\n",
"#Scale the data\n",
- "from sklearn.preprocessing import StandardScaler\n",
"scaler = StandardScaler()\n",
"scaler.fit(X_train)\n",
"X_train_scaled = scaler.transform(X_train)\n",
"X_test_scaled = scaler.transform(X_test)\n",
"#define methods\n",
"# Logistic Regression\n",
+ "logreg = LogisticRegression(solver='lbfgs')\n",
"logreg.fit(X_train_scaled, y_train)\n",
"print(\"Test set accuracy Logistic Regression with scaled data: {:.2f}\".format(logreg.score(X_test_scaled,y_test)))\n",
- "# Support Vector Machine\n",
- "svm.fit(X_train_scaled, y_train)\n",
- "print(\"Test set accuracy SVM with scaled data: {:.2f}\".format(logreg.score(X_test_scaled,y_test)))\n",
"# Decision Trees\n",
+ "deep_tree_clf = DecisionTreeClassifier(max_depth=None)\n",
"deep_tree_clf.fit(X_train_scaled, y_train)\n",
"print(\"Test set accuracy with Decision Trees and scaled data: {:.2f}\".format(deep_tree_clf.score(X_test_scaled,y_test)))\n",
- "\n",
- "\n",
- "from sklearn.ensemble import RandomForestClassifier\n",
- "from sklearn.preprocessing import LabelEncoder\n",
- "from sklearn.model_selection import cross_validate\n",
- "# Data set not specificied\n",
+ "# Support Vector Machine\n",
+ "svm = SVC(gamma='auto', C=100)\n",
+ "svm.fit(X_train_scaled, y_train)\n",
+ "print(\"Test set accuracy SVM with scaled data: {:.2f}\".format(logreg.score(X_test_scaled,y_test)))\n",
+ "# Random forests\n",
"#Instantiate the model with 500 trees and entropy as splitting criteria\n",
"Random_Forest_model = RandomForestClassifier(n_estimators=500,criterion=\"entropy\")\n",
"Random_Forest_model.fit(X_train_scaled, y_train)\n",
- "#Cross validation\n",
- "accuracy = cross_validate(Random_Forest_model,X_test_scaled,y_test,cv=10)['test_score']\n",
- "print(accuracy)\n",
"print(\"Test set accuracy with Random Forests and scaled data: {:.2f}\".format(Random_Forest_model.score(X_test_scaled,y_test)))\n",
"\n",
"\n",
- "import scikitplot as skplt\n",
+ "\n",
"y_pred = Random_Forest_model.predict(X_test_scaled)\n",
"skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=True)\n",
"plt.show()\n",
@@ -167,7 +167,7 @@
},
{
"cell_type": "markdown",
- "id": "b647351f",
+ "id": "d703c0d6",
"metadata": {
"editable": true
},
@@ -187,7 +187,7 @@
},
{
"cell_type": "markdown",
- "id": "e7dbffcd",
+ "id": "ccee85a0",
"metadata": {
"editable": true
},
@@ -201,7 +201,7 @@
},
{
"cell_type": "markdown",
- "id": "494a82af",
+ "id": "a519ddc4",
"metadata": {
"editable": true
},
@@ -213,7 +213,7 @@
},
{
"cell_type": "markdown",
- "id": "d27f68f8",
+ "id": "db6968e5",
"metadata": {
"editable": true
},
@@ -230,7 +230,7 @@
},
{
"cell_type": "markdown",
- "id": "4dabbeb4",
+ "id": "e7132763",
"metadata": {
"editable": true
},
@@ -242,7 +242,7 @@
},
{
"cell_type": "markdown",
- "id": "7937173f",
+ "id": "647540de",
"metadata": {
"editable": true
},
@@ -256,7 +256,7 @@
},
{
"cell_type": "markdown",
- "id": "8872158c",
+ "id": "fe9d52b3",
"metadata": {
"editable": true
},
@@ -268,7 +268,7 @@
},
{
"cell_type": "markdown",
- "id": "1e5b19b8",
+ "id": "00d09af0",
"metadata": {
"editable": true
},
@@ -281,7 +281,7 @@
},
{
"cell_type": "markdown",
- "id": "9c2e02d1",
+ "id": "722da425",
"metadata": {
"editable": true
},
@@ -293,7 +293,7 @@
},
{
"cell_type": "markdown",
- "id": "4244f14f",
+ "id": "3954663b",
"metadata": {
"editable": true
},
@@ -303,7 +303,7 @@
},
{
"cell_type": "markdown",
- "id": "91147e5f",
+ "id": "f63c1e38",
"metadata": {
"editable": true
},
@@ -331,7 +331,7 @@
},
{
"cell_type": "markdown",
- "id": "af34f35f",
+ "id": "d8d5c7ac",
"metadata": {
"editable": true
},
@@ -347,7 +347,7 @@
},
{
"cell_type": "markdown",
- "id": "cc2ea75e",
+ "id": "96cf5cd8",
"metadata": {
"editable": true
},
@@ -359,7 +359,7 @@
},
{
"cell_type": "markdown",
- "id": "5a5b4d62",
+ "id": "439579c9",
"metadata": {
"editable": true
},
@@ -370,7 +370,7 @@
},
{
"cell_type": "markdown",
- "id": "daddba87",
+ "id": "c38ab9a3",
"metadata": {
"editable": true
},
@@ -382,7 +382,7 @@
},
{
"cell_type": "markdown",
- "id": "2a6e0f8d",
+ "id": "8e21cd6d",
"metadata": {
"editable": true
},
@@ -392,7 +392,7 @@
},
{
"cell_type": "markdown",
- "id": "f39ea127",
+ "id": "704b3592",
"metadata": {
"editable": true
},
@@ -404,7 +404,7 @@
},
{
"cell_type": "markdown",
- "id": "62a2184d",
+ "id": "7476b8be",
"metadata": {
"editable": true
},
@@ -414,7 +414,7 @@
},
{
"cell_type": "markdown",
- "id": "a2781707",
+ "id": "03d12a19",
"metadata": {
"editable": true
},
@@ -426,7 +426,7 @@
},
{
"cell_type": "markdown",
- "id": "95c004bf",
+ "id": "7fb4048b",
"metadata": {
"editable": true
},
@@ -436,7 +436,7 @@
},
{
"cell_type": "markdown",
- "id": "4694fd52",
+ "id": "0c1adb18",
"metadata": {
"editable": true
},
@@ -448,7 +448,7 @@
},
{
"cell_type": "markdown",
- "id": "06aea446",
+ "id": "60880562",
"metadata": {
"editable": true
},
@@ -462,7 +462,7 @@
},
{
"cell_type": "markdown",
- "id": "20d085e6",
+ "id": "372bc35c",
"metadata": {
"editable": true
},
@@ -478,7 +478,7 @@
},
{
"cell_type": "markdown",
- "id": "acc85c07",
+ "id": "b65e2b72",
"metadata": {
"editable": true
},
@@ -490,7 +490,7 @@
},
{
"cell_type": "markdown",
- "id": "16f291d8",
+ "id": "12464e0a",
"metadata": {
"editable": true
},
@@ -506,7 +506,7 @@
},
{
"cell_type": "markdown",
- "id": "c3a7df55",
+ "id": "efc71414",
"metadata": {
"editable": true
},
@@ -518,7 +518,7 @@
},
{
"cell_type": "markdown",
- "id": "9104a175",
+ "id": "bc2c815d",
"metadata": {
"editable": true
},
@@ -528,7 +528,7 @@
},
{
"cell_type": "markdown",
- "id": "86ddaaa4",
+ "id": "de0906dc",
"metadata": {
"editable": true
},
@@ -540,7 +540,7 @@
},
{
"cell_type": "markdown",
- "id": "ec36807d",
+ "id": "fc08da05",
"metadata": {
"editable": true
},
@@ -552,7 +552,7 @@
},
{
"cell_type": "markdown",
- "id": "f102ce80",
+ "id": "1ad3aec7",
"metadata": {
"editable": true
},
@@ -564,7 +564,7 @@
},
{
"cell_type": "markdown",
- "id": "d7b0991f",
+ "id": "4d661142",
"metadata": {
"editable": true
},
@@ -575,7 +575,7 @@
},
{
"cell_type": "markdown",
- "id": "9c1752b5",
+ "id": "373fd6db",
"metadata": {
"editable": true
},
@@ -587,7 +587,7 @@
},
{
"cell_type": "markdown",
- "id": "7a9e3ab4",
+ "id": "241ade2a",
"metadata": {
"editable": true
},
@@ -598,7 +598,7 @@
},
{
"cell_type": "markdown",
- "id": "6fb6c431",
+ "id": "ced9d9f4",
"metadata": {
"editable": true
},
@@ -610,7 +610,7 @@
},
{
"cell_type": "markdown",
- "id": "46ccbf78",
+ "id": "9b361f88",
"metadata": {
"editable": true
},
@@ -620,7 +620,7 @@
},
{
"cell_type": "markdown",
- "id": "cc303451",
+ "id": "e0665101",
"metadata": {
"editable": true
},
@@ -632,7 +632,7 @@
},
{
"cell_type": "markdown",
- "id": "b1c2be38",
+ "id": "a8189cf6",
"metadata": {
"editable": true
},
@@ -644,7 +644,7 @@
},
{
"cell_type": "markdown",
- "id": "e45307bf",
+ "id": "509020f9",
"metadata": {
"editable": true
},
@@ -656,7 +656,7 @@
},
{
"cell_type": "markdown",
- "id": "edef26a5",
+ "id": "1ea5083e",
"metadata": {
"editable": true
},
@@ -668,7 +668,7 @@
},
{
"cell_type": "markdown",
- "id": "ef3f9795",
+ "id": "f021311a",
"metadata": {
"editable": true
},
@@ -678,7 +678,7 @@
},
{
"cell_type": "markdown",
- "id": "6772b2a5",
+ "id": "714b2b90",
"metadata": {
"editable": true
},
@@ -690,7 +690,7 @@
},
{
"cell_type": "markdown",
- "id": "645ab1ac",
+ "id": "57df0a90",
"metadata": {
"editable": true
},
@@ -700,7 +700,7 @@
},
{
"cell_type": "markdown",
- "id": "36afb932",
+ "id": "7dd87728",
"metadata": {
"editable": true
},
@@ -712,7 +712,7 @@
},
{
"cell_type": "markdown",
- "id": "a0e70734",
+ "id": "647ba1c0",
"metadata": {
"editable": true
},
@@ -722,7 +722,7 @@
},
{
"cell_type": "markdown",
- "id": "a20d1c75",
+ "id": "499ab775",
"metadata": {
"editable": true
},
@@ -734,7 +734,7 @@
},
{
"cell_type": "markdown",
- "id": "415dcee2",
+ "id": "6fd9ba90",
"metadata": {
"editable": true
},
@@ -744,7 +744,7 @@
},
{
"cell_type": "markdown",
- "id": "18c44408",
+ "id": "e2318f01",
"metadata": {
"editable": true
},
@@ -756,7 +756,7 @@
},
{
"cell_type": "markdown",
- "id": "2bf44e31",
+ "id": "461b32c3",
"metadata": {
"editable": true
},
@@ -766,7 +766,7 @@
},
{
"cell_type": "markdown",
- "id": "3cfed10d",
+ "id": "c8b03689",
"metadata": {
"editable": true
},
@@ -778,7 +778,7 @@
},
{
"cell_type": "markdown",
- "id": "84f4d3f8",
+ "id": "47d84c49",
"metadata": {
"editable": true
},
@@ -798,7 +798,7 @@
},
{
"cell_type": "markdown",
- "id": "4a886572",
+ "id": "16159393",
"metadata": {
"editable": true
},
@@ -810,7 +810,7 @@
},
{
"cell_type": "markdown",
- "id": "e2da363e",
+ "id": "297ad278",
"metadata": {
"editable": true
},
@@ -820,7 +820,7 @@
},
{
"cell_type": "markdown",
- "id": "aec10b1a",
+ "id": "4c619128",
"metadata": {
"editable": true
},
@@ -836,7 +836,7 @@
},
{
"cell_type": "markdown",
- "id": "1814cd1d",
+ "id": "41cd0b50",
"metadata": {
"editable": true
},
@@ -848,7 +848,7 @@
},
{
"cell_type": "markdown",
- "id": "72b3a813",
+ "id": "9ca95984",
"metadata": {
"editable": true
},
@@ -876,7 +876,7 @@
},
{
"cell_type": "markdown",
- "id": "7ec1c900",
+ "id": "1044743b",
"metadata": {
"editable": true
},
@@ -889,7 +889,7 @@
{
"cell_type": "code",
"execution_count": 2,
- "id": "341c3079",
+ "id": "fcf973b1",
"metadata": {
"collapsed": false,
"editable": true
@@ -921,7 +921,7 @@
},
{
"cell_type": "markdown",
- "id": "ddaaaa66",
+ "id": "2ec8ee43",
"metadata": {
"editable": true
},
@@ -939,7 +939,7 @@
},
{
"cell_type": "markdown",
- "id": "97b3c420",
+ "id": "740c50e2",
"metadata": {
"editable": true
},
@@ -952,7 +952,7 @@
},
{
"cell_type": "markdown",
- "id": "3e0cffa8",
+ "id": "be50ed96",
"metadata": {
"editable": true
},
@@ -964,7 +964,7 @@
},
{
"cell_type": "markdown",
- "id": "49e25f7c",
+ "id": "b247b123",
"metadata": {
"editable": true
},
@@ -974,7 +974,7 @@
},
{
"cell_type": "markdown",
- "id": "f4eda3ea",
+ "id": "8a250bd9",
"metadata": {
"editable": true
},
@@ -986,7 +986,7 @@
},
{
"cell_type": "markdown",
- "id": "6d9e5f3b",
+ "id": "01ec8e23",
"metadata": {
"editable": true
},
@@ -996,7 +996,7 @@
},
{
"cell_type": "markdown",
- "id": "f924c7ad",
+ "id": "43f1e9ca",
"metadata": {
"editable": true
},
@@ -1008,7 +1008,7 @@
},
{
"cell_type": "markdown",
- "id": "78272ab5",
+ "id": "f097d76e",
"metadata": {
"editable": true
},
@@ -1021,7 +1021,7 @@
},
{
"cell_type": "markdown",
- "id": "0c5911f7",
+ "id": "c164dbbf",
"metadata": {
"editable": true
},
@@ -1033,7 +1033,7 @@
},
{
"cell_type": "markdown",
- "id": "476e645a",
+ "id": "fa91537a",
"metadata": {
"editable": true
},
@@ -1045,7 +1045,7 @@
},
{
"cell_type": "markdown",
- "id": "0f989a46",
+ "id": "1b7f5606",
"metadata": {
"editable": true
},
@@ -1057,7 +1057,7 @@
},
{
"cell_type": "markdown",
- "id": "b2668d41",
+ "id": "953f7aa6",
"metadata": {
"editable": true
},
@@ -1067,7 +1067,7 @@
},
{
"cell_type": "markdown",
- "id": "7f5965b6",
+ "id": "08b92a46",
"metadata": {
"editable": true
},
@@ -1079,7 +1079,7 @@
},
{
"cell_type": "markdown",
- "id": "32e6877d",
+ "id": "36cf052c",
"metadata": {
"editable": true
},
@@ -1089,7 +1089,7 @@
},
{
"cell_type": "markdown",
- "id": "61785a3c",
+ "id": "554af8ba",
"metadata": {
"editable": true
},
@@ -1105,7 +1105,7 @@
},
{
"cell_type": "markdown",
- "id": "df29a69e",
+ "id": "ba8b8439",
"metadata": {
"editable": true
},
@@ -1117,7 +1117,7 @@
},
{
"cell_type": "markdown",
- "id": "d8b61f23",
+ "id": "8d9c4b52",
"metadata": {
"editable": true
},
@@ -1138,7 +1138,7 @@
},
{
"cell_type": "markdown",
- "id": "d067eeac",
+ "id": "597eaf22",
"metadata": {
"editable": true
},
@@ -1149,7 +1149,7 @@
{
"cell_type": "code",
"execution_count": 3,
- "id": "2c80d8e8",
+ "id": "251b3392",
"metadata": {
"collapsed": false,
"editable": true
@@ -1201,7 +1201,7 @@
},
{
"cell_type": "markdown",
- "id": "4128dc16",
+ "id": "bab59665",
"metadata": {
"editable": true
},
@@ -1212,7 +1212,7 @@
{
"cell_type": "code",
"execution_count": 4,
- "id": "ecc2c3bf",
+ "id": "d1b0876c",
"metadata": {
"collapsed": false,
"editable": true
@@ -1263,7 +1263,7 @@
},
{
"cell_type": "markdown",
- "id": "7aa38b8c",
+ "id": "dd7e281f",
"metadata": {
"editable": true
},
@@ -1286,7 +1286,7 @@
},
{
"cell_type": "markdown",
- "id": "6cf5f0de",
+ "id": "d2ac7037",
"metadata": {
"editable": true
},
@@ -1297,7 +1297,7 @@
{
"cell_type": "code",
"execution_count": 5,
- "id": "3d356194",
+ "id": "fd8fdb2a",
"metadata": {
"collapsed": false,
"editable": true
@@ -1349,7 +1349,7 @@
},
{
"cell_type": "markdown",
- "id": "ed420a20",
+ "id": "ba15ae38",
"metadata": {
"editable": true
},
@@ -1362,7 +1362,7 @@
{
"cell_type": "code",
"execution_count": 6,
- "id": "4de8cf9f",
+ "id": "f6f53545",
"metadata": {
"collapsed": false,
"editable": true
diff --git a/doc/src/week45/week45.do.txt b/doc/src/week45/week45.do.txt
index 2c1c8182f..1de92a3d2 100644
--- a/doc/src/week45/week45.do.txt
+++ b/doc/src/week45/week45.do.txt
@@ -6,15 +6,17 @@ DATE: today
===== Overview of week 45 =====
* Thursday: Boosting methods, froma AdaBoost to Gradient boosting
-* Friday: Gradient boosting and discussion of Decision trees and ensemble methods
+* Friday: Gradient boosting and discussion of Decision trees and ensemble methods. Wrapping up trees and start discussing Support Vector Machines
!bblock Videos
o "Video on Decision trees":"https://www.youtube.com/watch?v=RmajweUFKvM&ab_channel=Simplilearn"
o "Video on boosting methods by Hastie":"https://www.youtube.com/watch?v=wPqtzj5VZus&ab_channel=H2O.ai".
+o "Video on AdaBoost":"https://www.youtube.com/watch?v=LsK-xG1cLYA"
+o "Video on Gradient boost, part 1, parts 2-4 follows":"https://www.youtube.com/watch?v=3CC4N4z3GJc"
!eblock
!bblock Reading
-o Add material about AdaBoost and Gradient boosting
+o "Hastie et al, chapter 10.1-10.10":"https://github.com/CompPhysics/MachineLearning/blob/master/doc/Textbooks/elementsstat.pdf"
!eblock
@@ -22,25 +24,27 @@ o Add material about AdaBoost and Gradient boosting
===== Brief code reminder from last wekk =====
!bc pycod
+%matplotlib inline
+
# Common imports
from IPython.display import Image
from pydot import graph_from_dot_data
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
-from sklearn.tree import DecisionTreeClassifier
-from sklearn.tree import DecisionTreeRegressor
from sklearn.model_selection import train_test_split
from sklearn.tree import export_graphviz
from sklearn.preprocessing import StandardScaler, OneHotEncoder
from sklearn.compose import ColumnTransformer
-from IPython.display import Image
from pydot import graph_from_dot_data
from sklearn.datasets import load_breast_cancer
from sklearn.svm import SVC
from sklearn.linear_model import LogisticRegression
-from sklearn.ensemble import BaggingClassifier
-
+from sklearn.ensemble import RandomForestClassifier
+from sklearn.preprocessing import LabelEncoder
+from sklearn.model_selection import cross_validate
+import scikitplot as skplt
+from sklearn.preprocessing import StandardScaler
import os
# Where to save the figures and data files
@@ -73,37 +77,31 @@ X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,ra
print(X_train.shape)
print(X_test.shape)
#Scale the data
-from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
scaler.fit(X_train)
X_train_scaled = scaler.transform(X_train)
X_test_scaled = scaler.transform(X_test)
#define methods
# Logistic Regression
+logreg = LogisticRegression(solver='lbfgs')
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)))
-# Support Vector Machine
-svm.fit(X_train_scaled, y_train)
-print("Test set accuracy SVM with scaled data: {:.2f}".format(logreg.score(X_test_scaled,y_test)))
# Decision Trees
+deep_tree_clf = DecisionTreeClassifier(max_depth=None)
deep_tree_clf.fit(X_train_scaled, y_train)
print("Test set accuracy with Decision Trees and scaled data: {:.2f}".format(deep_tree_clf.score(X_test_scaled,y_test)))
-
-
-from sklearn.ensemble import RandomForestClassifier
-from sklearn.preprocessing import LabelEncoder
-from sklearn.model_selection import cross_validate
-# Data set not specificied
+# Support Vector Machine
+svm = SVC(gamma='auto', C=100)
+svm.fit(X_train_scaled, y_train)
+print("Test set accuracy SVM with scaled data: {:.2f}".format(logreg.score(X_test_scaled,y_test)))
+# Random forests
#Instantiate the model with 500 trees and entropy as splitting criteria
Random_Forest_model = RandomForestClassifier(n_estimators=500,criterion="entropy")
Random_Forest_model.fit(X_train_scaled, y_train)
-#Cross validation
-accuracy = cross_validate(Random_Forest_model,X_test_scaled,y_test,cv=10)['test_score']
-print(accuracy)
print("Test set accuracy with Random Forests and scaled data: {:.2f}".format(Random_Forest_model.score(X_test_scaled,y_test)))
-import scikitplot as skplt
+
y_pred = Random_Forest_model.predict(X_test_scaled)
skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=True)
plt.show()
@@ -112,7 +110,6 @@ skplt.metrics.plot_roc(y_test, y_probas)
plt.show()
skplt.metrics.plot_cumulative_gain(y_test, y_probas)
plt.show()
-
!ec