| Conditions | 4 |
| Total Lines | 54 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | from collections import defaultdict |
||
| 35 | def plot_roc_curves(roc_curves, aucs=None, |
||
| 36 | title='ROC Curves by Attribute', |
||
| 37 | ax=None, figsize=None, |
||
| 38 | title_fontsize='large', text_fontsize='medium'): |
||
| 39 | """Generate the ROC curves by attribute from (fpr, tpr, thresholds). |
||
| 40 | |||
| 41 | Based on :func:`skplt.metrics.plot_roc` |
||
| 42 | |||
| 43 | :param roc_curves: Receiver operating characteristic (ROC) |
||
| 44 | by attribute. |
||
| 45 | :type roc_curves: dict |
||
| 46 | :param aucs: Area Under the ROC (AUC) by attribute. |
||
| 47 | :type aucs: dict |
||
| 48 | :param str title: Title of the generated plot. |
||
| 49 | :param ax: The axes upon which to plot the curve. |
||
| 50 | If `None`, the plot is drawn on a new set of axes. |
||
| 51 | :param tuple figsize: Tuple denoting figure size of the plot |
||
| 52 | e.g. (6, 6). |
||
| 53 | :param title_fontsize: Matplotlib-style fontsizes. |
||
| 54 | Use e.g. 'small', 'medium', 'large' |
||
| 55 | or integer-values. |
||
| 56 | :param text_fontsize: Matplotlib-style fontsizes. |
||
| 57 | Use e.g. 'small', 'medium', 'large' |
||
| 58 | or integer-values. |
||
| 59 | :return: The axes on which the plot was drawn. |
||
| 60 | :rtype: :class:`matplotlib.axes.Axes` |
||
| 61 | |||
| 62 | """ |
||
| 63 | |||
| 64 | if ax is None: |
||
| 65 | fig, ax = plt.subplots(1, 1, figsize=figsize) # pylint: disable=unused-variable |
||
| 66 | |||
| 67 | ax.set_title(title, fontsize=title_fontsize) |
||
| 68 | |||
| 69 | for x_sens_value in roc_curves: |
||
| 70 | |||
| 71 | label = 'ROC curve of group {0}'.format(x_sens_value) |
||
| 72 | if aucs is not None: |
||
| 73 | label += ' (area = {:0.2f})'.format(aucs[x_sens_value]) |
||
| 74 | |||
| 75 | ax.plot(roc_curves[x_sens_value][0], |
||
| 76 | roc_curves[x_sens_value][1], |
||
| 77 | lw=2, |
||
| 78 | label=label) |
||
| 79 | |||
| 80 | ax.plot([0, 1], [0, 1], 'k--', lw=2) |
||
| 81 | ax.set_xlim([0.0, 1.0]) |
||
| 82 | ax.set_ylim([0.0, 1.05]) |
||
| 83 | ax.set_xlabel('False Positive Rate', fontsize=text_fontsize) |
||
| 84 | ax.set_ylabel('True Positive Rate', fontsize=text_fontsize) |
||
| 85 | ax.tick_params(labelsize=text_fontsize) |
||
| 86 | ax.legend(loc='lower right', fontsize=text_fontsize) |
||
| 87 | |||
| 88 | return ax |
||
| 89 | |||
| 124 |