Package smile.validation
Record Class ClassificationValidation<M>
java.lang.Object
java.lang.Record
smile.validation.ClassificationValidation<M>
- Type Parameters:
M
- The model type.- Record Components:
model
- The classification model.truth
- The ground true of validation data.prediction
- The model prediction.posteriori
- The posteriori probability of prediction if the model is a soft classifier.confusion
- The confusion matrix.metrics
- The classification metrics.
- All Implemented Interfaces:
Serializable
public record ClassificationValidation<M>(M model, int[] truth, int[] prediction, double[][] posteriori, ConfusionMatrix confusion, ClassificationMetrics metrics)
extends Record
implements Serializable
Classification model validation results.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionClassificationValidation
(M model, double fitTime, double scoreTime, int[] truth, int[] prediction) Constructor.ClassificationValidation
(M model, double fitTime, double scoreTime, int[] truth, int[] prediction, double[][] posteriori) Constructor of soft classifier validation.ClassificationValidation
(M model, int[] truth, int[] prediction, double[][] posteriori, ConfusionMatrix confusion, ClassificationMetrics metrics) Creates an instance of aClassificationValidation
record class. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of theconfusion
record component.final boolean
Indicates whether some other object is "equal to" this one.final int
hashCode()
Returns a hash code value for this object.metrics()
Returns the value of themetrics
record component.model()
Returns the value of themodel
record component.static <M extends DataFrameClassifier>
ClassificationValidation<M> Trains and validates a model on a train/validation split.static <M extends DataFrameClassifier>
ClassificationValidations<M> Trains and validates a model on multiple train/validation split.static <T,
M extends Classifier<T>>
ClassificationValidations<M> of
(Bag[] bags, T[] x, int[] y, BiFunction<T[], int[], M> trainer) Trains and validates a model on multiple train/validation split.static <T,
M extends Classifier<T>>
ClassificationValidation<M> of
(T[] x, int[] y, T[] testx, int[] testy, BiFunction<T[], int[], M> trainer) Trains and validates a model on a train/validation split.double[][]
Returns the value of theposteriori
record component.int[]
Returns the value of theprediction
record component.toString()
Returns a string representation of this record class.int[]
truth()
Returns the value of thetruth
record component.
-
Constructor Details
-
ClassificationValidation
public ClassificationValidation(M model, double fitTime, double scoreTime, int[] truth, int[] prediction) Constructor.- Parameters:
model
- the model.fitTime
- the time in milliseconds of fitting the model.scoreTime
- the time in milliseconds of scoring the validation data.truth
- the ground truth.prediction
- the predictions.
-
ClassificationValidation
public ClassificationValidation(M model, double fitTime, double scoreTime, int[] truth, int[] prediction, double[][] posteriori) Constructor of soft classifier validation.- Parameters:
model
- the model.fitTime
- the time in milliseconds of fitting the model.scoreTime
- the time in milliseconds of scoring the validation data.truth
- the ground truth.prediction
- the predictions.posteriori
- the posteriori probabilities of predictions.
-
ClassificationValidation
public ClassificationValidation(M model, int[] truth, int[] prediction, double[][] posteriori, ConfusionMatrix confusion, ClassificationMetrics metrics) Creates an instance of aClassificationValidation
record class.- Parameters:
model
- the value for themodel
record componenttruth
- the value for thetruth
record componentprediction
- the value for theprediction
record componentposteriori
- the value for theposteriori
record componentconfusion
- the value for theconfusion
record componentmetrics
- the value for themetrics
record component
-
-
Method Details
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
of
public static <T,M extends Classifier<T>> ClassificationValidation<M> of(T[] x, int[] y, T[] testx, int[] testy, BiFunction<T[], int[], M> trainer) Trains and validates a model on a train/validation split.- Type Parameters:
T
- the data type of samples.M
- the model type.- Parameters:
x
- the training data.y
- the class labels of training data.testx
- the validation data.testy
- the class labels of validation data.trainer
- the lambda to train the model.- Returns:
- the validation results.
-
of
public static <T,M extends Classifier<T>> ClassificationValidations<M> of(Bag[] bags, T[] x, int[] y, BiFunction<T[], int[], M> trainer) Trains and validates a model on multiple train/validation split.- Type Parameters:
T
- the data type of samples.M
- the model type.- Parameters:
bags
- the data splits.x
- the training data.y
- the class labels.trainer
- the lambda to train the model.- Returns:
- the validation results.
-
of
public static <M extends DataFrameClassifier> ClassificationValidation<M> of(Formula formula, DataFrame train, DataFrame test, BiFunction<Formula, DataFrame, M> trainer) Trains and validates a model on a train/validation split.- Type Parameters:
M
- the model type.- Parameters:
formula
- the model formula.train
- the training data.test
- the validation data.trainer
- the lambda to train the model.- Returns:
- the validation results.
-
of
public static <M extends DataFrameClassifier> ClassificationValidations<M> of(Bag[] bags, Formula formula, DataFrame data, BiFunction<Formula, DataFrame, M> trainer) Trains and validates a model on multiple train/validation split.- Type Parameters:
M
- the model type.- Parameters:
bags
- the data splits.formula
- the model formula.data
- the data.trainer
- the lambda to train the model.- Returns:
- the validation results.
-
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object)
. -
model
Returns the value of themodel
record component.- Returns:
- the value of the
model
record component
-
truth
public int[] truth()Returns the value of thetruth
record component.- Returns:
- the value of the
truth
record component
-
prediction
public int[] prediction()Returns the value of theprediction
record component.- Returns:
- the value of the
prediction
record component
-
posteriori
public double[][] posteriori()Returns the value of theposteriori
record component.- Returns:
- the value of the
posteriori
record component
-
confusion
Returns the value of theconfusion
record component.- Returns:
- the value of the
confusion
record component
-
metrics
Returns the value of themetrics
record component.- Returns:
- the value of the
metrics
record component
-