update notebooks to use scikit-learn 0.19.1 and Python 3.6

pull/14/merge
Kevin Markham 2018-06-29 12:11:35 -04:00
parent 1a20cab8fe
commit 283ef07cc5
9 changed files with 1485 additions and 971 deletions

View File

@ -4,8 +4,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# What is machine learning, and how does it work?\n",
"*From the video series: [Introduction to machine learning with scikit-learn](https://github.com/justmarkham/scikit-learn-videos)*"
"# What is machine learning, and how does it work? ([video #1](https://www.youtube.com/watch?v=elojMnjn4kk&list=PL5-da3qGB5ICeMbQuqbbCOQWcS6OYBr5A&index=1))\n",
"\n",
"Created by [Data School](http://www.dataschool.io/). Watch all 9 videos on [YouTube](https://www.youtube.com/playlist?list=PL5-da3qGB5ICeMbQuqbbCOQWcS6OYBr5A). Download the notebooks from [GitHub](https://github.com/justmarkham/scikit-learn-videos)."
]
},
{
@ -143,9 +144,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"data": {
@ -238,23 +237,23 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"display_name": "Python 3",
"language": "python",
"name": "python2"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11"
"pygments_lexer": "ipython3",
"version": "3.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}

View File

@ -4,8 +4,11 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Setting up Python for machine learning: scikit-learn and IPython Notebook\n",
"*From the video series: [Introduction to machine learning with scikit-learn](https://github.com/justmarkham/scikit-learn-videos)*"
"# Setting up Python for machine learning: scikit-learn and Jupyter Notebook ([video #2](https://www.youtube.com/watch?v=IsXXlYVBt1M&list=PL5-da3qGB5ICeMbQuqbbCOQWcS6OYBr5A&index=2))\n",
"\n",
"Created by [Data School](http://www.dataschool.io/). Watch all 9 videos on [YouTube](https://www.youtube.com/playlist?list=PL5-da3qGB5ICeMbQuqbbCOQWcS6OYBr5A). Download the notebooks from [GitHub](https://github.com/justmarkham/scikit-learn-videos).\n",
"\n",
"**Note:** Since the video recording, the official name of the \"IPython Notebook\" was changed to \"Jupyter Notebook\". However, the functionality is the same."
]
},
{
@ -16,7 +19,7 @@
"\n",
"- What are the benefits and drawbacks of scikit-learn?\n",
"- How do I install scikit-learn?\n",
"- How do I use the IPython Notebook?\n",
"- How do I use the Jupyter Notebook?\n",
"- What are some good resources for learning Python?"
]
},
@ -68,10 +71,10 @@
"\n",
"**Option 1:** [Install scikit-learn library](http://scikit-learn.org/stable/install.html) and dependencies (NumPy and SciPy)\n",
"\n",
"**Option 2:** [Install Anaconda distribution](https://www.continuum.io/downloads) of Python, which includes:\n",
"**Option 2:** [Install Anaconda distribution](https://www.anaconda.com/download/) of Python, which includes:\n",
"\n",
"- Hundreds of useful packages (including scikit-learn)\n",
"- IPython and IPython Notebook\n",
"- IPython and Jupyter Notebook\n",
"- conda package manager\n",
"- Spyder IDE"
]
@ -80,14 +83,14 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"![IPython header](images/02_ipython_header.png)"
"![Jupyter logo](images/02_jupyter_logo.svg)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Using the IPython Notebook\n",
"## Using the Jupyter Notebook\n",
"\n",
"### Components:\n",
"\n",
@ -96,12 +99,12 @@
"\n",
"### Installation:\n",
"\n",
"- **Option 1:** Install [IPython](http://ipython.org/install.html) and the [notebook](https://jupyter.readthedocs.io/en/latest/install.html)\n",
"- **Option 1:** [Install the Jupyter notebook](https://jupyter.readthedocs.io/en/latest/install.html) (includes IPython)\n",
"- **Option 2:** Included with the Anaconda distribution\n",
"\n",
"### Launching the Notebook:\n",
"\n",
"- Type **ipython notebook** at the command line to open the dashboard\n",
"- Type **jupyter notebook** at the command line to open the dashboard\n",
"- Don't close the command line window while the Notebook is running\n",
"\n",
"### Keyboard shortcuts:\n",
@ -119,11 +122,11 @@
"- **Ctrl+Enter** to run a cell\n",
"- Switch to Command mode using **Esc**\n",
"\n",
"### IPython and Markdown resources:\n",
"### IPython, Jupyter, and Markdown resources:\n",
"\n",
"- [nbviewer](http://nbviewer.jupyter.org/): view notebooks online as static documents\n",
"- [IPython documentation](http://ipython.readthedocs.io/en/stable/): focuses on the interpreter\n",
"- [IPython Notebook tutorials](http://jupyter.readthedocs.io/en/latest/content-quickstart.html): in-depth introduction\n",
"- [IPython documentation](http://ipython.readthedocs.io/en/stable/)\n",
"- [Jupyter Notebook quickstart](http://jupyter.readthedocs.io/en/latest/content-quickstart.html)\n",
"- [GitHub's Mastering Markdown](https://guides.github.com/features/mastering-markdown/): short guide with lots of examples"
]
},
@ -133,10 +136,10 @@
"source": [
"## Resources for learning Python\n",
"\n",
"- [Codecademy's Python course](https://www.codecademy.com/learn/python): browser-based, tons of exercises\n",
"- [Codecademy's Python course](https://www.codecademy.com/learn/learn-python): browser-based, tons of exercises\n",
"- [DataQuest](https://www.dataquest.io/): browser-based, teaches Python in the context of data science\n",
"- [Google's Python class](https://developers.google.com/edu/python/): slightly more advanced, includes videos and downloadable exercises (with solutions)\n",
"- [Python for Informatics](http://www.pythonlearn.com/): beginner-oriented book, includes slides and videos"
"- [Python for Everybody](https://www.py4e.com/): beginner-oriented book, includes slides and videos"
]
},
{
@ -153,9 +156,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"data": {
@ -248,23 +249,23 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"display_name": "Python 3",
"language": "python",
"name": "python2"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11"
"pygments_lexer": "ipython3",
"version": "3.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}

View File

@ -4,8 +4,11 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Getting started in scikit-learn with the famous iris dataset\n",
"*From the video series: [Introduction to machine learning with scikit-learn](https://github.com/justmarkham/scikit-learn-videos)*"
"# Getting started in scikit-learn with the famous iris dataset ([video #3](https://www.youtube.com/watch?v=hd1W4CyPX58&list=PL5-da3qGB5ICeMbQuqbbCOQWcS6OYBr5A&index=3))\n",
"\n",
"Created by [Data School](http://www.dataschool.io/). Watch all 9 videos on [YouTube](https://www.youtube.com/playlist?list=PL5-da3qGB5ICeMbQuqbbCOQWcS6OYBr5A). Download the notebooks from [GitHub](https://github.com/justmarkham/scikit-learn-videos).\n",
"\n",
"**Note:** This notebook uses Python 3.6 and scikit-learn 0.19.1. The original notebook (shown in the video) used Python 2.7 and scikit-learn 0.16, and can be downloaded from the [archive branch](https://github.com/justmarkham/scikit-learn-videos/tree/archive)."
]
},
{
@ -45,9 +48,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"data": {
@ -63,7 +64,7 @@
" "
],
"text/plain": [
"<IPython.lib.display.IFrame at 0x3ce33c8>"
"<IPython.lib.display.IFrame at 0x10caa2470>"
]
},
"execution_count": 2,
@ -97,9 +98,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"# import load_iris function from datasets module\n",
@ -109,14 +108,12 @@
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"sklearn.datasets.base.Bunch"
"sklearn.utils.Bunch"
]
},
"execution_count": 4,
@ -133,164 +130,162 @@
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[ 5.1 3.5 1.4 0.2]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2.8 4.9 2. ]\n",
" [7.7 2.8 6.7 2. ]\n",
" [6.3 2.7 4.9 1.8]\n",
" [6.7 3.3 5.7 2.1]\n",
" [7.2 3.2 6. 1.8]\n",
" [6.2 2.8 4.8 1.8]\n",
" [6.1 3. 4.9 1.8]\n",
" [6.4 2.8 5.6 2.1]\n",
" [7.2 3. 5.8 1.6]\n",
" [7.4 2.8 6.1 1.9]\n",
" [7.9 3.8 6.4 2. ]\n",
" [6.4 2.8 5.6 2.2]\n",
" [6.3 2.8 5.1 1.5]\n",
" [6.1 2.6 5.6 1.4]\n",
" [7.7 3. 6.1 2.3]\n",
" [6.3 3.4 5.6 2.4]\n",
" [6.4 3.1 5.5 1.8]\n",
" [6. 3. 4.8 1.8]\n",
" [6.9 3.1 5.4 2.1]\n",
" [6.7 3.1 5.6 2.4]\n",
" [6.9 3.1 5.1 2.3]\n",
" [5.8 2.7 5.1 1.9]\n",
" [6.8 3.2 5.9 2.3]\n",
" [6.7 3.3 5.7 2.5]\n",
" [6.7 3. 5.2 2.3]\n",
" [6.3 2.5 5. 1.9]\n",
" [6.5 3. 5.2 2. ]\n",
" [6.2 3.4 5.4 2.3]\n",
" [5.9 3. 5.1 1.8]]\n"
]
}
],
@ -312,9 +307,7 @@
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -332,9 +325,7 @@
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -356,9 +347,7 @@
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -397,16 +386,14 @@
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<type 'numpy.ndarray'>\n",
"<type 'numpy.ndarray'>\n"
"<class 'numpy.ndarray'>\n",
"<class 'numpy.ndarray'>\n"
]
}
],
@ -419,15 +406,13 @@
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(150L, 4L)\n"
"(150, 4)\n"
]
}
],
@ -439,15 +424,13 @@
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(150L,)\n"
"(150,)\n"
]
}
],
@ -459,9 +442,7 @@
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"# store feature matrix in \"X\"\n",
@ -496,9 +477,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"data": {
@ -591,23 +570,23 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"display_name": "Python 3",
"language": "python",
"name": "python2"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11"
"pygments_lexer": "ipython3",
"version": "3.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}

View File

@ -4,8 +4,11 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Training a machine learning model with scikit-learn\n",
"*From the video series: [Introduction to machine learning with scikit-learn](https://github.com/justmarkham/scikit-learn-videos)*"
"# Training a machine learning model with scikit-learn ([video #4](https://www.youtube.com/watch?v=RlQuVL6-qe8&list=PL5-da3qGB5ICeMbQuqbbCOQWcS6OYBr5A&index=4))\n",
"\n",
"Created by [Data School](http://www.dataschool.io/). Watch all 9 videos on [YouTube](https://www.youtube.com/playlist?list=PL5-da3qGB5ICeMbQuqbbCOQWcS6OYBr5A). Download the notebooks from [GitHub](https://github.com/justmarkham/scikit-learn-videos).\n",
"\n",
"**Note:** This notebook uses Python 3.6 and scikit-learn 0.19.1. The original notebook (shown in the video) used Python 2.7 and scikit-learn 0.16, and can be downloaded from the [archive branch](https://github.com/justmarkham/scikit-learn-videos/tree/archive)."
]
},
{
@ -29,9 +32,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"data": {
@ -47,7 +48,7 @@
" "
],
"text/plain": [
"<IPython.lib.display.IFrame at 0x3d50e80>"
"<IPython.lib.display.IFrame at 0x10fb4e4a8>"
]
},
"execution_count": 2,
@ -131,9 +132,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"# import load_iris function from datasets module\n",
@ -152,16 +151,14 @@
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(150L, 4L)\n",
"(150L,)\n"
"(150, 4)\n",
"(150,)\n"
]
}
],
@ -188,9 +185,7 @@
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"from sklearn.neighbors import KNeighborsClassifier"
@ -209,9 +204,7 @@
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"knn = KNeighborsClassifier(n_neighbors=1)"
@ -229,9 +222,7 @@
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -260,9 +251,7 @@
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"data": {
@ -294,9 +283,7 @@
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"data": {
@ -324,9 +311,7 @@
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"data": {
@ -354,9 +339,7 @@
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"data": {
@ -390,9 +373,7 @@
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"data": {
@ -447,9 +428,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"data": {
@ -542,23 +521,23 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"display_name": "Python 3",
"language": "python",
"name": "python2"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11"
"pygments_lexer": "ipython3",
"version": "3.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long