|
| 1 | +import matplotlib.pyplot as plt |
| 2 | +import numpy as np |
| 3 | + |
| 4 | +from shiny import ui |
| 5 | + |
| 6 | + |
| 7 | +def plot_loss_over_time(): |
| 8 | + epochs = np.arange(1, 101) |
| 9 | + loss = 1000 / np.sqrt(epochs) + np.random.rand(100) * 25 |
| 10 | + |
| 11 | + fig = plt.figure(figsize=(10, 6)) |
| 12 | + plt.plot(epochs, loss) |
| 13 | + plt.xlabel("Epochs") |
| 14 | + plt.ylabel("Loss") |
| 15 | + return fig |
| 16 | + |
| 17 | + |
| 18 | +def plot_accuracy_over_time(): |
| 19 | + epochs = np.arange(1, 101) |
| 20 | + accuracy = np.sqrt(epochs) / 12 + np.random.rand(100) * 0.15 |
| 21 | + accuracy = [np.min([np.max(accuracy[:i]), 1]) for i in range(1, 101)] |
| 22 | + |
| 23 | + fig = plt.figure(figsize=(10, 6)) |
| 24 | + plt.plot(epochs, accuracy) |
| 25 | + plt.xlabel("Epochs") |
| 26 | + plt.ylabel("Accuracy") |
| 27 | + return fig |
| 28 | + |
| 29 | + |
| 30 | +def plot_feature_importance(): |
| 31 | + features = ["Product Category", "Price", "Brand", "Rating", "Number of Reviews"] |
| 32 | + importance = np.random.rand(5) |
| 33 | + |
| 34 | + fig = plt.figure(figsize=(10, 6)) |
| 35 | + plt.barh(features, importance) |
| 36 | + plt.xlabel("Importance") |
| 37 | + return fig |
| 38 | + |
| 39 | + |
| 40 | +card_loss = ui.card( |
| 41 | + ui.card_header("Loss Over Time"), |
| 42 | + ui.output_plot("loss_over_time"), |
| 43 | + full_screen=True, |
| 44 | +) |
| 45 | + |
| 46 | +card_acc = ui.card( |
| 47 | + ui.card_header("Accuracy Over Time"), |
| 48 | + ui.output_plot("accuracy_over_time"), |
| 49 | + full_screen=True, |
| 50 | +) |
| 51 | + |
| 52 | +card_feat = ui.card( |
| 53 | + ui.card_header("Feature Importance"), |
| 54 | + ui.output_plot("feature_importance"), |
| 55 | + full_screen=True, |
| 56 | +) |
0 commit comments