Analyzer
analora.analyzer ¶
Contain analyzers.
analora.analyzer.AccuracyAnalyzer ¶
Bases: BaseTruePredAnalyzer
Implement the accuracy analyzer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y_true
|
str
|
The key of the ground truth target labels. |
required |
y_pred
|
str
|
The key of the predicted labels. |
required |
missing_policy
|
str
|
The policy on how to handle missing keys.
The following options are available: |
'raise'
|
nan_policy
|
str
|
The policy on how to handle NaN values in the input
arrays. The following options are available: |
'propagate'
|
Example usage:
>>> from analora.analyzer import AccuracyAnalyzer
>>> analyzer = AccuracyAnalyzer(y_true="target", y_pred="pred")
>>> analyzer
AccuracyAnalyzer(y_true='target', y_pred='pred', missing_policy='raise', nan_policy='propagate')
>>> data = {"pred": [3, 2, 0, 1, 0, 1], "target": [3, 2, 0, 1, 0, 1]}
>>> output = analyzer.analyze(data)
>>> output
Output(
(content): ContentGenerator()
(evaluator): AccuracyEvaluator(
(state): AccuracyState(y_true=(6,), y_pred=(6,), y_true_name='target', y_pred_name='pred', nan_policy='propagate')
)
)
analora.analyzer.BaseAnalyzer ¶
Bases: ABC
, Generic[T]
Define the base class to analyze a DataFrame.
Example usage:
# >>> import polars as pl
# >>> from analora.analyzer import AccuracyAnalyzer
# >>> analyzer = AccuracyAnalyzer(y_true="target", y_pred="pred")
# >>> analyzer
# AccuracyAnalyzer(y_true='target', y_pred='pred', drop_nulls=True, missing_policy='raise', nan_policy='propagate')
# >>> data = pl.DataFrame({"pred": [3, 2, 0, 1, 0, 1], "target": [3, 2, 0, 1, 0, 1]})
# >>> output = analyzer.analyze(data)
# >>> output
# AccuracyOutput(
# (state): AccuracyState(y_true=(6,), y_pred=(6,), y_true_name='target', y_pred_name='pred', nan_policy='propagate')
# )
analora.analyzer.BaseAnalyzer.analyze
abstractmethod
¶
analyze(data: T, lazy: bool = True) -> BaseOutput
Analyze the data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
T
|
The data to analyze. |
required |
lazy
|
bool
|
If |
True
|
Returns:
Type | Description |
---|---|
BaseOutput
|
The generated output. |
Example usage:
# >>> import polars as pl
# >>> from analora.analyzer import AccuracyAnalyzer
# >>> analyzer = AccuracyAnalyzer(y_true="target", y_pred="pred")
# >>> data = pl.DataFrame({"pred": [3, 2, 0, 1, 0, 1], "target": [3, 2, 0, 1, 0, 1]})
# >>> output = analyzer.analyze(data)
# >>> output
# AccuracyOutput(
# (state): AccuracyState(y_true=(6,), y_pred=(6,), y_true_name='target', y_pred_name='pred', nan_policy='propagate')
# )
analora.analyzer.BaseLazyAnalyzer ¶
Bases: BaseAnalyzer[T]
Define a base class to implement a lazy analyzer.
Example usage:
# >>> import polars as pl
# >>> from analora.analyzer import SummaryAnalyzer
# >>> analyzer = SummaryAnalyzer()
# >>> analyzer
# SummaryAnalyzer(columns=None, exclude_columns=(), missing_policy='raise', top=5)
# >>> frame = pl.DataFrame(
# ... {
# ... "col1": [0, 1, 1, 0, 0, 1, 0],
# ... "col2": [0, 1, 0, 1, 0, 1, 0],
# ... "col3": [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0],
# ... },
# ... schema={"col1": pl.Int64, "col2": pl.Int32, "col3": pl.Float64},
# ... )
# >>> output = analyzer.analyze(frame)
# >>> output
# SummaryOutput(
# (state): DataFrameState(dataframe=(7, 3), nan_policy='propagate', figure_config=MatplotlibFigureConfig(), top=5)
# )
analora.analyzer.BaseTruePredAnalyzer ¶
Bases: BaseLazyAnalyzer[T]
Define a base class to implement a data analyzer that takes two
input keys: y_true
and y_pred
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y_true
|
str
|
The key name of the ground truth target labels. |
required |
y_pred
|
str
|
The key name of the predicted labels. |
required |
missing_policy
|
str
|
The policy on how to handle missing keys.
The following options are available: |
required |
nan_policy
|
str
|
The policy on how to handle NaN values in the input
arrays. The following options are available: |
required |
analora.analyzer.ContentAnalyzer ¶
Bases: BaseLazyAnalyzer[Any]
Implement an analyzer that generates an output with the given custom content.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content
|
str
|
The content to use in the HTML code. |
required |
Example usage:
>>> from analora.analyzer import ContentAnalyzer
>>> analyzer = ContentAnalyzer(content="meow")
>>> analyzer
ContentAnalyzer()
>>> data = {"pred": [3, 2, 0, 1, 0, 1], "target": [3, 2, 0, 1, 0, 1]}
>>> output = analyzer.analyze(data)
>>> output
Output(
(content): ContentGenerator()
(evaluator): Evaluator(count=0)
)
analora.analyzer.is_analyzer_config ¶
is_analyzer_config(config: dict) -> bool
Indicate if the input configuration is a configuration for a
BaseAnalyzer
.
This function only checks if the value of the key _target_
is valid. It does not check the other values. If _target_
indicates a function, the returned type hint is used to check
the class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
dict
|
The configuration to check. |
required |
Returns:
Type | Description |
---|---|
bool
|
|
Example usage:
# >>> from analora.analyzer import is_analyzer_config
# >>> is_analyzer_config({"_target_": "analora.analyzer.AccuracyAnalyzer"})
# True
analora.analyzer.setup_analyzer ¶
setup_analyzer(
analyzer: BaseAnalyzer | dict,
) -> BaseAnalyzer
Set up an analyzer.
The analyzer is instantiated from its configuration
by using the BaseAnalyzer
factory function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
analyzer
|
BaseAnalyzer | dict
|
An analyzer or its configuration. |
required |
Returns:
Type | Description |
---|---|
BaseAnalyzer
|
An instantiated analyzer. |
Example usage:
# >>> from analora.analyzer import setup_analyzer
# >>> analyzer = setup_analyzer(
# ... {
# ... "_target_": "analora.analyzer.AccuracyAnalyzer",
# ... "y_true": "target",
# ... "y_pred": "pred",
# ... }
# ... )
# >>> analyzer
# AccuracyAnalyzer(y_true='target', y_pred='pred', drop_nulls=True, missing_policy='raise', nan_policy='propagate')