Refactor code for improved readability and consistency across multiple Jupyter notebooks

- Added missing commas in various print statements and function calls for better syntax.
- Reformatted code to enhance clarity, including breaking long lines and aligning parameters.
- Updated function signatures to use float type for sigma parameters instead of int for better precision.
- Cleaned up comments and documentation strings for clarity and consistency.
- Ensured consistent formatting in plotting functions and data handling.
This commit is contained in:
2025-12-13 23:38:17 +01:00
parent f89ff4a016
commit d5a6bfd339
50 changed files with 779 additions and 449 deletions

View File

@@ -1246,14 +1246,15 @@
"# 2. Displaying the vectors :\n",
"\n",
"print(\n",
" \"2. The vectors corresponding to the sms are : \\n\", X.toarray()\n",
" \"2. The vectors corresponding to the sms are : \\n\",\n",
" X.toarray(),\n",
") # X.toarray because\n",
"# X is a \"sparse\" matrix.\n",
"\n",
"# 3. For a new data x_0=\"iphone gratuit\",\n",
"# you must also transform x_0 into a numerical vector before predicting.\n",
"\n",
"vec_x_0 = vec.transform([\"iphone gratuit\"]).toarray() #\n",
"vec_x_0 = vec.transform([\"iphone gratuit\"]).toarray()\n",
"print(\"3. The numerical vector corresponding to (x_0=iphone gratuit) is \\n\", vec_x_0)"
]
},
@@ -1410,7 +1411,10 @@
"from sklearn.model_selection import train_test_split\n",
"\n",
"X_train, X_test, y_train, y_test = train_test_split(\n",
" X, y, test_size=0.30, random_state=50\n",
" X,\n",
" y,\n",
" test_size=0.30,\n",
" random_state=50,\n",
")\n",
"\n",
"print(\"size of the training set: \", X_train.shape[0])\n",
@@ -1986,7 +1990,7 @@
" \"Iphone 15 is now free\",\n",
" \"I want coffee\",\n",
" \"I want to buy a new iphone\",\n",
" ]\n",
" ],\n",
")\n",
"\n",
"pred_my_sms = sms_bayes.predict(my_sms)\n",
@@ -2055,7 +2059,10 @@
"X_copy = (X.copy() >= 127).astype(int)\n",
"\n",
"X_train, X_test, y_train, y_test = train_test_split(\n",
" X_copy, y, test_size=0.25, random_state=42\n",
" X_copy,\n",
" y,\n",
" test_size=0.25,\n",
" random_state=42,\n",
")\n",
"\n",
"ber_bayes = BernoulliNB()\n",