public class KNN
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected static int |
K
Number of neighbor-prototypes to be searched in the KNN.
|
Constructor and Description |
---|
KNN() |
Modifier and Type | Method and Description |
---|---|
static Prototype |
_1nn(Prototype current,
PrototypeSet dataSet)
Implements the 1NN algorithm
|
static int |
classficationAccuracy(PrototypeSet training,
PrototypeSet test)
Informs of the classification accuracy
|
static int |
classficationAccuracy(PrototypeSet training,
PrototypeSet test,
int k)
Informs of the classification accuracy.
|
static int |
classficationAccuracy1NN(PrototypeSet training,
PrototypeSet test)
Informs of the number of prototypes with correct class.
|
static Pair<java.lang.Integer,java.lang.Integer> |
classficationAccuracyAndError1NN(PrototypeSet training,
PrototypeSet test)
Informs of the number of prototypes with correct class.
|
static int[] |
classify(PrototypeSet training,
PrototypeSet test,
int k,
double[][] probabilities)
Informs of the classification done.
|
static int[] |
classify2(PrototypeSet training,
PrototypeSet test,
int k)
Informs of the classification done.
|
static int |
getK()
Returns the current value of K.
|
static Prototype |
getNearest(Prototype current,
PrototypeSet dataSet)
Return the nearest prototype to another in a set.
|
static Prototype |
getNearest(Prototype current,
PrototypeSet dataSet,
boolean isSameClass)
Return the nearest prototype to another with the same of different class
|
static PrototypeSet |
getNearestNeighbors(Prototype current,
PrototypeSet dataSet,
int numberOfNeighbors)
Return some nearest prototypes to another with different class
|
static PrototypeSet |
getNearestNeighborsWithDifferentClassAs(Prototype current,
PrototypeSet dataSet,
int numberOfNeighbors)
Return some nearest prototypes to another with different class
|
static PrototypeSet |
getNearestNeighborsWithSameClassAs(Prototype current,
PrototypeSet dataSet)
Return the nearest prototypes to another with the same class
|
static PrototypeSet |
getNearestNeighborsWithSameClassAs(Prototype current,
PrototypeSet dataSet,
int numberOfNeighbors)
Return some nearest prototypes to another with the same class
|
static Prototype |
getNearestWithDifferentClassAs(Prototype current,
PrototypeSet dataSet)
Return the nearest prototype to another with the same class
|
static Prototype |
getNearestWithSameClassAs(Prototype current,
PrototypeSet dataSet)
Return the nearest prototype to another with the same class.
|
static int |
k()
Returns the current value of K.
|
static PrototypeSet |
knn(Prototype current,
PrototypeSet dataSet)
Implements the KNN algorithm.
|
static PrototypeSet |
knn(Prototype current,
PrototypeSet dataSet,
int k)
Implements the KNN algorithm
|
static void |
setK(int n)
Sets the number of prototypes to be used in the knn algorithm.
|
public static void setK(int n)
n
- Number of prototypespublic static int k()
public static int getK()
public static Prototype _1nn(Prototype current, PrototypeSet dataSet)
current
- Prototype which the algorithm will find its nearest-neighbor.dataSet
- Prototype set in which the algorithm will search.public static PrototypeSet knn(Prototype current, PrototypeSet dataSet, int k)
current
- Prototype which the algorithm will find its nearest-neighbors.dataSet
- Prototype set in which the algorithm will search.k
- The size neighborhood to be returned.public static PrototypeSet knn(Prototype current, PrototypeSet dataSet)
current
- Prototype which the algorithm will find its nearest-neighbors.dataSet
- Prototype set in which the algorithm will search.public static int classficationAccuracy1NN(PrototypeSet training, PrototypeSet test)
training
- Training data prototype settest
- Test data prototype setpublic static Pair<java.lang.Integer,java.lang.Integer> classficationAccuracyAndError1NN(PrototypeSet training, PrototypeSet test)
training
- Training data prototype settest
- Test data prototype setpublic static int classficationAccuracy(PrototypeSet training, PrototypeSet test, int k)
training
- Training data prototype settest
- Test data prototype setk
- Number of prototype-neighbors to be compared with each prototype of test data prototypes.public static int classficationAccuracy(PrototypeSet training, PrototypeSet test)
training
- Training data prototype settest
- Test data prototype setpublic static Prototype getNearest(Prototype current, PrototypeSet dataSet, boolean isSameClass)
current
- Prototype which the algorithm will find its nearest-neighbors.dataSet
- Prototype set in which the algorithm will search.isSameClass
- Must return a prototype with the same class as current?public static Prototype getNearest(Prototype current, PrototypeSet dataSet)
current
- Prototype which the algorithm will find its nearest-neighbors.dataSet
- Prototype set in which the algorithm will search.public static Prototype getNearestWithSameClassAs(Prototype current, PrototypeSet dataSet)
current
- Prototype which the algorithm will find its nearest-neighbor.dataSet
- Prototype set in which the algorithm will search.public static PrototypeSet getNearestNeighborsWithSameClassAs(Prototype current, PrototypeSet dataSet)
current
- Prototype which the algorithm will find its nearest-neighbor.dataSet
- Prototype set in which the algorithm will search.public static PrototypeSet getNearestNeighborsWithSameClassAs(Prototype current, PrototypeSet dataSet, int numberOfNeighbors)
current
- Prototype which the algorithm will find its nearest-neighbor.dataSet
- Prototype set in which the algorithm will search.numberOfNeighbors
- Number of neighbors to be returned.public static PrototypeSet getNearestNeighborsWithDifferentClassAs(Prototype current, PrototypeSet dataSet, int numberOfNeighbors)
current
- Prototype which the algorithm will find its nearest-neighbor.dataSet
- Prototype set in which the algorithm will search.numberOfNeighbors
- Number of neighbors to be returned.public static Prototype getNearestWithDifferentClassAs(Prototype current, PrototypeSet dataSet)
current
- Prototype which the algorithm will find its nearest-neighbor.dataSet
- Prototype set in which the algorithm will search.public static PrototypeSet getNearestNeighbors(Prototype current, PrototypeSet dataSet, int numberOfNeighbors)
current
- Prototype which the algorithm will find its nearest-neighbor.dataSet
- Prototype set in which the algorithm will search.numberOfNeighbors
- Number of neighbors to be returned.public static int[] classify(PrototypeSet training, PrototypeSet test, int k, double[][] probabilities)
training
- Training data prototype settest
- Test data prototype setk
- Number of prototype-neighbors to be compared with each prototype of test data prototypes.probabilities
- classes probabilities for the each test instance.public static int[] classify2(PrototypeSet training, PrototypeSet test, int k)
training
- Training data prototype settest
- Test data prototype setk
- Number of prototype-neighbors to be compared with each prototype of test data prototypes.