Plots precision recall curves for distributions. Creates the PRD plot for the given data and stores the plot in a given path. Args: precision_recall_pairs: List of prd_data to plot. Each item in this list is a 2D array of precision and recall values for the
(precision_recall_pairs, labels=None, out_path=None,
legend_loc='lower left', dpi=300)
| 221 | return precision, recall |
| 222 | |
| 223 | def plot(precision_recall_pairs, labels=None, out_path=None, |
| 224 | legend_loc='lower left', dpi=300): |
| 225 | """Plots precision recall curves for distributions. |
| 226 | |
| 227 | Creates the PRD plot for the given data and stores the plot in a given path. |
| 228 | |
| 229 | Args: |
| 230 | precision_recall_pairs: List of prd_data to plot. Each item in this list is |
| 231 | a 2D array of precision and recall values for the |
| 232 | same number of ratios. |
| 233 | labels: Optional list of labels of same length as list_of_prd_data. The |
| 234 | default value is None. |
| 235 | out_path: Output path for the resulting plot. If None, the plot will be |
| 236 | opened via plt.show(). The default value is None. |
| 237 | legend_loc: Location of the legend. The default value is 'lower left'. |
| 238 | dpi: Dots per inch (DPI) for the figure. The default value is 150. |
| 239 | |
| 240 | Raises: |
| 241 | ValueError: If labels is a list of different length than list_of_prd_data. |
| 242 | """ |
| 243 | |
| 244 | if labels is not None and len(labels) != len(precision_recall_pairs): |
| 245 | raise ValueError( |
| 246 | 'Length of labels %d must be identical to length of ' |
| 247 | 'precision_recall_pairs %d.' |
| 248 | % (len(labels), len(precision_recall_pairs))) |
| 249 | |
| 250 | fig = plt.figure(figsize=(3.5, 3.5), dpi=dpi) |
| 251 | plot_handle = fig.add_subplot(111) |
| 252 | plot_handle.tick_params(axis='both', which='major', labelsize=12) |
| 253 | |
| 254 | for i in range(len(precision_recall_pairs)): |
| 255 | precision, recall = precision_recall_pairs[i] |
| 256 | label = labels[i] if labels is not None else None |
| 257 | plt.plot(recall, precision, label=label, alpha=0.5, linewidth=3) |
| 258 | |
| 259 | if labels is not None: |
| 260 | plt.legend(loc=legend_loc) |
| 261 | |
| 262 | plt.xlim([0, 1]) |
| 263 | plt.ylim([0, 1]) |
| 264 | plt.xlabel('Recall', fontsize=12) |
| 265 | plt.ylabel('Precision', fontsize=12) |
| 266 | plt.tight_layout() |
| 267 | if out_path is None: |
| 268 | plt.show() |
| 269 | else: |
| 270 | plt.savefig(out_path, bbox_inches='tight', dpi=dpi) |
| 271 | plt.close() |
| 272 | |
| 273 | |
| 274 | # the next class and 4 function are ported from https://github.com/youngjung/improved-precision-and-recall-metric-pytorch/blob/master/improved_precision_recall.py#L239 |
nothing calls this directly
no outgoing calls
no test coverage detected