HeartKit
heartkit.cli
parse_content(cls, content)
Parse file or raw content into Pydantic model.
Parameters:
-
cls
(B
) –Pydantic model subclasss
-
content
(str
) –File path or raw content
Returns:
-
B
(B
) –Pydantic model subclass instance
Source code in heartkit/cli.py
heartkit.defines
AugmentationParams
DatasetParams
Bases: BaseModel
Dataset parameters
Source code in heartkit/defines.py
HKDemoParams
Bases: BaseModel
HK demo command params
Source code in heartkit/defines.py
HKDownloadParams
Bases: BaseModel
Download command params
Source code in heartkit/defines.py
HKExportParams
Bases: BaseModel
Export command params
Source code in heartkit/defines.py
model_post_init(__context)
Post init hook
Source code in heartkit/defines.py
HKMode
HKTestParams
Bases: BaseModel
Test command params
Source code in heartkit/defines.py
model_post_init(__context)
Post init hook
Source code in heartkit/defines.py
HKTrainParams
Bases: BaseModel
Train command params
Source code in heartkit/defines.py
model_post_init(__context)
Post init hook
Source code in heartkit/defines.py
ModelArchitecture
PreprocessParams
QuantizationParams
Bases: BaseModel
Quantization parameters
Source code in heartkit/defines.py
heartkit.metrics
compute_iou(y_true, y_pred, average='micro')
Compute IoU
Parameters:
Returns:
-
float
(float
) –IoU
Source code in heartkit/metrics.py
confusion_matrix_plot(y_true, y_pred, labels, save_path=None, normalize=False, **kwargs)
Generate confusion matrix plot via matplotlib/seaborn
Parameters:
-
y_true
(NDArray
) –True y labels
-
y_pred
(NDArray
) –Predicted y labels
-
labels
(list[str]
) –Label names
-
save_path
(str | None
, default:None
) –Path to save plot. Defaults to None.
Returns:
-
tuple[Figure, Axes] | None
–tuple[plt.Figure, plt.Axes] | None: Figure and axes
Source code in heartkit/metrics.py
f1(y_true, y_prob, multiclass=False, threshold=None)
Compute F1 scores
Parameters:
-
y_true
(npt.NDArray
) –Y true
-
y_prob
(npt.NDArray
) –2D matrix with class probs
-
multiclass
(bool
, default:False
) –If multiclass. Defaults to False.
-
threshold
(float
, default:None
) –Decision threshold for multiclass. Defaults to None.
Returns:
Source code in heartkit/metrics.py
f_max(y_true, y_prob, thresholds=None)
Compute F max source: https://github.com/helme/ecg_ptbxl_benchmarking
Parameters:
-
y_true
(NDArray
) –Y True
-
y_prob
(NDArray
) –Y probs
-
thresholds
(float | list[float] | None
, default:None
) –Thresholds. Defaults to None.
Returns:
Source code in heartkit/metrics.py
macro_precision_recall(y_true, y_prob, thresholds)
Compute macro precision and recall source: https://github.com/helme/ecg_ptbxl_benchmarking
Parameters:
-
y_true
(NDArray
) –True y labels
-
y_prob
(NDArray
) –Predicted y labels
-
thresholds
(NDArray
) –Thresholds
Returns:
Source code in heartkit/metrics.py
multi_f1(y_true, y_prob)
Compute multi-class F1
Parameters:
Returns:
Source code in heartkit/metrics.py
multilabel_confusion_matrix_plot(y_true, y_pred, labels, save_path=None, normalize=False, max_cols=5, **kwargs)
Generate multilabel confusion matrix plot via matplotlib/seaborn
Parameters:
-
y_true
(NDArray
) –True y labels
-
y_pred
(NDArray
) –Predicted y labels
-
labels
(list[str]
) –Label names
-
save_path
(str | None
, default:None
) –Path to save plot. Defaults to None.
-
normalize
(Literal['true', 'pred', 'all'] | None
, default:False
) –Normalize. Defaults to False.
-
max_cols
(int
, default:5
) –Max columns. Defaults to 5.
Returns:
-
tuple[Figure, Axes] | None
–tuple[plt.Figure, plt.Axes] | None: Figure and axes
Source code in heartkit/metrics.py
px_plot_confusion_matrix(y_true, y_pred, labels, normalize=False, save_path=None, title=None, width=None, height=400, bg_color='rgba(38,42,50,1.0)')
Generate confusion matrix plot via plotly
Parameters:
-
y_true
(NDArray
) –True y labels
-
y_pred
(NDArray
) –Predicted y labels
-
labels
(list[str]
) –Label names
-
normalize
(Literal['true', 'pred', 'all'] | None
, default:False
) –Normalize. Defaults to False.
-
save_path
(PathLike | None
, default:None
) –Path to save plot. Defaults to None.
-
title
(str | None
, default:None
) –Title. Defaults to None.
-
width
(int | None
, default:None
) –Width. Defaults to None.
-
height
(int | None
, default:400
) –Height. Defaults to 400.
-
bg_color
(str
, default:'rgba(38,42,50,1.0)'
) –Background color. Defaults to "rgba(38,42,50,1.0)".
Returns:
-
–
plotly.graph_objs.Figure: Plotly figure
Source code in heartkit/metrics.py
roc_auc_plot(y_true, y_prob, labels, save_path=None, **kwargs)
Generate ROC plot via matplotlib/seaborn
Parameters:
-
y_true
(NDArray
) –True y labels
-
y_prob
(NDArray
) –Predicted y labels
-
labels
(list[str]
) –Label names
-
save_path
(str | None
, default:None
) –Path to save plot. Defaults to None.
Returns:
-
tuple[Figure, Axes] | None
–tuple[plt.Figure, plt.Axes] | None: Figure and axes
Source code in heartkit/metrics.py
heartkit.utils
download_file(src, dst, progress=True, chunk_size=8192)
Download file from supplied url to destination streaming.
Parameters:
-
src
(str
) –Source URL path
-
dst
(PathLike
) –Destination file path
-
progress
(bool
, default:True
) –Display progress bar. Defaults to True.
Source code in heartkit/utils.py
env_flag(env_var, default=False)
Return the specified environment variable coerced to a bool, as follows:
- When the variable is unset, or set to the empty string, return default
.
- When the variable is set to a truthy value, returns True
.
These are the truthy values:
- 1
- true, yes, on
- When the variable is set to the anything else, returns False.
Example falsy values:
- 0
- no
- Ignore case and leading/trailing whitespace.
Parameters:
-
env_var
(str
) –Environment variable name
-
default
(bool
, default:False
) –Default value. Defaults to False.
Returns:
-
bool
(bool
) –Value of environment variable
Source code in heartkit/utils.py
load_pkl(file, compress=True)
Load pickled file.
Parameters:
-
file
(str
) –File path (.pkl)
-
compress
(bool
, default:True
) –If file is compressed. Defaults to True.
Returns:
Source code in heartkit/utils.py
resolve_template_path(fpath, **kwargs)
Resolve templated path w/ supplied substitutions.
Parameters:
Returns:
-
Path
(Path
) –Resolved file path
Source code in heartkit/utils.py
save_pkl(file, compress=True, **kwargs)
Save python objects into pickle file.
Parameters:
-
file
(str
) –File path (.pkl)
-
compress
(bool
, default:True
) –Whether to compress file. Defaults to True.
Source code in heartkit/utils.py
set_random_seed(seed=None)
Set random seed across libraries: TF, Numpy, Python
Parameters:
-
seed
(int | None
, default:None
) –Random seed state to use. Defaults to None.
Returns:
-
int
(int
) –Random seed
Source code in heartkit/utils.py
setup_logger(log_name)
Setup logger with Rich
Parameters:
-
log_name
(str
) –Logger name
Returns:
-
Logger
–logging.Logger: Logger