@@ -75,41 +75,50 @@ Why create everything from scratch, if some things exist already? Here are some
75
75
+ [ CHARTIO] ( https://chartio.com/learn/charts/how-to-choose-colors-data-visualization/ ) - must read on how to choose colors and color palettes.
76
76
77
77
78
- # How to use
79
- > TBD: How to use the functions. What is their standardization? How can a figure be altered?
78
+ # Install
80
79
81
- Install the package (currently) .
80
+ Install the package via pip .
82
81
``` bash
83
- pip install -e .
82
+ pip install plotsandgraphs
84
83
```
85
84
86
- Install the package (in the future) .
85
+ Alternativelynstall the package from git .
87
86
``` bash
88
- pip install plotsandgraphs
87
+ git clone https://github.com/joshuawe/plots_and_graphs
88
+ cd plots_and_graphs
89
+ pip install -e .
89
90
```
90
91
91
- Example usage for a calibration curve.
92
+ # Usage
93
+
94
+ Example usage of results from a binary classifier for a calibration curve.
92
95
93
96
``` python
94
- import plotsandgraphs
95
97
import matplotlib.pyplot as plt
96
98
import numpy as np
99
+ import plotsandgraphs as pandg
97
100
98
- # create some data
101
+ # create some predictions of a hypothetical binary classifier
99
102
n_samples = 1000
100
- y_prob = np.random.uniform(0 , 1 , n_samples) # the probability of class 1 predictions
101
- y_true = np.random.choice([0 ,1 ], n_samples) # the actually corresponding class labels
103
+ y_true = np.random.choice([0 ,1 ], n_samples, p = [0.4 , 0.6 ]) # the true class labels 0 or 1, with class imbalance 40:60
102
104
103
- # create figure
104
- fig_auroc = plotsandgraphs.binary_classifier.plot_calibration_curve(y_prob, y_true, save_fig_path = None )
105
+ y_prob = np.zeros(y_true.shape) # a model's probability of class 1 predictions
106
+ y_prob[y_true== 1 ] = np.random.beta(1 , 0.6 , y_prob[y_true== 1 ].shape)
107
+ y_prob[y_true== 0 ] = np.random.beta(0.5 , 1 , y_prob[y_true== 0 ].shape)
105
108
106
- # customize figure
109
+ # show prob distribution
110
+ fig_hist = pandg.binary_classifier.plot_y_prob_histogram(y_prob, y_true, save_fig_path = None )
111
+
112
+ # create calibration curve
113
+ fig_auroc = pandg.binary_classifier.plot_calibration_curve(y_prob, y_true, save_fig_path = None )
114
+
115
+
116
+ # --- OPTIONAL: Customize figure ---
117
+ # get axis of figure and change title
107
118
axes = fig_auroc.get_axes()
108
119
ax0 = axes[0 ]
109
120
ax0.set_title(' New Title for Calibration Plot' )
110
-
111
- # save figure
112
- fig.savefig(' calibration_plot.png' , bbox_inches = ' tight' )
121
+ fig_auroc.show()
113
122
```
114
123
115
124
# Requirements
0 commit comments