Refactor code formatting and improve readability in Jupyter notebooks for TP_4 and TP_5

- Adjusted indentation and line breaks for better clarity in function definitions and import statements.
- Standardized string quotes for consistency across the codebase.
- Enhanced readability of DataFrame creation and manipulation by breaking long lines into multiple lines.
- Cleaned up print statements and comments for improved understanding.
- Ensured consistent use of whitespace around operators and after commas.
This commit is contained in:
2025-11-25 10:46:16 +01:00
parent 751412c1cd
commit e57995ba85
17 changed files with 11975 additions and 11713 deletions

View File

@@ -159,11 +159,15 @@
"\n",
" for n in range(N - 1):\n",
" p1 = f(vt[n], yn[:, n])\n",
"\n",
" def F1(p2):\n",
" return f(vt[n] + h / 3, yn[:, n] + h / 6 * (p1 + p2)) - p2\n",
"\n",
" p2 = newton(F1, yn[:, n], fprime=None, tol=tol, maxiter=itmax)\n",
"\n",
" def F2(yn1):\n",
" return yn[:, n] + h / 4 * (3 * p2 + f(vt[n + 1], yn1)) - yn1\n",
"\n",
" yn[:, n + 1] = newton(F2, yn[:, n], fprime=None, tol=tol, maxiter=itmax)\n",
" return yn"
]

View File

@@ -66,6 +66,8 @@
"\n",
"def f(x):\n",
" return np.tanh(x)\n",
"\n",
"\n",
"aL, aR = -20, 3\n",
"print(dichotomy(f, aL, aR))"
]
@@ -135,9 +137,15 @@
"\n",
"def f(x):\n",
" return np.log(np.exp(x) + np.exp(-x))\n",
"\n",
"\n",
"x0 = 1.8\n",
"\n",
"\n",
"def df(x):\n",
" return (np.exp(x) - np.exp(-x)) / (np.exp(x) + np.exp(-x))\n",
"\n",
"\n",
"print(Newton(f, df, x0))"
]
},
@@ -188,6 +196,8 @@
"\n",
"def f(x):\n",
" return np.log(np.exp(x) + np.exp(-x))\n",
"\n",
"\n",
"xx = [(1, 1.9), (1, 2.3), (1, 2.4)]\n",
"\n",
"for x0, x1 in xx:\n",
@@ -265,8 +275,12 @@
"\n",
"def f(x):\n",
" return np.log(np.exp(x) + np.exp(-x))\n",
"\n",
"\n",
"def df(x):\n",
" return (np.exp(x) - np.exp(-x)) / (np.exp(x) + np.exp(-x))\n",
"\n",
"\n",
"print(DichotomyNewton(f, df, -20, 3))"
]
},

View File

@@ -1412,7 +1412,10 @@
"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], strict=False\n",
" product([0, 1, 2], [0, 1, 2]),\n",
" KNNs,\n",
" [f\"KNN (k={k})\" for k in nb_neighbors],\n",
" strict=False,\n",
"):\n",
" Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])\n",
" Z = Z.reshape(xx.shape)\n",

View File

@@ -2545,7 +2545,9 @@
"\n",
"MSEs = []\n",
"for name, estimator in zip(\n",
" [\"LassoCV\", \"LassoBIC\", \"RidgeCV\", \"OLS\"], [lassoCV, lassoBIC, ridgeCV, linReg], strict=False\n",
" [\"LassoCV\", \"LassoBIC\", \"RidgeCV\", \"OLS\"],\n",
" [lassoCV, lassoBIC, ridgeCV, linReg],\n",
" strict=False,\n",
"):\n",
" y_pred = estimator.predict(Xtest)\n",
" MSE = mean_squared_error(Ytest, y_pred)\n",