Loading...

vastorbit.machine_learning.vast.ensemble.GradientBoostingClassifier.score

GradientBoostingClassifier.score(metric: Literal['aic', 'bic', 'accuracy', 'acc', 'balanced_accuracy', 'ba', 'auc', 'roc_auc', 'prc_auc', 'best_cutoff', 'best_threshold', 'false_discovery_rate', 'fdr', 'false_omission_rate', 'for', 'false_negative_rate', 'fnr', 'false_positive_rate', 'fpr', 'recall', 'tpr', 'precision', 'ppv', 'specificity', 'tnr', 'negative_predictive_value', 'npv', 'negative_likelihood_ratio', 'lr-', 'positive_likelihood_ratio', 'lr+', 'diagnostic_odds_ratio', 'dor', 'log_loss', 'logloss', 'f1', 'f1_score', 'mcc', 'bm', 'informedness', 'mk', 'markedness', 'ts', 'csi', 'critical_success_index', 'fowlkes_mallows_index', 'fm', 'prevalence_threshold', 'pm', 'confusion_matrix', 'classification_report'] = 'accuracy', average: Literal[None, 'binary', 'micro', 'macro', 'scores', 'weighted'] = None, pos_label: Annotated[bool | float | str | timedelta | datetime, 'Python Scalar'] | None = None, cutoff: Annotated[int | float | Decimal, 'Python Numbers'] = 0.5, nbins: int = 9999) float | list[float]

Computes the model score.

Parameters:
  • metric (str, optional) –

    The metric used to compute the score.

    • accuracy:

      Accuracy.

      \[Accuracy = \frac{TP + TN}{TP + TN + FP + FN}\]
    • aic:

      Akaike’s Information Criterion

      \[AIC = 2k - 2\ln(\hat{L})\]
    • auc:

      Area Under the Curve (ROC).

      \[AUC = \int_{0}^{1} TPR(FPR) \, dFPR\]
    • ba:

      Balanced Accuracy.

      \[BA = \frac{TPR + TNR}{2}\]
    • best_cutoff:

      Cutoff which optimised the ROC Curve prediction.

    • bic:

      Bayesian Information Criterion

      \[BIC = -2\ln(\hat{L}) + k \ln(n)\]
    • bm:

      Informedness

      \[BM = TPR + TNR - 1\]
    • csi:

      Critical Success Index

      \[index = \frac{TP}{TP + FN + FP}\]
    • f1:

      F1 Score

      \[F_1 Score = 2 \times \frac{Precision \times Recall}{Precision + Recall}\]
    • fdr:

      False Discovery Rate

      \[FDR = 1 - PPV\]
    • fm:

      Fowlkes-Mallows index

      \[FM = \sqrt{PPV * TPR}\]
    • fnr:

      False Negative Rate

      \[FNR = \frac{FN}{FN + TP}\]
    • for:

      False Omission Rate

      \[FOR = 1 - NPV\]
    • fpr:

      False Positive Rate

      \[FPR = \frac{FP}{FP + TN}\]
    • logloss:

      Log Loss.

      \[Loss = -\frac{1}{N} \sum_{i=1}^{N} \left( y_i \log(p_i) + (1 - y_i) \log(1 - p_i) \right)\]
    • lr+:

      Positive Likelihood Ratio.

      \[LR+ = \frac{TPR}{FPR}\]
    • lr-:

      Negative Likelihood Ratio.

      \[LR- = \frac{FNR}{TNR}\]
    • dor:

      Diagnostic Odds Ratio.

      \[DOR = \frac{TP \times TN}{FP \times FN}\]
    • mc:

      Matthews Correlation Coefficient .. math:

      MCC = \frac{TP \times TN - FP \times FN}{\sqrt{(TP + FP)(TP + FN)(TN + FP)(TN + FN)}}
      
    • mk:

      Markedness

      \[MK = PPV + NPV - 1\]
    • npv:

      Negative Predictive Value

      \[NPV = \frac{TN}{TN + FN}\]
    • prc_auc:

      Area Under the Curve (PRC)

      \[AUC = \int_{0}^{1} Precision(Recall) \, dRecall\]
    • precision:

      Precision

      \[Precision = TP / (TP + FP)\]
    • pt:

      Prevalence Threshold.

      \[threshold = \frac{\sqrt{FPR}}{\sqrt{TPR} + \sqrt{FPR}}\]
    • recall:

      Recall.

      \[Recall = \frac{TP}{TP + FN}\]
    • specificity:

      Specificity.

      \[Specificity = \frac{TN}{TN + FP}\]

  • average (str, optional) –

    The method used to compute the final score for multiclass-classification.

    • binary:

      considers one of the classes as positive and use the binary confusion matrix to compute the score.

    • micro:

      positive and negative values globally.

    • macro:

      average of the score of each class.

    • scores:

      scores for all the classes.

    • weighted:

      weighted average of the score of each class.

    If empty, the result will depend on the input metric. Whenever it is possible, the exact score is computed. Otherwise, the behaviour is similar to the ‘scores’ option.

  • pos_label (PythonScalar, optional) – Label to consider as positive. All the other classes will be merged and considered as negative for multiclass classification.

  • cutoff (PythonNumber, optional) – Cutoff for which the tested category is accepted as a prediction.

  • nbins (int, optional) – [Only when method is set to auc|prc_auc|best_cutoff] An integer value that determines the number of decision boundaries. Decision boundaries are set at equally spaced intervals between 0 and 1, inclusive. Greater values for nbins give more precise estimations of the AUC, but can potentially decrease performance. The maximum value is 999,999. If negative, the maximum value is used.

Returns:

score.

Return type:

float

Examples

For this example, we will use the Iris dataset.

import vastorbit.datasets as vod
data = vod.load_iris()
train, test = data.train_test_split(test_size = 0.2)
123
sepallengthcm
Decimal(5, 2)
123
sepalwidthcm
Decimal(5, 2)
123
petallengthcm
Decimal(5, 2)
123
petalwidthcm
Decimal(5, 2)
Abc
species
Varchar(30)
15.13.51.40.2Iris-setosa
24.93.01.40.2Iris-setosa
34.73.21.30.2Iris-setosa
44.63.11.50.2Iris-setosa
55.03.61.40.2Iris-setosa
65.43.91.70.4Iris-setosa
74.63.41.40.3Iris-setosa
85.03.41.50.2Iris-setosa
94.42.91.40.2Iris-setosa
104.93.11.50.1Iris-setosa
115.43.71.50.2Iris-setosa
124.83.41.60.2Iris-setosa
134.83.01.40.1Iris-setosa
144.33.01.10.1Iris-setosa
155.84.01.20.2Iris-setosa
165.74.41.50.4Iris-setosa
175.43.91.30.4Iris-setosa
185.13.51.40.3Iris-setosa
195.73.81.70.3Iris-setosa
205.13.81.50.3Iris-setosa
215.43.41.70.2Iris-setosa
225.13.71.50.4Iris-setosa
234.63.61.00.2Iris-setosa
245.13.31.70.5Iris-setosa
254.83.41.90.2Iris-setosa
265.03.01.60.2Iris-setosa
275.03.41.60.4Iris-setosa
285.23.51.50.2Iris-setosa
295.23.41.40.2Iris-setosa
304.73.21.60.2Iris-setosa
314.83.11.60.2Iris-setosa
325.43.41.50.4Iris-setosa
335.24.11.50.1Iris-setosa
345.54.21.40.2Iris-setosa
354.93.11.50.1Iris-setosa
365.03.21.20.2Iris-setosa
375.53.51.30.2Iris-setosa
384.93.11.50.1Iris-setosa
394.43.01.30.2Iris-setosa
405.13.41.50.2Iris-setosa
415.03.51.30.3Iris-setosa
424.52.31.30.3Iris-setosa
434.43.21.30.2Iris-setosa
445.03.51.60.6Iris-setosa
455.13.81.90.4Iris-setosa
464.83.01.40.3Iris-setosa
475.13.81.60.2Iris-setosa
484.63.21.40.2Iris-setosa
495.33.71.50.2Iris-setosa
505.03.31.40.2Iris-setosa
517.03.24.71.4Iris-versicolor
526.43.24.51.5Iris-versicolor
536.93.14.91.5Iris-versicolor
545.52.34.01.3Iris-versicolor
556.52.84.61.5Iris-versicolor
565.72.84.51.3Iris-versicolor
576.33.34.71.6Iris-versicolor
584.92.43.31.0Iris-versicolor
596.62.94.61.3Iris-versicolor
605.22.73.91.4Iris-versicolor
615.02.03.51.0Iris-versicolor
625.93.04.21.5Iris-versicolor
636.02.24.01.0Iris-versicolor
646.12.94.71.4Iris-versicolor
655.62.93.61.3Iris-versicolor
666.73.14.41.4Iris-versicolor
675.63.04.51.5Iris-versicolor
685.82.74.11.0Iris-versicolor
696.22.24.51.5Iris-versicolor
705.62.53.91.1Iris-versicolor
715.93.24.81.8Iris-versicolor
726.12.84.01.3Iris-versicolor
736.32.54.91.5Iris-versicolor
746.12.84.71.2Iris-versicolor
756.42.94.31.3Iris-versicolor
766.63.04.41.4Iris-versicolor
776.82.84.81.4Iris-versicolor
786.73.05.01.7Iris-versicolor
796.02.94.51.5Iris-versicolor
805.72.63.51.0Iris-versicolor
815.52.43.81.1Iris-versicolor
825.52.43.71.0Iris-versicolor
835.82.73.91.2Iris-versicolor
846.02.75.11.6Iris-versicolor
855.43.04.51.5Iris-versicolor
866.03.44.51.6Iris-versicolor
876.73.14.71.5Iris-versicolor
886.32.34.41.3Iris-versicolor
895.63.04.11.3Iris-versicolor
905.52.54.01.3Iris-versicolor
915.52.64.41.2Iris-versicolor
926.13.04.61.4Iris-versicolor
935.82.64.01.2Iris-versicolor
945.02.33.31.0Iris-versicolor
955.62.74.21.3Iris-versicolor
965.73.04.21.2Iris-versicolor
975.72.94.21.3Iris-versicolor
986.22.94.31.3Iris-versicolor
995.12.53.01.1Iris-versicolor
1005.72.84.11.3Iris-versicolor
Rows: 1-100 | Columns: 5

Let’s import the model:

from vastorbit.machine_learning.vast import NearestCentroid

Then we can create the model:

model = NearestCentroid(p = 2)

We can now fit the model:

model.fit(
    train,
    [
        "SepalLengthCm",
        "SepalWidthCm",
        "PetalLengthCm",
        "PetalWidthCm",
    ],
    "Species",
    test,
)

We can get the score:

model.score()

To get the score of a particular class:

model.score(pos_label= "Iris-setosa")

Important

For this example, a specific model is utilized, and it may not correspond exactly to the model you are working with. To see a comprehensive example specific to your class of interest, please refer to that particular class.