Skip to content
This repository was archived by the owner on Mar 21, 2023. It is now read-only.

Update apis #13

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ target/
# IPython
.ipynb_checkpoints
notebooks/.ipynb_checkpoints

/.idea
# Emacs
*~
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,20 @@ Once this is installed, the following command will install all required packages
Original install (2015)
$ conda install numpy scipy matplotlib scikit-learn ipython-notebook seaborn

Or for current versions of Anaconda (Mar 2018)
For older version Anaconda (Mar 2018)

$ conda create -n skl_tut python=3.4.5 ipywidgets=5.2.2 numpy scipy matplotlib scikit-learn ipython-notebook seaborn pillow
```

$ activate skl_tut
**For current (2023) version of the project:**
```
$ conda create -n skl_tut python=3.10.8 --file requirements.txt
```

```
$ activate skl_tut
```
```
$ jupyter notebook --notebook-dir='<tutorial folder>'
```

Expand Down
28 changes: 22 additions & 6 deletions notebooks/01-Preliminaries.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"IPython: 8.10.0\n",
"numpy: 1.23.5\n",
"scipy: 1.10.0\n",
"matplotlib: 3.6.2\n",
"scikit-learn: 1.2.1\n",
"seaborn: 0.12.2\n"
]
}
],
"source": [
"from __future__ import print_function\n",
"\n",
Expand All @@ -134,7 +147,10 @@
"print('matplotlib:', matplotlib.__version__)\n",
"\n",
"import sklearn\n",
"print('scikit-learn:', sklearn.__version__)"
"print('scikit-learn:', sklearn.__version__)\n",
"\n",
"import seaborn\n",
"print('seaborn:', seaborn.__version__)"
]
},
{
Expand All @@ -156,7 +172,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -170,9 +186,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.0"
"version": "3.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}
12 changes: 5 additions & 7 deletions notebooks/02.1-Machine-Learning-Intro.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,8 @@
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"import matplotlib.pyplot as plt\n",
"\n",
"plt.style.use('seaborn')"
"plt.style.use(\"seaborn-v0_8-darkgrid\")"
]
},
{
Expand Down Expand Up @@ -194,7 +192,7 @@
"metadata": {},
"outputs": [],
"source": [
"from IPython.core.display import Image, display\n",
"from IPython.display import Image, display\n",
"display(Image(filename='images/iris_setosa.jpg'))\n",
"print(\"Iris Setosa\\n\")\n",
"\n",
Expand Down Expand Up @@ -422,7 +420,7 @@
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -436,9 +434,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.0"
"version": "3.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}
31 changes: 19 additions & 12 deletions notebooks/02.2-Basic-Principles.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"plt.style.use('seaborn')"
"plt.style.use(\"seaborn-v0_8-darkgrid\")"
]
},
{
Expand All @@ -51,7 +50,8 @@
"metadata": {},
"outputs": [],
"source": [
"from sklearn.linear_model import LinearRegression"
"from sklearn.linear_model import LinearRegression\n",
"from sklearn.preprocessing import normalize"
]
},
{
Expand All @@ -67,8 +67,7 @@
"metadata": {},
"outputs": [],
"source": [
"model = LinearRegression(normalize=True)\n",
"print(model.normalize)"
"model = LinearRegression() # normalize=True is no longer an argument, not using it does not seem to affect the result here"
]
},
{
Expand Down Expand Up @@ -471,7 +470,7 @@
"outputs": [],
"source": [
"from sklearn.cluster import KMeans\n",
"k_means = KMeans(n_clusters=3, random_state=0) # Fixing the RNG in kmeans\n",
"k_means = KMeans(n_clusters=3, random_state=0, n_init='auto') # Fixing the RNG in kmeans\n",
"k_means.fit(X)\n",
"y_pred = k_means.predict(X)\n",
"\n",
Expand Down Expand Up @@ -740,7 +739,7 @@
"metadata": {},
"outputs": [],
"source": [
"iso = Isomap(n_components=2)\n",
"iso = Isomap(n_components=2, n_neighbors=7)\n",
"data_projected = iso.fit_transform(digits.data)"
]
},
Expand Down Expand Up @@ -807,8 +806,16 @@
"outputs": [],
"source": [
"from sklearn.linear_model import LogisticRegression\n",
"clf = LogisticRegression(penalty='l2')\n",
"clf.fit(Xtrain, ytrain)\n",
"from sklearn import preprocessing\n",
"\n",
"scaler = preprocessing.StandardScaler().fit(Xtrain) # Scale data to avoid 'ConvergenceWarning: lbfgs failed to converge (status=1)'\n",
"X_scaled = scaler.transform(Xtrain)\n",
"\n",
"scaler_test = preprocessing.StandardScaler().fit(Xtest)\n",
"Xtest = scaler.transform(Xtest)\n",
"\n",
"clf = LogisticRegression(penalty='l2', max_iter=150) # Increase max_iter from 100 to 150 to avoid 'ConvergenceWarning: lbfgs failed to converge (status=1)'\n",
"clf.fit(X_scaled, ytrain)\n",
"ypred = clf.predict(Xtest)"
]
},
Expand Down Expand Up @@ -897,7 +904,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -911,9 +918,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.0"
"version": "3.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}
15 changes: 7 additions & 8 deletions notebooks/03.1-Classification-SVMs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from scipy import stats\n",
"\n",
"plt.style.use('seaborn')"
"plt.style.use(\"seaborn-v0_8-darkgrid\")"
]
},
{
Expand All @@ -58,7 +57,7 @@
"metadata": {},
"outputs": [],
"source": [
"from sklearn.datasets.samples_generator import make_blobs\n",
"from sklearn.datasets import make_blobs\n",
"X, y = make_blobs(n_samples=50, centers=2,\n",
" random_state=0, cluster_std=0.60)\n",
"plt.scatter(X[:, 0], X[:, 1], c=y, s=50, cmap='spring');"
Expand Down Expand Up @@ -240,7 +239,7 @@
" plt.scatter(clf.support_vectors_[:, 0], clf.support_vectors_[:, 1],\n",
" s=200, facecolors='none')\n",
" \n",
"interact(plot_svm, N=[10, 200], kernel='linear');"
"interact(plot_svm, N=(10, 200), kernel='linear');"
]
},
{
Expand All @@ -266,7 +265,7 @@
"metadata": {},
"outputs": [],
"source": [
"from sklearn.datasets.samples_generator import make_circles\n",
"from sklearn.datasets import make_circles\n",
"X, y = make_circles(100, factor=.1, noise=.1)\n",
"\n",
"clf = SVC(kernel='linear').fit(X, y)\n",
Expand Down Expand Up @@ -355,7 +354,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -369,9 +368,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.0"
"version": "3.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}
9 changes: 4 additions & 5 deletions notebooks/03.2-Regression-Forests.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from scipy import stats\n",
"\n",
"plt.style.use('seaborn')"
"plt.style.use(\"seaborn-v0_8-darkgrid\")"
]
},
{
Expand Down Expand Up @@ -410,7 +409,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -424,9 +423,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.0"
"version": "3.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}
11 changes: 5 additions & 6 deletions notebooks/04.1-Dimensionality-PCA.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@
"source": [
"from __future__ import print_function, division\n",
"\n",
"%matplotlib inline\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from scipy import stats\n",
"\n",
"plt.style.use('seaborn')"
"plt.style.use(\"seaborn-v0_8-darkgrid\")"
]
},
{
Expand Down Expand Up @@ -355,7 +354,7 @@
" size=18)\n",
" plt.clim(0, 16)\n",
" \n",
"interact(plot_digits, n_components=[1, 64], nside=[1, 8]);"
"interact(plot_digits, n_components=(1, 64), nside=[1, 8]);"
]
},
{
Expand Down Expand Up @@ -388,7 +387,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -402,9 +401,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.0"
"version": "3.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}
Loading