Common
This is the reference to the functions contained in
common
. For now, they are all accesible directly
through machine-learning-datasets
and you don't
need to use the common
namespace.
Common Utility Functions
BaseAIF360DSProtocol
Bases: Protocol
Protocol for AIF360 Datasets
Source code in machine_learning_datasets/common.py
30 31 32 33 |
|
validate_dataset()
Validate the AIF360 dataset
Source code in machine_learning_datasets/common.py
32 33 |
|
BaseAIF360MetricProtocol
Bases: Protocol
Protocol for AIF360 Metrics
Source code in machine_learning_datasets/common.py
35 36 37 38 |
|
num_instances(privileged=None)
Count the number of priviledged instances
Source code in machine_learning_datasets/common.py
37 38 |
|
BaseAlibiExplanationProtocol
Bases: Protocol
Protocol for Alibi Explanations
Source code in machine_learning_datasets/common.py
40 41 42 43 |
|
to_json()
Convert the Alibi explanation to JSON format
Source code in machine_learning_datasets/common.py
42 43 |
|
BaseModelProtocol
Bases: Protocol
Protocol for Any Sklearn Compatible Models
Source code in machine_learning_datasets/common.py
17 18 19 20 |
|
predict(X, **kwargs)
Predict with the fitted model
Source code in machine_learning_datasets/common.py
19 20 |
|
BaseTransformerProtocol
Bases: Protocol
Protocol for Any Sklearn Compatible Scalers, Encoders & Transformers
Source code in machine_learning_datasets/common.py
22 23 24 25 26 27 28 |
|
inverse_transform(X, **kwargs)
Inverse transform with the fitted transformer
Source code in machine_learning_datasets/common.py
27 28 |
|
transform(X, **kwargs)
Transform with the fitted transformer
Source code in machine_learning_datasets/common.py
24 25 |
|
plot_polar(df, r, theta, name=None, show=True)
Plots a polar line chart using Plotly Express.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
The DataFrame containing the data. |
required |
r |
Union[str, int, ArrayLike]
|
The column name or index of the radial coordinate. |
required |
theta |
Union[str, int, ArrayLike]
|
The column name or index of the angular coordinate. |
required |
name |
Optional[str]
|
The title of the chart. Defaults to None. |
None
|
show |
Optional[bool]
|
Whether to display the chart. Defaults to True. |
True
|
Returns:
Type | Description |
---|---|
Optional[Figure]
|
Optional[Figure]: The Plotly Figure object if show is False, otherwise None. |
Raises:
Type | Description |
---|---|
ModuleNotFoundError
|
If |
Example
plot_polar(df, 'r', 'theta', name='Polar Chart', show=True)
Source code in machine_learning_datasets/common.py
85 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 124 125 126 127 128 129 130 131 132 |
|
runcmd(cmd, verbose=False)
Runs a command in the shell and captures the output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cmd |
str
|
The command to be executed. |
required |
verbose |
bool
|
If True, the output will be printed to the console. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
Tuple[bool, str, int]
|
Tuple[bool, str, int]: A tuple containing the following elements: - error (bool): True if an error occurred during the execution of the command, False otherwise. - output (str): The output generated by the command. - numlines (int): The number of lines in the output. |
Source code in machine_learning_datasets/common.py
45 46 47 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 83 |
|
show_image(path_to_image, width=None, height=None)
Displays an image in Jupyter Notebook.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path_to_image |
str
|
The path to the image file. |
required |
width |
Optional[int]
|
The width of the displayed image. Defaults to None. |
None
|
height |
Optional[int]
|
The height of the displayed image. Defaults to None. |
None
|
Raises:
Type | Description |
---|---|
ModuleNotFoundError
|
If |
Raises:
Type | Description |
---|---|
ValueError
|
If the extension of the image file is unknown. |
Returns:
Type | Description |
---|---|
None
|
None |
Example
show_image('path/to/image.jpg', width=500, height=300)
Source code in machine_learning_datasets/common.py
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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
|