Refactor code in numerical methods notebooks

- Updated import order in Point_Fixe.ipynb for consistency.
- Changed lambda functions to regular function definitions for clarity in Point_Fixe.ipynb.
- Added numpy import in TP1_EDO_EulerExp.ipynb, TP2_Lokta_Volterra.ipynb, and TP3_Convergence.ipynb for better readability.
- Modified for loops in TP1_EDO_EulerExp.ipynb and TP2_Lokta_Volterra.ipynb to include strict=False for compatibility with future Python versions.
This commit is contained in:
2025-09-01 16:14:53 +02:00
parent dfee405ea0
commit 8cf328e18a
31 changed files with 177 additions and 156 deletions

View File

@@ -124,7 +124,9 @@
{
"cell_type": "markdown",
"metadata": {},
"source": "## 1. K-NN classification for `Iris` <a class=\"anchor\" id=\"chapter1\"></a>"
"source": [
"## 1. K-NN classification for `Iris` <a class=\"anchor\" id=\"chapter1\"></a>"
]
},
{
"attachments": {
@@ -331,7 +333,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-07T16:32:18.698079Z",
@@ -355,8 +357,9 @@
}
],
"source": [
"# np.argsort\n",
"from collections import Counter\n",
"\n",
"# np.argsort\n",
"distance_ex = np.array([4, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 0.5, 0.2])\n",
"print(\n",
" \"The indices where the 4 smallest digits are located are \\n\",\n",
@@ -367,9 +370,6 @@
"print(\"\\n\")\n",
"\n",
"# counter.most_common()\n",
"\n",
"from collections import Counter\n",
"\n",
"print(\n",
" \"In 'aabbbbccccccc', the frequencies of the letters are : \\n\",\n",
" Counter(\"aabbbbccccccc\").most_common(),\n",
@@ -1274,9 +1274,10 @@
},
"outputs": [],
"source": [
"from itertools import product\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"from itertools import product\n",
"from sklearn.neighbors import KNeighborsClassifier"
]
},
@@ -1411,7 +1412,7 @@
"f, axarr = plt.subplots(2, 3, sharex=\"col\", sharey=\"row\", figsize=(15, 12))\n",
"\n",
"for idx, clf, tt in zip(\n",
" product([0, 1, 2], [0, 1, 2]), KNNs, [f\"KNN (k={k})\" for k in nb_neighbors]\n",
" product([0, 1, 2], [0, 1, 2]), KNNs, [f\"KNN (k={k})\" for k in nb_neighbors], strict=False\n",
"):\n",
" Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])\n",
" Z = Z.reshape(xx.shape)\n",