KNNEvaluator<T>
Models & Types ยท AiDotNet.SelfSupervisedLearning.Evaluation
k-Nearest Neighbors (k-NN) evaluation for SSL representation quality.
Inheritance: ModelBase<T, Tensor<T>, Tensor<T>> โ KNNEvaluator<T>
Implements: IGeneratedParameterRegistrar<T>
For Beginners
k-NN evaluation is a simple way to test SSL representations without any training. We classify each test sample based on the labels of its k nearest neighbors in the representation space.
How It Works
Why k-NN evaluation?
Typical protocol:
Common settings: k=20, cosine similarity or L2 distance
Constructors
| Constructor | Summary |
|---|---|
KNNEvaluator(INeuralNetwork<T> encoder, int k, bool useCosine, double temperature) |
Initializes a new instance of the KNNEvaluator class. |
Properties
| Property | Summary |
|---|---|
ILossFunction<T> DefaultLossFunction { get; } |
|
int K { get; } |
Gets the k value for k-NN. |
Methods
| Method | Summary |
|---|---|
Dictionary<int, double> EvaluateMultipleK(Tensor<T> testData, int[] testLabels, int[] kValues) |
Evaluates k-NN with different k values. |
IFullModel<T, Tensor<T>, Tensor<T>> WithParameters(Vector<T> parameters) |
|
Tensor<T> Predict(Tensor<T> input) |
|
double Evaluate(Tensor<T> testData, int[] testLabels) |
Evaluates k-NN classification on test data. |
int[] PredictClasses(Tensor<T> testData) |
Predicts classes for multiple test samples. |
void Fit(Tensor<T> trainData, int[] trainLabels) |
Fits the k-NN classifier with training data. |
void Train(Tensor<T> input, Tensor<T> expectedOutput) |