visualization
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| visualization [2025/05/30 13:55] – [System Workflow] eagleeyenebula | visualization [2025/05/30 13:59] (current) – [Best Practices] eagleeyenebula | ||
|---|---|---|---|
| Line 43: | Line 43: | ||
| ===== Method: `plot_metrics` ===== | ===== Method: `plot_metrics` ===== | ||
| - | The `plot_metrics` method provides a one-stop solution for visualizing ML training metrics. | + | The **plot_metrics** method provides a one-stop solution for visualizing ML training metrics. |
| < | < | ||
| - | ```python | + | python |
| @staticmethod | @staticmethod | ||
| def plot_metrics(metrics): | def plot_metrics(metrics): | ||
| Line 68: | Line 68: | ||
| except Exception as e: | except Exception as e: | ||
| logging.error(f" | logging.error(f" | ||
| - | ``` | + | |
| </ | </ | ||
| ==== Parameters ==== | ==== Parameters ==== | ||
| - | | + | ** **metrics** (dict): A dictionary where: |
| - | | + | |
| - | | + | |
| ==== Workflow of the Method ==== | ==== Workflow of the Method ==== | ||
| 1. **Initialize Logging**: | 1. **Initialize Logging**: | ||
| - | Logs the start of the plotting process for transparency in debugging. | + | * Logs the start of the plotting process for transparency in debugging. |
| 2. **Iterate Through Metrics**: | 2. **Iterate Through Metrics**: | ||
| - | Loops through each metric (e.g., accuracy, loss) and plots its values versus epochs. | + | * Loops through each metric (e.g., accuracy, loss) and plots its values versus epochs. |
| 3. **Add Legends and Labels**: | 3. **Add Legends and Labels**: | ||
| - | | + | * Annotates the plot with legends, titles, and axis labels to improve clarity. |
| 4. **Display Plot**: | 4. **Display Plot**: | ||
| - | Opens the rendered plot for analysis. | + | * Opens the rendered plot for analysis. |
| 5. **Error Handling**: | 5. **Error Handling**: | ||
| - | Logs any errors in the process, such as missing or mismatched data. | + | * Logs any errors in the process, such as missing or mismatched data. |
| ===== Usage Examples ===== | ===== Usage Examples ===== | ||
| - | Below are practical examples of how to use the `plot_metrics()` method for visualizing training metrics. | + | Below are practical examples of how to use the **plot_metrics()** method for visualizing training metrics. |
| ==== Example 1: Visualizing Accuracy and Loss ==== | ==== Example 1: Visualizing Accuracy and Loss ==== | ||
| Line 103: | Line 103: | ||
| < | < | ||
| - | ```python | + | python |
| from visualization import Visualization | from visualization import Visualization | ||
| Line 114: | Line 114: | ||
| # Plot metrics | # Plot metrics | ||
| Visualization.plot_metrics(metrics) | Visualization.plot_metrics(metrics) | ||
| - | ``` | + | |
| </ | </ | ||
| **Expected Output**: | **Expected Output**: | ||
| - | - A plot with two lines: | + | * A plot with two lines: |
| 1. Accuracy improving over epochs. | 1. Accuracy improving over epochs. | ||
| 2. Loss decreasing over epochs. | 2. Loss decreasing over epochs. | ||
| - | - X-axis labeled as " | + | * X-axis labeled as " |
| - | - Y-axis labeled as " | + | * Y-axis labeled as " |
| ==== Example 2: Single Metric Plot ==== | ==== Example 2: Single Metric Plot ==== | ||
| Line 129: | Line 129: | ||
| < | < | ||
| - | ```python | + | python |
| # Only validation loss | # Only validation loss | ||
| metrics = { | metrics = { | ||
| Line 136: | Line 136: | ||
| Visualization.plot_metrics(metrics) | Visualization.plot_metrics(metrics) | ||
| - | ``` | + | |
| </ | </ | ||
| Line 144: | Line 144: | ||
| < | < | ||
| - | ```python | + | python |
| # Extended visualization | # Extended visualization | ||
| metrics = { | metrics = { | ||
| Line 157: | Line 157: | ||
| plt.grid(color=" | plt.grid(color=" | ||
| plt.show() | plt.show() | ||
| - | ``` | + | |
| </ | </ | ||
| Line 165: | Line 165: | ||
| < | < | ||
| - | ```python | + | python |
| # Invalid metrics format to simulate failure | # Invalid metrics format to simulate failure | ||
| metrics = { | metrics = { | ||
| Line 173: | Line 173: | ||
| Visualization.plot_metrics(metrics) | Visualization.plot_metrics(metrics) | ||
| - | ``` | + | |
| </ | </ | ||
| **Expected Log**: | **Expected Log**: | ||
| < | < | ||
| - | ``` | + | |
| `ERROR: | `ERROR: | ||
| - | ``` | + | |
| </ | </ | ||
| Line 190: | Line 190: | ||
| < | < | ||
| - | ```python | + | python |
| for key, values in metrics.items(): | for key, values in metrics.items(): | ||
| plt.plot(values, | plt.plot(values, | ||
| - | ``` | + | |
| </ | </ | ||
| Line 201: | Line 201: | ||
| < | < | ||
| - | ```python | + | python |
| plt.savefig(" | plt.savefig(" | ||
| logging.info(f" | logging.info(f" | ||
| - | ``` | + | |
| </ | </ | ||
| Line 211: | Line 211: | ||
| Embed the plotted visualizations into a web dashboard using tools such as **Dash** or **Flask**: | Embed the plotted visualizations into a web dashboard using tools such as **Dash** or **Flask**: | ||
| < | < | ||
| - | ```python | + | python |
| import io | import io | ||
| from flask import Flask, Response | from flask import Flask, Response | ||
| Line 228: | Line 228: | ||
| if __name__ == " | if __name__ == " | ||
| app.run(debug=True) | app.run(debug=True) | ||
| - | ``` | + | |
| </ | </ | ||
| Line 234: | Line 234: | ||
| 1. **Label Your Plots**: | 1. **Label Your Plots**: | ||
| - | | + | * Always provide meaningful titles, axis labels, and legends to improve readability. |
| 2. **Validate Data Inputs**: | 2. **Validate Data Inputs**: | ||
| - | | + | * Ensure that all metric keys and values are properly structured before invoking `plot_metrics()`. |
| 3. **Modular Designs**: | 3. **Modular Designs**: | ||
| - | | + | * Extend and customize utility functions without modifying the core `Visualization` class directly. |
| 4. **Optimize for Scaling**: | 4. **Optimize for Scaling**: | ||
| - | For handling large datasets, reduce the number of points or smooth values to improve performance. | + | * For handling large datasets, reduce the number of points or smooth values to improve performance. |
| ===== Conclusion ===== | ===== Conclusion ===== | ||
visualization.1748613353.txt.gz · Last modified: 2025/05/30 13:55 by eagleeyenebula
