You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Chapter6/logging_debugging.ipynb
+29-4Lines changed: 29 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -357,14 +357,22 @@
357
357
"### Simplify Python Logging with Loguru"
358
358
]
359
359
},
360
+
{
361
+
"cell_type": "markdown",
362
+
"id": "0a74f279-828b-4d57-90ae-e78a8e4a2340",
363
+
"metadata": {},
364
+
"source": [
365
+
"Have you ever found yourself using print() instead of a proper logger due to the hassle of setup?\n",
366
+
"\n",
367
+
"With Loguru, you can get started with logging right away. A single import is all you need to begin logging with pre-configured color and format settings.\n"
368
+
]
369
+
},
360
370
{
361
371
"attachments": {},
362
372
"cell_type": "markdown",
363
373
"id": "6f30417a",
364
374
"metadata": {},
365
375
"source": [
366
-
"Are you struggling with the complexity of configuring a logger object before logging in Python? With Loguru, you can skip this step and use the logger object directly with pre-built color and format settings.\n",
367
-
"\n",
368
376
"Here is the comparison between the standard Python logging library and Loguru:"
369
377
]
370
378
},
@@ -1452,7 +1460,24 @@
1452
1460
},
1453
1461
{
1454
1462
"data": {
1455
-
"application/javascript": "\n setTimeout(function() {\n var nbb_cell_id = 17;\n var nbb_unformatted_code = \"from tqdm.notebook import tqdm\\nfrom time import sleep\\n\\n\\ndef lower(word):\\n sleep(1)\\n print(f\\\"Processing {word}\\\")\\n return word.lower()\\n\\n\\nwords = tqdm([\\\"Duck\\\", \\\"dog\\\", \\\"Flower\\\", \\\"fan\\\"])\\n\\n[lower(word) for word in words]\";\n var nbb_formatted_code = \"from tqdm.notebook import tqdm\\nfrom time import sleep\\n\\n\\ndef lower(word):\\n sleep(1)\\n print(f\\\"Processing {word}\\\")\\n return word.lower()\\n\\n\\nwords = tqdm([\\\"Duck\\\", \\\"dog\\\", \\\"Flower\\\", \\\"fan\\\"])\\n\\n[lower(word) for word in words]\";\n var nbb_cells = Jupyter.notebook.get_cells();\n for (var i = 0; i < nbb_cells.length; ++i) {\n if (nbb_cells[i].input_prompt_number == nbb_cell_id) {\n if (nbb_cells[i].get_text() == nbb_unformatted_code) {\n nbb_cells[i].set_text(nbb_formatted_code);\n }\n break;\n }\n }\n }, 500);\n ",
1463
+
"application/javascript": [
1464
+
"\n",
1465
+
" setTimeout(function() {\n",
1466
+
" var nbb_cell_id = 17;\n",
1467
+
" var nbb_unformatted_code = \"from tqdm.notebook import tqdm\\nfrom time import sleep\\n\\n\\ndef lower(word):\\n sleep(1)\\n print(f\\\"Processing {word}\\\")\\n return word.lower()\\n\\n\\nwords = tqdm([\\\"Duck\\\", \\\"dog\\\", \\\"Flower\\\", \\\"fan\\\"])\\n\\n[lower(word) for word in words]\";\n",
1468
+
" var nbb_formatted_code = \"from tqdm.notebook import tqdm\\nfrom time import sleep\\n\\n\\ndef lower(word):\\n sleep(1)\\n print(f\\\"Processing {word}\\\")\\n return word.lower()\\n\\n\\nwords = tqdm([\\\"Duck\\\", \\\"dog\\\", \\\"Flower\\\", \\\"fan\\\"])\\n\\n[lower(word) for word in words]\";\n",
1469
+
" var nbb_cells = Jupyter.notebook.get_cells();\n",
1470
+
" for (var i = 0; i < nbb_cells.length; ++i) {\n",
1471
+
" if (nbb_cells[i].input_prompt_number == nbb_cell_id) {\n",
1472
+
" if (nbb_cells[i].get_text() == nbb_unformatted_code) {\n",
<p>To address issues with imbalanced datasets, where one class significantly outweighs others, you can use the <codeclass="docutils literal notranslate"><spanclass="pre">imbalanced-learn</span></code> library to generate additional samples for under-represented classes.</p>
1237
-
<p>Here’s how you can use the <codeclass="docutils literal notranslate"><spanclass="pre">RandomOverSampler</span></code> from <codeclass="docutils literal notranslate"><spanclass="pre">imbalanced-learn</span></code> to create a balanced dataset by oversampling the minority class:</p>
1236
+
<p>In machine learning, imbalanced datasets can lead to biased models that perform poorly on minority classes. This is particularly problematic in critical applications like fraud detection or disease diagnosis.</p>
1237
+
<p>With imbalanced-learn, you can rebalance your dataset using various sampling techniques that work seamlessly with scikit-learn.</p>
1238
+
<p>To demonstrate this, let’s generate a sample dataset with 5000 samples, 2 features, and 4 classes:</p>
1238
1239
<divclass="cell docutils container">
1239
1240
<divclass="cell_input docutils container">
1240
1241
<divclass="highlight-ipython3 notranslate"><divclass="highlight"><pre><span></span><spanclass="c1"># Libraries for plotting</span>
@@ -1271,17 +1268,16 @@ <h2><span class="section-number">6.5.10. </span>imbalanced-learn: Deal with an I
1271
1268
</div>
1272
1269
</div>
1273
1270
</div>
1271
+
<p>Resample the dataset using the <codeclass="docutils literal notranslate"><spanclass="pre">RandomOverSampler</span></code> class from imbalanced-learn to balance the class distribution. This technique works by duplicating minority samples until they match the majority class.</p>
<divclass="output stderr highlight-myst-ansi notranslate"><divclass="highlight"><pre><span></span>/Users/khuyentran/book/venv/lib/python3.11/site-packages/mlxtend/plotting/decision_regions.py:300: UserWarning: You passed a edgecolor/edgecolors ('black') for an unfilled marker ('x'). Matplotlib is ignoring the edgecolor in favor of the facecolor. This behavior may change in the future.
1302
+
ax.scatter(
1303
+
/Users/khuyentran/book/venv/lib/python3.11/site-packages/mlxtend/plotting/decision_regions.py:300: UserWarning: You passed a edgecolor/edgecolors ('black') for an unfilled marker ('x'). Matplotlib is ignoring the edgecolor in favor of the facecolor. This behavior may change in the future.
<p>The plot reveals that the resampling process has added more data points to the minority class (green), effectively balancing the class distribution.</p>
1307
1311
<p><aclass="reference external" href="https://github.com/scikit-learn-contrib/imbalanced-learn">Link to imbalanced-learn</a>.</p>
<liclass="toctree-l3"><aclass="reference internal" href="../Chapter1/list/interaction_between_2_lists.html">2.3.4. Interaction Between 2 Lists</a></li>
215
-
<liclass="toctree-l3"><aclass="reference internal" href="../Chapter1/list/apply_functions_to_elements.html">2.3.5. Apply Functions to Elements in a List</a></li>
214
+
<liclass="toctree-l3"><aclass="reference internal" href="../Chapter1/list/apply_functions_to_elements.html">2.3.4. Apply Functions to Elements in a List</a></li>
<h2><spanclass="section-number">7.4.3. </span>Simplify Python Logging with Loguru<aclass="headerlink" href="#simplify-python-logging-with-loguru" title="Permalink to this heading">#</a></h2>
715
-
<p>Are you struggling with the complexity of configuring a logger object before logging in Python? With Loguru, you can skip this step and use the logger object directly with pre-built color and format settings.</p>
715
+
<p>Have you ever found yourself using print() instead of a proper logger due to the hassle of setup?</p>
716
+
<p>With Loguru, you can get started with logging right away. A single import is all you need to begin logging with pre-configured color and format settings.</p>
716
717
<p>Here is the comparison between the standard Python logging library and Loguru:</p>
0 commit comments