Metrics
The class for testing models and reporting results
A collection of methods to simplify your code.
Targets and Predictions management
Splits tuples of sample and its target in the relative lists |
|
Predicts with your model |
Metrics management
Creates and prints confusion matrix |
|
Gets classification metrics |
|
Gets classification metrics after prediction |
|
Gets classification metrics after training and prediction |
|
Prints metrics |
Model management
Saves model |
|
Resumes model |
Detailed list
- class smltk.metrics.Metrics
- clean_binary_classification(y_test, y_pred)
Transforms the target and prediction in integer 0 and 1
- Arguments:
- y_test (list[]):
list of targets
- y_pred (list[]):
list of predictions
- Returns:
y_test and y_pred with only 0 and 1 values
- create_confusion_matrix(y_test, y_pred, is_test=False)
Creates and prints confusion matrix
- Arguments:
- y_test (list[]):
list of targets
- y_pred (list[]):
list of predictions
- is_test (bool):
default is False
- Returns:
confusion matrix
- fit_exists(model)
Get a boolean True if fit method exists
- Arguments:
- model (obj):
object of your model
- Returns:
boolean
- get_classification_metrics(params={})
Gets classification metrics
- Arguments: params (dict) with the keys below
- model (obj):
object of your model
- X_train (list[]|list[tuple]):
list of samples or list of tuples with sample and its target
- y_train (list[]):
list of targets
- X_test (list[] | list[tuple]):
list of samples or list of tuples with sample and its target
- y_test (list[]):
list of targets
- y_pred (list[]):
list of predictions
- loss (str):
parameter of bias_variance_decomp, default mse
- num_rounds (int):
parameter of bias_variance_decomp, default 200
- random_seed (int):
parameter of bias_variance_decomp, default 3
- Returns:
dictionary with Loss, Bias, Variance, MCC, ROC_AUC, Accuracy, Precision, Recall, Fscore
- is_binary_classification(y_test, y_pred)
Gets if the classification is binary or not
- Arguments:
- y_test (list[]):
list of targets
- y_pred (list[]):
list of predictions
- Returns:
boolean
- modeling(model, X_train, y_train, X_test, y_test)
Gets classification metrics after training and prediction
- Arguments:
- model (obj):
object of your model
- X_train (list[]|list[tuple]):
list of samples or list of tuples with sample and its target
- y_train (list[]):
list of targets
- X_test (list[] | list[tuple]):
list of samples or list of tuples with sample and its target
- y_test (list[]):
list of targets
- Returns:
dictionary with Loss, Bias, Variance, MCC, ROC_AUC, Accuracy, Precision, Recall, Fscore
- predict_exists(model)
Get a boolean True if predict method exists
- Arguments:
- model (obj):
object of your model
- Returns:
boolean
- prediction(model, method, X_test, y_test=[])
Predicts with your model
- Arguments:
- model (obj):
object of your model
- method (str):
name of method
- X_test (list[]|list[tuple]):
list of samples or list of tuples with sample and its target
- y_test (list[]):
list of targets
- Returns:
tuple of list of targets and list of predictions
- print_metrics(metrics)
Prints metrics
- Arguments:
- metrics (dict):
dictionary of metrics with their value
- Returns:
only the print of metrics
- resume_model(filename)
Resumes model
- Arguments:
- filename (str):
pathname and filename where you want to save your model
- Returns:
object of your model
- save_model(model, filename)
Saves model
- Arguments:
- model (obj):
object of your model
- filename (str):
pathname and filename where you want to save your model
- scoring(model, X_test, y_test)
Gets classification metrics after prediction
- Arguments:
- model (obj):
object of your model
- X_test (list[] | list[tuple]):
list of samples or list of tuples with sample and its target
- y_test (list[]):
list of targets
- Returns:
dictionary with Loss, Bias, Variance, MCC, ROC_AUC, Accuracy, Precision, Recall, Fscore
- split_tuples(tuples)
Splits tuples of sample and its target in the relative lists
- Arguments:
- tuples (list[tuple]):
list of tuples with sample and its target
- Returns:
tuple of list of samples and list of targets