Skip to content

getml.pipeline.Plots

Plots(name: str)

Custom class for handling the plots generated by the pipeline.

PARAMETER DESCRIPTION
name

The id of the pipeline the plots are associated with.

TYPE: str

Example
recall, precision = my_pipeline.plots.precision_recall_curve()
fpr, tpr = my_pipeline.plots.roc_curve()
Source code in getml/pipeline/plots.py
40
41
42
43
44
def __init__(self, name: str) -> None:
    if not isinstance(name, str):
        raise ValueError("'name' must be a str.")

    self.name = name

lift_curve

lift_curve(target_num: int = 0) -> Tuple[ndarray, ndarray]

Returns the data for the lift curve, as displayed in the getML Monitor.

This requires that you call score first. The data used for the curve will always be the data from the last time you called score.

PARAMETER DESCRIPTION
target_num

Indicates for which target you want to plot the lift curve. (Pipelines can have more than one target.)

TYPE: int DEFAULT: 0

RETURNS DESCRIPTION
Tuple[ndarray, ndarray]

The first array is the proportion of samples, usually displayed on the x-axis. The second array is the lift, usually displayed on the y-axis.

Source code in getml/pipeline/plots.py
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
def lift_curve(self, target_num: int = 0) -> Tuple[np.ndarray, np.ndarray]:
    """
    Returns the data for the lift curve, as displayed in the getML Monitor.

    This requires that you call
    [`score`][getml.Pipeline.score] first. The data used
    for the curve will always be the data from the *last* time
    you called [`score`][getml.Pipeline.score].

    Args:
        target_num:
            Indicates for which target you want to plot the lift
            curve. (Pipelines can have more than one target.)

    Returns:
        The first array is the proportion of samples, usually displayed on the x-axis.
            The second array is the lift, usually displayed on the y-axis.
    """

    cmd: Dict[str, Any] = {}

    cmd["type_"] = "Pipeline.lift_curve"
    cmd["name_"] = self.name

    cmd["target_num_"] = target_num

    with comm.send_and_get_socket(cmd) as sock:
        msg = comm.recv_string(sock)
        if msg != "Success!":
            comm.handle_engine_exception(msg)
        msg = comm.recv_string(sock)

    json_obj = json.loads(msg)

    return (np.asarray(json_obj["proportion_"]), np.asarray(json_obj["lift_"]))

precision_recall_curve

precision_recall_curve(
    target_num: int = 0,
) -> Tuple[ndarray, ndarray]

Returns the data for the precision-recall curve, as displayed in the getML Monitor.

This requires that you call score first. The data used for the curve will always be the data from the last time you called score.

PARAMETER DESCRIPTION
target_num

Indicates for which target you want to plot the lift curve. (Pipelines can have more than one target.)

TYPE: int DEFAULT: 0

RETURNS DESCRIPTION
Tuple[ndarray, ndarray]

The first array is the recall (a.k.a. true positive rate), usually displayed on the x-axis. The second array is the precision, usually displayed on the y-axis.

Source code in getml/pipeline/plots.py
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
def precision_recall_curve(
    self, target_num: int = 0
) -> Tuple[np.ndarray, np.ndarray]:
    """
    Returns the data for the precision-recall curve, as displayed in the getML
    Monitor.

    This requires that you call
    [`score`][getml.Pipeline.score] first. The data used
    for the curve will always be the data from the *last* time
    you called [`score`][getml.Pipeline.score].

    Args:
        target_num:
            Indicates for which target you want to plot the lift
            curve. (Pipelines can have more than one target.)

    Returns:
        The first array is the recall (a.k.a. true positive rate), usually displayed on the x-axis.
            The second array is the precision, usually displayed on the y-axis.
    """

    cmd: Dict[str, Any] = {}

    cmd["type_"] = "Pipeline.precision_recall_curve"
    cmd["name_"] = self.name

    cmd["target_num_"] = target_num

    with comm.send_and_get_socket(cmd) as sock:
        msg = comm.recv_string(sock)
        if msg != "Success!":
            comm.handle_engine_exception(msg)
        msg = comm.recv_string(sock)

    json_obj = json.loads(msg)

    return (np.asarray(json_obj["tpr_"]), np.asarray(json_obj["precision_"]))

roc_curve

roc_curve(target_num: int = 0) -> Tuple[ndarray, ndarray]

Returns the data for the ROC curve, as displayed in the getML Monitor.

This requires that you call score first. The data used for the curve will always be the data from the last time you called score.

PARAMETER DESCRIPTION
target_num

Indicates for which target you want to plot the lift curve. (Pipelines can have more than one target.)

TYPE: int DEFAULT: 0

RETURNS DESCRIPTION
Tuple[ndarray, ndarray]

The first array is the false positive rate, usually displayed on the x-axis. The second array is the true positive rate, usually displayed on the y-axis.

Source code in getml/pipeline/plots.py
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
def roc_curve(self, target_num: int = 0) -> Tuple[np.ndarray, np.ndarray]:
    """
    Returns the data for the ROC curve, as displayed in the getML Monitor.

    This requires that you call
    [`score`][getml.Pipeline.score] first. The data used
    for the curve will always be the data from the *last* time
    you called [`score`][getml.Pipeline.score].

    Args:
        target_num:
            Indicates for which target you want to plot the lift
            curve. (Pipelines can have more than one target.)

    Returns:
        The first array is the false positive rate, usually displayed on the x-axis.
            The second array is the true positive rate, usually displayed on the y-axis.
    """

    cmd: Dict[str, Any] = {}

    cmd["type_"] = "Pipeline.roc_curve"
    cmd["name_"] = self.name

    cmd["target_num_"] = target_num

    with comm.send_and_get_socket(cmd) as sock:
        msg = comm.recv_string(sock)
        if msg != "Success!":
            comm.handle_engine_exception(msg)
        msg = comm.recv_string(sock)

    json_obj = json.loads(msg)

    return (np.asarray(json_obj["fpr_"]), np.asarray(json_obj["tpr_"]))