diff --git a/doc/pub/LogReg/html/._LogReg-bs000.html b/doc/pub/LogReg/html/._LogReg-bs000.html index bbb583e11..d4f17bb42 100644 --- a/doc/pub/LogReg/html/._LogReg-bs000.html +++ b/doc/pub/LogReg/html/._LogReg-bs000.html @@ -49,7 +49,8 @@ Automatically generated HTML file from DocOnce source None, '___sec4'), ('Maximum likelihood', 2, None, '___sec5'), - ('Minimizing the cross entropy', 2, None, '___sec6')]} + ('Minimizing the cross entropy', 2, None, '___sec6'), + ('A _scikit-learn_ example', 2, None, '___sec7')]} end of tocinfo --> @@ -94,6 +95,7 @@ MathJax.Hub.Config({
  • The cross-entropy as a cost function for logistic regression
  • Maximum likelihood
  • Minimizing the cross entropy
  • +
  • A scikit-learn example
  • @@ -128,7 +130,7 @@ MathJax.Hub.Config({
    [2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University

    -

    Sep 17, 2018

    +

    Sep 20, 2018


    @@ -143,6 +145,7 @@ MathJax.Hub.Config({

  • 7
  • 8
  • 9
  • +
  • 10
  • »
  • diff --git a/doc/pub/LogReg/html/._LogReg-bs001.html b/doc/pub/LogReg/html/._LogReg-bs001.html index 5bfcf585c..2b693e58c 100644 --- a/doc/pub/LogReg/html/._LogReg-bs001.html +++ b/doc/pub/LogReg/html/._LogReg-bs001.html @@ -49,7 +49,8 @@ Automatically generated HTML file from DocOnce source None, '___sec4'), ('Maximum likelihood', 2, None, '___sec5'), - ('Minimizing the cross entropy', 2, None, '___sec6')]} + ('Minimizing the cross entropy', 2, None, '___sec6'), + ('A _scikit-learn_ example', 2, None, '___sec7')]} end of tocinfo --> @@ -94,6 +95,7 @@ MathJax.Hub.Config({
  • The cross-entropy as a cost function for logistic regression
  • Maximum likelihood
  • Minimizing the cross entropy
  • +
  • A scikit-learn example
  • @@ -149,6 +151,7 @@ models, as we will see later.
  • 7
  • 8
  • 9
  • +
  • 10
  • »
  • diff --git a/doc/pub/LogReg/html/._LogReg-bs002.html b/doc/pub/LogReg/html/._LogReg-bs002.html index c7761cde7..4fec6083b 100644 --- a/doc/pub/LogReg/html/._LogReg-bs002.html +++ b/doc/pub/LogReg/html/._LogReg-bs002.html @@ -49,7 +49,8 @@ Automatically generated HTML file from DocOnce source None, '___sec4'), ('Maximum likelihood', 2, None, '___sec5'), - ('Minimizing the cross entropy', 2, None, '___sec6')]} + ('Minimizing the cross entropy', 2, None, '___sec6'), + ('A _scikit-learn_ example', 2, None, '___sec7')]} end of tocinfo --> @@ -94,6 +95,7 @@ MathJax.Hub.Config({
  • The cross-entropy as a cost function for logistic regression
  • Maximum likelihood
  • Minimizing the cross entropy
  • +
  • A scikit-learn example
  • @@ -137,6 +139,7 @@ belong.
  • 7
  • 8
  • 9
  • +
  • 10
  • »
  • diff --git a/doc/pub/LogReg/html/._LogReg-bs003.html b/doc/pub/LogReg/html/._LogReg-bs003.html index a0d1dc1b2..0b5762269 100644 --- a/doc/pub/LogReg/html/._LogReg-bs003.html +++ b/doc/pub/LogReg/html/._LogReg-bs003.html @@ -49,7 +49,8 @@ Automatically generated HTML file from DocOnce source None, '___sec4'), ('Maximum likelihood', 2, None, '___sec5'), - ('Minimizing the cross entropy', 2, None, '___sec6')]} + ('Minimizing the cross entropy', 2, None, '___sec6'), + ('A _scikit-learn_ example', 2, None, '___sec7')]} end of tocinfo --> @@ -94,6 +95,7 @@ MathJax.Hub.Config({
  • The cross-entropy as a cost function for logistic regression
  • Maximum likelihood
  • Minimizing the cross entropy
  • +
  • A scikit-learn example
  • @@ -137,6 +139,7 @@ where we use the short-hand notation
  • 7
  • 8
  • 9
  • +
  • 10
  • »
  • diff --git a/doc/pub/LogReg/html/._LogReg-bs004.html b/doc/pub/LogReg/html/._LogReg-bs004.html index 6c222f591..bb7891e84 100644 --- a/doc/pub/LogReg/html/._LogReg-bs004.html +++ b/doc/pub/LogReg/html/._LogReg-bs004.html @@ -49,7 +49,8 @@ Automatically generated HTML file from DocOnce source None, '___sec4'), ('Maximum likelihood', 2, None, '___sec5'), - ('Minimizing the cross entropy', 2, None, '___sec6')]} + ('Minimizing the cross entropy', 2, None, '___sec6'), + ('A _scikit-learn_ example', 2, None, '___sec7')]} end of tocinfo --> @@ -94,6 +95,7 @@ MathJax.Hub.Config({
  • The cross-entropy as a cost function for logistic regression
  • Maximum likelihood
  • Minimizing the cross entropy
  • +
  • A scikit-learn example
  • @@ -147,6 +149,7 @@ Note that \( 1-f(s)= f(-s) \), which will be useful shortly.
  • 7
  • 8
  • 9
  • +
  • 10
  • »
  • diff --git a/doc/pub/LogReg/html/._LogReg-bs005.html b/doc/pub/LogReg/html/._LogReg-bs005.html index 07482a3a8..cb2b2feb5 100644 --- a/doc/pub/LogReg/html/._LogReg-bs005.html +++ b/doc/pub/LogReg/html/._LogReg-bs005.html @@ -49,7 +49,8 @@ Automatically generated HTML file from DocOnce source None, '___sec4'), ('Maximum likelihood', 2, None, '___sec5'), - ('Minimizing the cross entropy', 2, None, '___sec6')]} + ('Minimizing the cross entropy', 2, None, '___sec6'), + ('A _scikit-learn_ example', 2, None, '___sec7')]} end of tocinfo --> @@ -94,6 +95,7 @@ MathJax.Hub.Config({
  • The cross-entropy as a cost function for logistic regression
  • Maximum likelihood
  • Minimizing the cross entropy
  • +
  • A scikit-learn example
  • @@ -143,6 +145,7 @@ $$
  • 7
  • 8
  • 9
  • +
  • 10
  • »
  • diff --git a/doc/pub/LogReg/html/._LogReg-bs006.html b/doc/pub/LogReg/html/._LogReg-bs006.html index bed88a490..8c6090e91 100644 --- a/doc/pub/LogReg/html/._LogReg-bs006.html +++ b/doc/pub/LogReg/html/._LogReg-bs006.html @@ -49,7 +49,8 @@ Automatically generated HTML file from DocOnce source None, '___sec4'), ('Maximum likelihood', 2, None, '___sec5'), - ('Minimizing the cross entropy', 2, None, '___sec6')]} + ('Minimizing the cross entropy', 2, None, '___sec6'), + ('A _scikit-learn_ example', 2, None, '___sec7')]} end of tocinfo --> @@ -94,6 +95,7 @@ MathJax.Hub.Config({
  • The cross-entropy as a cost function for logistic regression
  • Maximum likelihood
  • Minimizing the cross entropy
  • +
  • A scikit-learn example
  • @@ -147,6 +149,7 @@ $$
  • 7
  • 8
  • 9
  • +
  • 10
  • »
  • diff --git a/doc/pub/LogReg/html/._LogReg-bs007.html b/doc/pub/LogReg/html/._LogReg-bs007.html index cd38b5b73..58dd903f9 100644 --- a/doc/pub/LogReg/html/._LogReg-bs007.html +++ b/doc/pub/LogReg/html/._LogReg-bs007.html @@ -49,7 +49,8 @@ Automatically generated HTML file from DocOnce source None, '___sec4'), ('Maximum likelihood', 2, None, '___sec5'), - ('Minimizing the cross entropy', 2, None, '___sec6')]} + ('Minimizing the cross entropy', 2, None, '___sec6'), + ('A _scikit-learn_ example', 2, None, '___sec7')]} end of tocinfo --> @@ -94,6 +95,7 @@ MathJax.Hub.Config({
  • The cross-entropy as a cost function for logistic regression
  • Maximum likelihood
  • Minimizing the cross entropy
  • +
  • A scikit-learn example
  • @@ -138,6 +140,7 @@ in practice we usually supplement the cross-entropy with additional regularizati
  • 7
  • 8
  • 9
  • +
  • 10
  • »
  • diff --git a/doc/pub/LogReg/html/._LogReg-bs008.html b/doc/pub/LogReg/html/._LogReg-bs008.html index 16143ecbd..28edf976e 100644 --- a/doc/pub/LogReg/html/._LogReg-bs008.html +++ b/doc/pub/LogReg/html/._LogReg-bs008.html @@ -49,7 +49,8 @@ Automatically generated HTML file from DocOnce source None, '___sec4'), ('Maximum likelihood', 2, None, '___sec5'), - ('Minimizing the cross entropy', 2, None, '___sec6')]} + ('Minimizing the cross entropy', 2, None, '___sec6'), + ('A _scikit-learn_ example', 2, None, '___sec7')]} end of tocinfo --> @@ -94,6 +95,7 @@ MathJax.Hub.Config({
  • The cross-entropy as a cost function for logistic regression
  • Maximum likelihood
  • Minimizing the cross entropy
  • +
  • A scikit-learn example
  • @@ -130,6 +132,7 @@ f(z)[1-f(z)] \). This equation defines a transcendental equation for be written in a closed form. Here we need gradient descent methods! +

    diff --git a/doc/pub/LogReg/html/._LogReg-bs009.html b/doc/pub/LogReg/html/._LogReg-bs009.html new file mode 100644 index 000000000..f81543409 --- /dev/null +++ b/doc/pub/LogReg/html/._LogReg-bs009.html @@ -0,0 +1,177 @@ + + + + + + + +Data Analysis and Machine Learning: Logistic Regression + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + +

     

     

     

    + + + + +

    A scikit-learn example

    + +

    + + +

    import numpy as np
    +import matplotlib.pyplot as plt
    +from sklearn import datasets
    +iris = datasets.load_iris()
    +list(iris.keys())
    +['data', 'target_names', 'feature_names', 'target', 'DESCR']
    +X = iris["data"][:, 3:] # petal width
    +y = (iris["target"] == 2).astype(np.int) # 1 if Iris-Virginica, else 0
    +
    +from sklearn.linear_model import LogisticRegression
    +log_reg = LogisticRegression()
    +log_reg.fit(X, y)
    +
    +X_new = np.linspace(0, 3, 1000).reshape(-1, 1)
    +y_proba = log_reg.predict_proba(X_new)
    +plt.plot(X_new, y_proba[:, 1], "g-", label="Iris-Virginica")
    +plt.plot(X_new, y_proba[:, 0], "b--", label="Not Iris-Virginica")
    +plt.show()
    +
    +

    + +

    + +

    + + +
    + + + + + + + +
    + +
    + + + + + + diff --git a/doc/pub/LogReg/html/LogReg-bs.html b/doc/pub/LogReg/html/LogReg-bs.html index bbb583e11..d4f17bb42 100644 --- a/doc/pub/LogReg/html/LogReg-bs.html +++ b/doc/pub/LogReg/html/LogReg-bs.html @@ -49,7 +49,8 @@ Automatically generated HTML file from DocOnce source None, '___sec4'), ('Maximum likelihood', 2, None, '___sec5'), - ('Minimizing the cross entropy', 2, None, '___sec6')]} + ('Minimizing the cross entropy', 2, None, '___sec6'), + ('A _scikit-learn_ example', 2, None, '___sec7')]} end of tocinfo --> @@ -94,6 +95,7 @@ MathJax.Hub.Config({
  • The cross-entropy as a cost function for logistic regression
  • Maximum likelihood
  • Minimizing the cross entropy
  • +
  • A scikit-learn example
  • @@ -128,7 +130,7 @@ MathJax.Hub.Config({
    [2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University

    -

    Sep 17, 2018

    +

    Sep 20, 2018


    @@ -143,6 +145,7 @@ MathJax.Hub.Config({

  • 7
  • 8
  • 9
  • +
  • 10
  • »
  • diff --git a/doc/pub/LogReg/html/LogReg-reveal.html b/doc/pub/LogReg/html/LogReg-reveal.html index d4f9473b3..852458fb9 100644 --- a/doc/pub/LogReg/html/LogReg-reveal.html +++ b/doc/pub/LogReg/html/LogReg-reveal.html @@ -148,7 +148,7 @@ MathJax.Hub.Config({
    [2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University

     
    -

    Sep 17, 2018

    +

    Sep 20, 2018


    @@ -356,6 +356,34 @@ Here we need gradient descent methods! +

    +

    A scikit-learn example

    + +

    + + +

    import numpy as np
    +import matplotlib.pyplot as plt
    +from sklearn import datasets
    +iris = datasets.load_iris()
    +list(iris.keys())
    +['data', 'target_names', 'feature_names', 'target', 'DESCR']
    +X = iris["data"][:, 3:] # petal width
    +y = (iris["target"] == 2).astype(np.int) # 1 if Iris-Virginica, else 0
    +
    +from sklearn.linear_model import LogisticRegression
    +log_reg = LogisticRegression()
    +log_reg.fit(X, y)
    +
    +X_new = np.linspace(0, 3, 1000).reshape(-1, 1)
    +y_proba = log_reg.predict_proba(X_new)
    +plt.plot(X_new, y_proba[:, 1], "g-", label="Iris-Virginica")
    +plt.plot(X_new, y_proba[:, 0], "b--", label="Not Iris-Virginica")
    +plt.show()
    +
    +
    + + diff --git a/doc/pub/LogReg/html/LogReg-solarized.html b/doc/pub/LogReg/html/LogReg-solarized.html index ff268fe82..e482c3596 100644 --- a/doc/pub/LogReg/html/LogReg-solarized.html +++ b/doc/pub/LogReg/html/LogReg-solarized.html @@ -43,7 +43,8 @@ div { text-align: justify; text-justify: inter-word; } None, '___sec4'), ('Maximum likelihood', 2, None, '___sec5'), - ('Minimizing the cross entropy', 2, None, '___sec6')]} + ('Minimizing the cross entropy', 2, None, '___sec6'), + ('A _scikit-learn_ example', 2, None, '___sec7')]} end of tocinfo --> @@ -85,7 +86,7 @@ MathJax.Hub.Config({
    [2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University

    -

    Sep 17, 2018

    +

    Sep 20, 2018


    @@ -266,6 +267,35 @@ f(z)[1-f(z)] \). This equation defines a transcendental equation for be written in a closed form. Here we need gradient descent methods! +

    +









    + +

    A scikit-learn example

    + +

    + + +

    import numpy as np
    +import matplotlib.pyplot as plt
    +from sklearn import datasets
    +iris = datasets.load_iris()
    +list(iris.keys())
    +['data', 'target_names', 'feature_names', 'target', 'DESCR']
    +X = iris["data"][:, 3:] # petal width
    +y = (iris["target"] == 2).astype(np.int) # 1 if Iris-Virginica, else 0
    +
    +from sklearn.linear_model import LogisticRegression
    +log_reg = LogisticRegression()
    +log_reg.fit(X, y)
    +
    +X_new = np.linspace(0, 3, 1000).reshape(-1, 1)
    +y_proba = log_reg.predict_proba(X_new)
    +plt.plot(X_new, y_proba[:, 1], "g-", label="Iris-Virginica")
    +plt.plot(X_new, y_proba[:, 0], "b--", label="Not Iris-Virginica")
    +plt.show()
    +
    +

    + diff --git a/doc/pub/LogReg/html/LogReg.html b/doc/pub/LogReg/html/LogReg.html index e63170fc4..889e00fb5 100644 --- a/doc/pub/LogReg/html/LogReg.html +++ b/doc/pub/LogReg/html/LogReg.html @@ -48,7 +48,8 @@ div { text-align: justify; text-justify: inter-word; } None, '___sec4'), ('Maximum likelihood', 2, None, '___sec5'), - ('Minimizing the cross entropy', 2, None, '___sec6')]} + ('Minimizing the cross entropy', 2, None, '___sec6'), + ('A _scikit-learn_ example', 2, None, '___sec7')]} end of tocinfo --> @@ -90,7 +91,7 @@ MathJax.Hub.Config({

    [2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University

    -

    Sep 17, 2018

    +

    Sep 20, 2018


    @@ -271,6 +272,35 @@ f(z)[1-f(z)] \). This equation defines a transcendental equation for be written in a closed form. Here we need gradient descent methods! +

    +









    + +

    A scikit-learn example

    + +

    + + +

    import numpy as np
    +import matplotlib.pyplot as plt
    +from sklearn import datasets
    +iris = datasets.load_iris()
    +list(iris.keys())
    +['data', 'target_names', 'feature_names', 'target', 'DESCR']
    +X = iris["data"][:, 3:] # petal width
    +y = (iris["target"] == 2).astype(np.int) # 1 if Iris-Virginica, else 0
    +
    +from sklearn.linear_model import LogisticRegression
    +log_reg = LogisticRegression()
    +log_reg.fit(X, y)
    +
    +X_new = np.linspace(0, 3, 1000).reshape(-1, 1)
    +y_proba = log_reg.predict_proba(X_new)
    +plt.plot(X_new, y_proba[:, 1], "g-", label="Iris-Virginica")
    +plt.plot(X_new, y_proba[:, 0], "b--", label="Not Iris-Virginica")
    +plt.show()
    +
    +

    + diff --git a/doc/pub/LogReg/ipynb/LogReg.ipynb b/doc/pub/LogReg/ipynb/LogReg.ipynb index 4c9b78863..90c236b5c 100644 --- a/doc/pub/LogReg/ipynb/LogReg.ipynb +++ b/doc/pub/LogReg/ipynb/LogReg.ipynb @@ -10,7 +10,7 @@ " \n", "**Morten Hjorth-Jensen**, Department of Physics, University of Oslo and Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University\n", "\n", - "Date: **Sep 17, 2018**\n", + "Date: **Sep 20, 2018**\n", "\n", "Copyright 1999-2018, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license\n", "\n", @@ -285,7 +285,40 @@ "f(z)[1-f(z)]$. This equation defines a transcendental equation for\n", "$\\mathbf{w}$, the solution of which, unlike linear regression, cannot\n", "be written in a closed form. \n", - "Here we need gradient descent methods!" + "Here we need gradient descent methods!\n", + "\n", + "\n", + "## A **scikit-learn** example" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "%matplotlib inline\n", + "\n", + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "from sklearn import datasets\n", + "iris = datasets.load_iris()\n", + "list(iris.keys())\n", + "['data', 'target_names', 'feature_names', 'target', 'DESCR']\n", + "X = iris[\"data\"][:, 3:] # petal width\n", + "y = (iris[\"target\"] == 2).astype(np.int) # 1 if Iris-Virginica, else 0\n", + "\n", + "from sklearn.linear_model import LogisticRegression\n", + "log_reg = LogisticRegression()\n", + "log_reg.fit(X, y)\n", + "\n", + "X_new = np.linspace(0, 3, 1000).reshape(-1, 1)\n", + "y_proba = log_reg.predict_proba(X_new)\n", + "plt.plot(X_new, y_proba[:, 1], \"g-\", label=\"Iris-Virginica\")\n", + "plt.plot(X_new, y_proba[:, 0], \"b--\", label=\"Not Iris-Virginica\")\n", + "plt.show()" ] } ], diff --git a/doc/pub/LogReg/ipynb/ipynb-LogReg-src.tar.gz b/doc/pub/LogReg/ipynb/ipynb-LogReg-src.tar.gz index 95a287a49..901d9ce8b 100644 Binary files a/doc/pub/LogReg/ipynb/ipynb-LogReg-src.tar.gz and b/doc/pub/LogReg/ipynb/ipynb-LogReg-src.tar.gz differ diff --git a/doc/pub/LogReg/pdf/LogReg-beamer-handouts2x3.pdf b/doc/pub/LogReg/pdf/LogReg-beamer-handouts2x3.pdf index 03f53c2e5..4e19fd9be 100644 Binary files a/doc/pub/LogReg/pdf/LogReg-beamer-handouts2x3.pdf and b/doc/pub/LogReg/pdf/LogReg-beamer-handouts2x3.pdf differ diff --git a/doc/pub/LogReg/pdf/LogReg-beamer.pdf b/doc/pub/LogReg/pdf/LogReg-beamer.pdf index 59633c0de..2bff2cb51 100644 Binary files a/doc/pub/LogReg/pdf/LogReg-beamer.pdf and b/doc/pub/LogReg/pdf/LogReg-beamer.pdf differ diff --git a/doc/pub/LogReg/pdf/LogReg-minted.pdf b/doc/pub/LogReg/pdf/LogReg-minted.pdf index 3e659592b..e321dd04d 100644 Binary files a/doc/pub/LogReg/pdf/LogReg-minted.pdf and b/doc/pub/LogReg/pdf/LogReg-minted.pdf differ diff --git a/doc/src/LogisticRegression/LogReg.do.txt b/doc/src/LogisticRegression/LogReg.do.txt index 3c60670e4..0f5ea1bec 100644 --- a/doc/src/LogisticRegression/LogReg.do.txt +++ b/doc/src/LogisticRegression/LogReg.do.txt @@ -151,3 +151,29 @@ f(z)[1-f(z)]$. This equation defines a transcendental equation for $\mathbf{w}$, the solution of which, unlike linear regression, cannot be written in a closed form. Here we need gradient descent methods! + + +!split +===== A _scikit-learn_ example ===== + +!bc pycod +import numpy as np +import matplotlib.pyplot as plt +from sklearn import datasets +iris = datasets.load_iris() +list(iris.keys()) +['data', 'target_names', 'feature_names', 'target', 'DESCR'] +X = iris["data"][:, 3:] # petal width +y = (iris["target"] == 2).astype(np.int) # 1 if Iris-Virginica, else 0 + +from sklearn.linear_model import LogisticRegression +log_reg = LogisticRegression() +log_reg.fit(X, y) + +X_new = np.linspace(0, 3, 1000).reshape(-1, 1) +y_proba = log_reg.predict_proba(X_new) +plt.plot(X_new, y_proba[:, 1], "g-", label="Iris-Virginica") +plt.plot(X_new, y_proba[:, 0], "b--", label="Not Iris-Virginica") +plt.show() + +!ec