public class DistanceBased_best
extends java.lang.Object
This class implements a stratified scheme (equal number of examples of each class in each partition) to partition a dataset
Constructor and Description |
---|
DistanceBased_best(java.lang.String source_file,
int np)
It reads the training set and creates the partitions
|
Modifier and Type | Method and Description |
---|---|
void |
calculo_previo_hvdm() |
void |
createPartitionFiles(java.lang.String _carpeta,
java.lang.String _ds)
It creates the files of each training and test partition
|
void |
deletePartitionFiles()
It deletes the files of each training and test partition
|
double |
distancia(int ej1,
int ej2)
Calculates the HVDM distance between two instances
|
int |
evaluationKNNClass(int nvec,
int instancia,
int nClases,
boolean distance,
int[] vecinos,
int clase)
Computes the k nearest neighbors of a given item belonging to a fixed class.
|
Instance[] |
getInstances()
It returns all the original instances
|
java.util.Vector[] |
getPartitions()
It returns the indexes of the original instances in all partitions
|
Instance[] |
getTestPartition(int num)
It returns the test partition specified
|
Instance[] |
getTrainPartition(int num)
It returns the training partition specified
|
public DistanceBased_best(java.lang.String source_file, int np)
It reads the training set and creates the partitions
public Instance[] getTrainPartition(int num)
It returns the training partition specified
num
- number of the partitionpublic Instance[] getTestPartition(int num)
It returns the test partition specified
num
- number of the partitionpublic Instance[] getInstances()
It returns all the original instances
the
- instancespublic java.util.Vector[] getPartitions()
It returns the indexes of the original instances in all partitions
the
- indexes of the instances in each partitionpublic void createPartitionFiles(java.lang.String _carpeta, java.lang.String _ds)
It creates the files of each training and test partition
public void deletePartitionFiles()
It deletes the files of each training and test partition
public int evaluationKNNClass(int nvec, int instancia, int nClases, boolean distance, int[] vecinos, int clase)
Computes the k nearest neighbors of a given item belonging to a fixed class. With that neighbors a suggested class for the item is returned.
nvec
- Number of nearest neighbors that are going to be searchedconj
- Matrix with the data of all the items in the datasetreal
- Matrix with the data associated to the real attributes of the datasetnominal
- Matrix with the data associated to the nominal attributes of the datasetnulos
- Matrix with the data associated to the missing values of the datasetclases
- Array with the associated class for each item in the datasetejemplo
- Array with the data of the specific item in the dataset used
as a reference in the nearest neighbor searchejReal
- Array with the data of the real attributes of the specific item in the datasetejNominal
- Array with the data of the nominal attributes of the specific item in the datasetejNulos
- Array with the data of the missing values of the specific item in the datasetnClases
- Class of the specific item in the datasetdistance
- Kind of distance used in the nearest neighbors computation.
If true the distance used is the euclidean, if false the HVMD distance is usedvecinos
- Array that will have the nearest neighbours id for the current specific itemclase
- Class of the neighbours searched for the itempublic double distancia(int ej1, int ej2)
ej1
- First instanceej1Real
- First instance (Real valued)ej1Nom
- First instance (Nominal valued)ej1Nul
- First instance (Null values)ej2
- Second instanceej2Real
- First instance (Real valued)ej2Nom
- First instance (Nominal valued)ej2Nul
- First instance (Null values)Euc
- Use euclidean distance instead of HVDMpublic void calculo_previo_hvdm()