postprocessing
This consists of modules which handles the output of Model after the model has been trained i.e. after .fit method has been called on it.
Please note that the SeqMetrics sub-module has been deprecated. Please use SeqMetrics library instead.
ProcessPredictions
- class ai4water.postprocessing.ProcessPredictions(mode: str, forecast_len: Optional[int] = None, output_features: Optional[Union[str, list]] = None, wandb_config: Optional[dict] = None, path: Optional[str] = None, dpi: int = 300, show=1, save: bool = True, plots: Optional[Union[str, list]] = None, quantiles: Optional[int] = None)[source]
Bases:
Plot
post processing of results after training.
- __init__(mode: str, forecast_len: Optional[int] = None, output_features: Optional[Union[str, list]] = None, wandb_config: Optional[dict] = None, path: Optional[str] = None, dpi: int = 300, show=1, save: bool = True, plots: Optional[Union[str, list]] = None, quantiles: Optional[int] = None)[source]
- Parameters:
mode (str) – either “regression” or “classification”
forecast_len (int, optional (default=None)) – forecast length, only valid when mode is regression
output_features (str, optional) – names of output features
plots (int/list, optional (default=None)) –
the names of plots to draw. Following plots are avialble.
residual
regression
prediction
errors
fdc
murphy
edf
path (str) – folder in which to save the results/plots
show (bool) – whether to show the plots or not
save (bool) – whether to save the plots or not
wandb_config – weights and bias configuration dictionary
dpi (int) – determines resolution of saved figure
Examples
>>> import numpy as np >>> from ai4water.postprocessing import ProcessPredictions >>> true = np.random.random(100) >>> predicted = np.random.random(100) >>> processor = ProcessPredictions("regression", forecast_len=1, ... plots=['prediction', 'regression', 'residual']) >>> processor(true, predicted)
# for postprocessing of classification, we need to set the mode
>>> true = np.random.randint(0, 2, (100, 1)) >>> predicted = np.random.randint(0, 2, (100, 1)) >>> processor = ProcessPredictions("classification") >>> processor(true, predicted)
- __call__(true_outputs, predicted, metrics='minimal', prefix='test', index=None, inputs=None, model=None)[source]
Call self as a function.
- available_plots = ['regression', 'prediction', 'residual', 'murphy', 'fdc', 'errors', 'edf']
- confusion_matrix(true, predicted, prefix=None, cmap='Blues', **kwargs)[source]
plots confusion matrix.
cmap : **kwargs :
any keyword arguments for imshow
- edf_plot(true, predicted, prefix, where, **kwargs)[source]
cumulative distribution function of absolute error between true and predicted.
- Parameters:
true – array like
predicted – array like
prefix –
where –
- plot_results(true, predicted: DataFrame, prefix, where, inputs=None)[source]
- # kwargs can be any/all of followings
# fillstyle: # marker: # linestyle: # markersize: # color:
- process_cls_results(true: ndarray, predicted: ndarray, metrics='minimal', prefix=None, index=None, inputs=None, model=None)[source]
post-processes classification results.
- process_rgr_results(true: ndarray, predicted: ndarray, metrics='minimal', prefix=None, index=None, remove_nans=True, inputs=None)[source]
predicted, true are arrays of shape (examples, outs, forecast_len).
- property quantiles