public class Dataset
{
int noOfRecords;
int noOfAttributes;
String[][] dataSet;
String attributeInformation[][];
String[] minValues;
String[] maxValues;
String[][] attributeValues;
int noOfClasses;
String[] classLevels;
int noOfDifferentAttributeValues[];
String[][] normalizedDataSet;
String[][] normalizedAttributeValues;
String valuesOfAttributes[];
String changePoints[][];
double informationGain[];
String dominentClassLabel;
Dataset(String dataFileName,String dataFileDlimiter,String attributeFileName,String attributeFileDlimiter,String type)
{
findNoOfRecords(dataFileName);
findNoOfAttributes(dataFileName,dataFileDlimiter);
insertRecordsInTwoDimentionalArray(dataFileName,dataFileDlimiter);
if(type.equals("training"))
{
insertAttributeInformationsInTwoDimentionalArray(attributeFileName,attributeFileDlimiter);
findMinValues();
findMaxValues();
storeSortedUniqueAttributeValues();
findNoOfDifferentAttributeValues();
getNumberOfClasses();
findClassLevels();
findDominantClassLevel();
changePoints=findChangePoints();
informationGain=calculateInformationGain();
}
}
public void findNoOfRecords(String dataFileName)
{
FileUtil dataFileOriginal=new FileUtil(dataFileName);
dataFileOriginal.readFile();
noOfRecords=dataFileOriginal.noOfLines()-1;
}
public void showNoOfRecords()
{
System.out.println("noOfRecords="+noOfRecords);//for testing
}
public void findNoOfAttributes(String dataFileName,String dataFileDlimiter)
{
FileUtil dataFileOriginal=new FileUtil(dataFileName);
dataFileOriginal.readFile();
dataFileOriginal.readFile();
String firstLine=dataFileOriginal.readLine(1,noOfRecords);
IOUtil FL=new IOUtil(firstLine);
FL.init_delim(dataFileDlimiter);
noOfAttributes=0;
while(FL.getNext()!=null)
{
noOfAttributes++;
}
}
public void showNoOfAttributes()
{
System.out.println("noOfAttributes="+noOfAttributes);//for testing
}
public void insertRecordsInTwoDimentionalArray(String dataFileName,String dataFileDlimiter)
{
FileUtil dataFileOriginal=new FileUtil(dataFileName);
dataSet=new String[noOfRecords][noOfAttributes];
for(int outerLoopCounter=0;outerLoopCounter<=noOfRecords-1;outerLoopCounter++)
{
//System.out.println(outerLoopCounter);//for testing
String record=dataFileOriginal.readLine(outerLoopCounter+1,noOfRecords);
//System.out.println(record);//for testing
IOUtil IO=new IOUtil(record);
IO.init_delim(dataFileDlimiter);
for(int innerLoopCounter=0;innerLoopCounter<=noOfAttributes-1;innerLoopCounter++)
{
dataSet[outerLoopCounter][innerLoopCounter]=IO.getNext();
}
}
}
public void showDataset()
{
for(int outerLoopCounter=0;outerLoopCounter<=noOfRecords-1;outerLoopCounter++)
{
for(int innerLoopCounter=0;innerLoopCounter<=noOfAttributes-1;innerLoopCounter++)
{
System.out.print(dataSet[outerLoopCounter][innerLoopCounter]+" ");
}
System.out.println("");
}
}
public void insertAttributeInformationsInTwoDimentionalArray(String attributeFileName,String attributeFileDlimiter)
{
FileUtil attributeFileOriginal=new FileUtil(attributeFileName);
attributeFileOriginal.readFile();
int noOfLines=attributeFileOriginal.noOfLines()-1;
attributeFileOriginal.readFile();
String attributeFirstLine=attributeFileOriginal.readLine(1,noOfLines);
IOUtil FL2=new IOUtil(attributeFirstLine);
FL2.init_delim(attributeFileDlimiter);
attributeInformation=new String[2][noOfAttributes];
for(int outerLoopCounter=0;outerLoopCounter<=1;outerLoopCounter++)
{
String record=attributeFileOriginal.readLine(outerLoopCounter+1,noOfLines);
IOUtil IO=new IOUtil(record);
IO.init_delim(attributeFileDlimiter);
for(int innerLoopCounter=0;innerLoopCounter<=noOfAttributes-1;innerLoopCounter++)
{
attributeInformation[outerLoopCounter][innerLoopCounter]=IO.getNext();
}
}
}
public void showAttributeInformation()
{
for(int outerLoopCounter=0;outerLoopCounter<=2-1;outerLoopCounter++)
{
for(int innerLoopCounter=0;innerLoopCounter<=noOfAttributes-1;innerLoopCounter++)
{
System.out.print(attributeInformation[outerLoopCounter][innerLoopCounter]+" ");
}
System.out.println("");
}
}
public void findMinValues()
{
minValues=new String[noOfAttributes];
for(int loopCounter=0;loopCounter<=noOfAttributes-1;loopCounter++)
{
if(attributeInformation[1][loopCounter].equals("Float")||attributeInformation[1][loopCounter].equals("Integer"))
{
int counter=-1;
do
{
counter++;
if(!dataSet[counter][loopCounter].equals("?"))
break;
}while(counter<(noOfRecords-1));
minValues[loopCounter]=dataSet[counter][loopCounter];
for(int loopCounter1=0;loopCounter1<=noOfRecords-1;loopCounter1++)
{
if(!dataSet[loopCounter1][loopCounter].equals("?"))
{
if(Double.parseDouble(minValues[loopCounter])>Double.parseDouble(dataSet[loopCounter1][loopCounter]))
{
minValues[loopCounter]=dataSet[loopCounter1][loopCounter];
}
}
}
}
}
}
public void showMinValues()
{
for(int loopCounter=0;loopCounter<=noOfAttributes-1;loopCounter++)
{
if(attributeInformation[1][loopCounter].equals("Float")||attributeInformation[1][loopCounter].equals("Integer"))
{
System.out.println("minValues["+loopCounter+"]="+minValues[loopCounter]);
}
}
}
public void findMaxValues()
{
maxValues=new String[noOfAttributes];
for(int loopCounter=0;loopCounter<=noOfAttributes-1;loopCounter++)
{
if(attributeInformation[1][loopCounter].equals("Float")||attributeInformation[1][loopCounter].equals("Integer"))
{
int counter=-1;
do
{
counter++;
if(!dataSet[counter][loopCounter].equals("?"))
break;
}while(counter<(noOfRecords-1));
maxValues[loopCounter]=dataSet[counter][loopCounter];
for(int loopCounter1=0;loopCounter1<=noOfRecords-1;loopCounter1++)
{
if(!dataSet[loopCounter1][loopCounter].equals("?"))
{
if(Double.parseDouble(maxValues[loopCounter])<Double.parseDouble(dataSet[loopCounter1][loopCounter]))
{
maxValues[loopCounter]=dataSet[loopCounter1][loopCounter];
}
}
}
}
}
}
public void showMaxValues()
{
for(int loopCounter=0;loopCounter<=noOfAttributes-1;loopCounter++)
{
if(attributeInformation[1][loopCounter].equals("Float")||attributeInformation[1][loopCounter].equals("Integer"))
{
System.out.println("maxValues["+loopCounter+"]="+maxValues[loopCounter]);
}
}
}
public void storeSortedUniqueAttributeValues()
{
attributeValues=new String[noOfAttributes][noOfRecords+1];
String Temp[]=new String[noOfRecords];
boolean flag[]=new boolean[noOfRecords];
for(int outerLoopCounter=0;outerLoopCounter<=noOfAttributes-1;outerLoopCounter++)
{
if(attributeInformation[1][outerLoopCounter].equals("Float")||attributeInformation[1][outerLoopCounter].equals("Integer"))
{
String Temp2[]=new String[noOfRecords+1];
for(int innerLoopCounter=0;innerLoopCounter<=noOfRecords-1;innerLoopCounter++)
{
Temp[innerLoopCounter]=dataSet[innerLoopCounter][outerLoopCounter];//to store attributes values
if(!Temp[innerLoopCounter].equals("?"))
flag[innerLoopCounter]=true;
else
flag[innerLoopCounter]=false;
}//end of for
boolean flag1=false;
int counter=0;
do
{
flag1=false;
String lowestAvaliableValue=maxValues[outerLoopCounter];
for(int innerLoopCounter=0;innerLoopCounter<=noOfRecords-1;innerLoopCounter++)
{
if(flag[innerLoopCounter])
{
if(Double.parseDouble(lowestAvaliableValue)>Double.parseDouble(Temp[innerLoopCounter]))
{
lowestAvaliableValue=Temp[innerLoopCounter];
flag1=true;
}
}
}
Temp2[counter]=lowestAvaliableValue;
counter++;
for(int innerLoopCounter=0;innerLoopCounter<=noOfRecords-1;innerLoopCounter++)
{
if(lowestAvaliableValue.equals(Temp[innerLoopCounter]))
{
flag[innerLoopCounter]=false;
}
}
}while(flag1);
attributeValues[outerLoopCounter]=Temp2;
}
if(attributeInformation[1][outerLoopCounter].equals("String")||attributeInformation[1][outerLoopCounter].equals("Binary"))
{
String Temp2[]=new String[noOfRecords+1];
for(int innerLoopCounter=0;innerLoopCounter<=noOfRecords-1;innerLoopCounter++)
{
Temp[innerLoopCounter]=dataSet[innerLoopCounter][outerLoopCounter];
if(!Temp[innerLoopCounter].equals("?"))
flag[innerLoopCounter]=true;
else
flag[innerLoopCounter]=false;
}
boolean flag1=false;
int counter=0;
do
{
flag1=false;
int innerLoopCounter1=0;
String firstAvaliableValue="";
do
{
firstAvaliableValue=Temp[innerLoopCounter1];
innerLoopCounter1++;
if(!firstAvaliableValue.equals("?"))
break;
}while(innerLoopCounter1<=(noOfRecords-1));
for(int innerLoopCounter=0;innerLoopCounter<=noOfRecords-1;innerLoopCounter++)
{
if(flag[innerLoopCounter])
{
firstAvaliableValue=Temp[innerLoopCounter];
flag1=true;
break;
}
}
if(flag1)
{
Temp2[counter]=firstAvaliableValue;
counter++;
for(int innerLoopCounter=0;innerLoopCounter<=noOfRecords-1;innerLoopCounter++)
{
if(firstAvaliableValue.equals(Temp[innerLoopCounter]))
{
flag[innerLoopCounter]=false;
}
}
}
}while(flag1);
attributeValues[outerLoopCounter]=Temp2;
}
}
}
public void findNoOfDifferentAttributeValues()
{
noOfDifferentAttributeValues=new int[noOfAttributes];
for(int outerLoopCounter=0;outerLoopCounter<=noOfAttributes-1;outerLoopCounter++)
{
int counter=0;
for(int innerLoopCounter=0;innerLoopCounter<=noOfRecords;innerLoopCounter++)
{
if(attributeValues[outerLoopCounter][innerLoopCounter]==null)
{
counter=innerLoopCounter;
break;
}
}
noOfDifferentAttributeValues[outerLoopCounter]=counter;
}
}
public void showNoOfDifferentAttributeValues()
{
for(int counter1=0;counter1<=noOfAttributes-1;counter1++)
{
System.out.println("Number of different values for "+counter1+"th Attribute="+noOfDifferentAttributeValues[counter1]);
}
}
public void showSorted()
{
System.out.println("Sorted Attributes Values");
for(int counter1=0;counter1<=noOfAttributes-1;counter1++)
{
System.out.println("Attribute Number="+counter1);
for(int counter2=0;counter2<=noOfRecords-1;counter2++)
{
if(attributeValues[counter1][counter2]==null)
break;
else
System.out.print(attributeValues[counter1][counter2]);
System.out.print(",");
}
System.out.println("");
}
}
public void getNumberOfClasses()
{
noOfClasses=0;
for(int counter=0;counter<=noOfRecords-1;counter++)
{
if(attributeValues[noOfAttributes-1][counter]!=null)
noOfClasses++;
else
break;
}
}
public void showNoOfClasses()
{
System.out.println("No of Classes="+noOfClasses);
}
public void findClassLevels()
{
classLevels=new String[noOfClasses];
for(int counter=0;counter<=noOfClasses-1;counter++)
{
classLevels[counter]=attributeValues[noOfAttributes-1][counter];
}
}
public void showClassLevels()
{
System.out.println("Class Levels");
for(int i=0;i<noOfClasses;i++)
System.out.println(classLevels[i]);
}
public void findDominantClassLevel()
{
int classCounter[]=new int[noOfClasses];
for(int recordNo=0;recordNo<=noOfRecords-1;recordNo++)
{
for(int classNo=0;classNo<=noOfClasses-1;classNo++)
{
if(dataSet[recordNo][noOfAttributes-1].equals(classLevels[classNo]))
{
classCounter[classNo]++;
break;
}
}
}
int maxClassCounter=0;
for(int classNo=0;classNo<=noOfClasses-1;classNo++)
{
if(classCounter[classNo]>maxClassCounter)
{
maxClassCounter=classCounter[classNo];
dominentClassLabel=classLevels[classNo];
}
}
}
public void showValuesOfAttributes()
{
for(int loopCounter=0;loopCounter<=noOfAttributes-1;loopCounter++)
{
System.out.println("Attribute["+loopCounter+"]="+valuesOfAttributes[loopCounter]);//for testing
}
}
public String[][] findChangePoints()
{
String changePoints[][]=new String[noOfAttributes][];
for(int outerloopCounter=0;outerloopCounter<=noOfAttributes-2;outerloopCounter++)
{
if(attributeInformation[1][outerloopCounter].equals("Float")||attributeInformation[1][outerloopCounter].equals("Integer"))
{
String sortedAttributeAndClass[][]=sortRecordsAsPerAttributeValue(outerloopCounter,noOfAttributes,dataSet,attributeValues[outerloopCounter]);
int noOfChangePoints=findNoOfChangePoints(sortedAttributeAndClass);
//System.out.println("noOfChangePoints"+noOfChangePoints);//for testing
changePoints[outerloopCounter]=findArrayOfChangePoints(sortedAttributeAndClass,noOfChangePoints);
}
}
return changePoints;
}
String [][] sortRecordsAsPerAttributeValue(int attributeNo,int numberOfAttribute,String dataSet[][],String attributeValues[])
{
String sortedAttributeAndClass[][]=new String[2][dataSet.length];
boolean flag[]=new boolean[dataSet.length];
int counter=0;
for(int outerloopCounter=0;outerloopCounter<=attributeValues.length-1;outerloopCounter++)
{
for(int innerloopCounter=0;innerloopCounter<=dataSet.length-1;innerloopCounter++)
{
if(dataSet[innerloopCounter][attributeNo].equals(attributeValues[outerloopCounter])&&!flag[innerloopCounter])
{
sortedAttributeAndClass[0][counter]=dataSet[innerloopCounter][attributeNo];
sortedAttributeAndClass[1][counter]=dataSet[innerloopCounter][numberOfAttribute-1];
flag[innerloopCounter]=true;
counter++;
}
}
}
counter=0;
boolean flag2=false;
for(int loopCounter=0;loopCounter<=dataSet.length-1;loopCounter++)
{
counter++;
if(sortedAttributeAndClass[0][loopCounter]==null)
{
flag2=true;
break;
}
}
String sortedAttributeAndClass2[][];
if(flag2)
{
sortedAttributeAndClass2=new String[2][counter-1];
}
else
{
sortedAttributeAndClass2=new String[2][counter];
}
for(int loopCounter=0;loopCounter<=sortedAttributeAndClass2[0].length-1;loopCounter++)
{
sortedAttributeAndClass2[0][loopCounter]=sortedAttributeAndClass[0][loopCounter];
sortedAttributeAndClass2[1][loopCounter]=sortedAttributeAndClass[1][loopCounter];
}
return sortedAttributeAndClass2;
}
int findNoOfChangePoints(String sortedAttributeAndClass[][])
{
int noOfChangePoints=0;
String classLabel_1=sortedAttributeAndClass[1][0];
String attributevalue_1=sortedAttributeAndClass[0][0];
for(int loopCounter=1;loopCounter<=sortedAttributeAndClass[0].length-1;loopCounter++)
{
String classLabel_2=sortedAttributeAndClass[1][loopCounter];
String attributevalue_2=sortedAttributeAndClass[0][loopCounter];
if(!classLabel_1.equals(classLabel_2))
{
if(!attributevalue_1.equals(attributevalue_2))
{
noOfChangePoints=noOfChangePoints+1;
}
}
attributevalue_1=sortedAttributeAndClass[0][loopCounter];
classLabel_1=sortedAttributeAndClass[1][loopCounter];
}
noOfChangePoints=noOfChangePoints+2;
//}
return noOfChangePoints;
}
String[] findArrayOfChangePoints(String sortedAttributeAndClass[][],int noOfChangePoints)
{
String arrayOfChangePointsWithDuplicateValues[]=new String[noOfChangePoints];
arrayOfChangePointsWithDuplicateValues[0]=sortedAttributeAndClass[0][0];
int counter=1;
String attributevalue_1=sortedAttributeAndClass[0][0];
String classLabel_1=sortedAttributeAndClass[1][0];
for(int loopCounter=1;loopCounter<=sortedAttributeAndClass[0].length-1;loopCounter++)
{
String classLabel_2=sortedAttributeAndClass[1][loopCounter];
String attributevalue_2=sortedAttributeAndClass[0][loopCounter];
if(!classLabel_1.equals(classLabel_2))
{
if(!attributevalue_1.equals(attributevalue_2))
{
double a=Double.valueOf(attributevalue_1);
double b=Double.valueOf(attributevalue_2);
double c=((a+b)/2.0);
arrayOfChangePointsWithDuplicateValues[counter]=Double.toString(c);
//arrayOfChangePointsWithDuplicateValues[counter]=Double.toString(Double.valueOf(attributevalue_1)+Double.valueOf(attributevalue_2)/2.0);
//System.out.println(arrayOfChangePointsWithDuplicateValues[counter]);//for testing
counter++;
}//end of if
}//end of if
attributevalue_1=sortedAttributeAndClass[0][loopCounter];
classLabel_1=sortedAttributeAndClass[1][loopCounter];
}//end of for
arrayOfChangePointsWithDuplicateValues[counter]=sortedAttributeAndClass[0][sortedAttributeAndClass[0].length-1];
/*if(!attributevalue.equals(sortedAttributeAndClass[0][sortedAttributeAndClass[0].length-1]))
{
arrayOfChangePoints[counter]=sortedAttributeAndClass[0][sortedAttributeAndClass[0].length-1];
}//end of if*/
/*for(int loopCounter=0;loopCounter<=arrayOfChangePointsWithDuplicateValues.length-1;loopCounter++)
{
System.out.println(arrayOfChangePointsWithDuplicateValues[loopCounter]);//for testing
}//end of for*/
//to eliminate duplicate values
noOfChangePoints=1;
String point=arrayOfChangePointsWithDuplicateValues[0];
for(int loopCounter=1;loopCounter<=arrayOfChangePointsWithDuplicateValues.length-1;loopCounter++)
{
if(!point.equals(arrayOfChangePointsWithDuplicateValues[loopCounter]))
{
noOfChangePoints++;
point=arrayOfChangePointsWithDuplicateValues[loopCounter];
}//end of if
}//end of for
//System.out.println("noOfChangePoints="+noOfChangePoints);//for testing
String arrayOfChangePoints[]=new String[noOfChangePoints];
point=arrayOfChangePointsWithDuplicateValues[0];
arrayOfChangePoints[0]=point;
counter=1;
for(int loopCounter=1;loopCounter<=arrayOfChangePointsWithDuplicateValues.length-1;loopCounter++)
{
if(!point.equals(arrayOfChangePointsWithDuplicateValues[loopCounter]))
{
arrayOfChangePoints[counter]=arrayOfChangePointsWithDuplicateValues[loopCounter];
point=arrayOfChangePointsWithDuplicateValues[loopCounter];
counter++;
}//end of if
}//end of for
return arrayOfChangePoints;
}
public double[] calculateInformationGain()
{
double entropy[]=calculateEntropy();
double informationGain[]=new double[noOfAttributes-1];
for(int attributeNo=0;attributeNo<=noOfAttributes-2;attributeNo++)
{
informationGain[attributeNo]=entropy[noOfAttributes-1]-entropy[attributeNo];
}
return informationGain;
}
public double[] calculateEntropy()
{
double classEntropy=calculateEntropyOfClass();
double entropy[]=new double[noOfAttributes];
entropy[noOfAttributes-1]=classEntropy;
for(int attributeNo=0;attributeNo<=noOfAttributes-2;attributeNo++)
{
String attributesType=attributeInformation[1][attributeNo];
if(attributesType.equals("Integer")||attributesType.equals("Float"))
{
entropy[attributeNo]=calculateEntropyOfContinuousAttribute(attributeNo);
}
else if(attributesType.equals("Binary")||attributesType.equals("String"))
{
entropy[attributeNo]=calculateEntropyOfCategoricalAttribute(attributeNo);
}
}
return entropy;
}
public double calculateEntropyOfClass()
{
double probability_of_class[]=new double[noOfClasses];
double classEntropy=0.0;
for(int loopCounter=0;loopCounter<=noOfClasses-1;loopCounter++)
{
probability_of_class[loopCounter]=calculateProbabilityOfClass(classLevels[loopCounter]);
classEntropy=classEntropy-probability_of_class[loopCounter]*Math.log(probability_of_class[loopCounter])/Math.log(2);
}
return classEntropy;
}
public double calculateProbabilityOfClass(String classLabel)
{
double classProbability=0.0;
int classCount=0;
for(int loopCounter=0;loopCounter<=noOfRecords-1;loopCounter++)
{
if(classLabel.equals(dataSet[loopCounter][noOfAttributes-1]))
classCount++;
}
classProbability=(double)classCount/noOfRecords;
return classProbability;
}
public double calculateEntropyOfContinuousAttribute(int attributeNo)
{
double average_interval_and_class_Entropy=0.0;
int noOfIntervals=changePoints[attributeNo].length-1;
for(int intervalNo=0;intervalNo<=noOfIntervals-1;intervalNo++)
{
double minValue=Double.valueOf(changePoints[attributeNo][intervalNo]);
double maxValue=Double.valueOf(changePoints[attributeNo][intervalNo+1]);
double interval_and_class_Entropy=0.0;
if(intervalNo==0)
{
for(int classNo=0;classNo<=noOfClasses-1;classNo++)
{
double probability_of_interval_and_class=calculateProbabilityOfFirstIntervalAndClass(classLevels[classNo],minValue,maxValue,attributeNo);
if(probability_of_interval_and_class>0.0)
interval_and_class_Entropy=interval_and_class_Entropy-probability_of_interval_and_class*Math.log(probability_of_interval_and_class)/Math.log(2);
}
int interval_value_count=calculateFirstIntervalValueCount(minValue,maxValue,attributeNo);
average_interval_and_class_Entropy=average_interval_and_class_Entropy+(double)interval_value_count/noOfRecords*interval_and_class_Entropy;
}
else
{
for(int classNo=0;classNo<=noOfClasses-1;classNo++)
{
double probability_of_interval_and_class=calculateProbabilityOfIntervalAndClass(classLevels[classNo],minValue,maxValue,attributeNo);
if(probability_of_interval_and_class>0.0)
interval_and_class_Entropy=interval_and_class_Entropy-probability_of_interval_and_class*Math.log(probability_of_interval_and_class)/Math.log(2);
}
int interval_value_count=calculateIntervalValueCount(minValue,maxValue,attributeNo);
average_interval_and_class_Entropy=average_interval_and_class_Entropy+(double)interval_value_count/noOfRecords*interval_and_class_Entropy;
}
}
return average_interval_and_class_Entropy;
}
public double calculateEntropyOfCategoricalAttribute(int attributeNo)
{
double average_attribute_and_class_Entropy=0.0;
for(int attributeValueNo=0;attributeValueNo<=noOfDifferentAttributeValues[attributeNo]-1;attributeValueNo++)
{
double attribute_and_class_Entropy=0.0;
for(int classNo=0;classNo<=noOfClasses-1;classNo++)
{
double probability_of_attribute_and_class=calculateProbabilityOfAttributeAndClass(classLevels[classNo],attributeValues[attributeNo][attributeValueNo],attributeNo);
if(probability_of_attribute_and_class>0.0)
attribute_and_class_Entropy=attribute_and_class_Entropy-probability_of_attribute_and_class*Math.log(probability_of_attribute_and_class)/Math.log(2);
}
int attribute_value_count=calculateAtttributeValueCount(attributeValues[attributeNo][attributeValueNo],attributeNo);
average_attribute_and_class_Entropy=average_attribute_and_class_Entropy+(double)attribute_value_count/noOfRecords*attribute_and_class_Entropy;
}
return average_attribute_and_class_Entropy;
}
public double calculateProbabilityOfFirstIntervalAndClass(String classLabel,double min,double max,int attributeNo)
{
double intervalAndClassProbability=0.0;
int intervalAndClassCount=0;
for(int loopCounter=0;loopCounter<=noOfRecords-1;loopCounter++)
{
if(!dataSet[loopCounter][attributeNo].equals("?"))
{
if(classLabel.equals(dataSet[loopCounter][noOfAttributes-1])&&min<=Double.valueOf(dataSet[loopCounter][attributeNo])&&max>=Double.valueOf(dataSet[loopCounter][attributeNo]))
{
intervalAndClassCount++;
}
}
}
intervalAndClassProbability=(double)intervalAndClassCount/noOfRecords;
return intervalAndClassProbability;
}
public double calculateProbabilityOfIntervalAndClass(String classLabel,double min,double max,int attributeNo)
{
double intervalAndClassProbability=0.0;
int intervalAndClassCount=0;
for(int loopCounter=0;loopCounter<=noOfRecords-1;loopCounter++)
{
if(!dataSet[loopCounter][attributeNo].equals("?"))
{
if(classLabel.equals(dataSet[loopCounter][noOfAttributes-1])&&min<Double.valueOf(dataSet[loopCounter][attributeNo])&&max>=Double.valueOf(dataSet[loopCounter][attributeNo]))
{
intervalAndClassCount++;
}
}//end of if
}//end of for
intervalAndClassProbability=(double)intervalAndClassCount/noOfRecords;
return intervalAndClassProbability;
}
public double calculateProbabilityOfAttributeAndClass(String classLabel,String attributeValue,int attributeNo)
{
double attributeAndClassProbability=0.0;
int attributeAndClassCount=0;
for(int loopCounter=0;loopCounter<=noOfRecords-1;loopCounter++)
{
if(classLabel.equals(dataSet[loopCounter][noOfAttributes-1])&&attributeValue.equals(dataSet[loopCounter][attributeNo]))
attributeAndClassCount++;
}
attributeAndClassProbability=(double)attributeAndClassCount/noOfRecords;
return attributeAndClassProbability;
}
public int calculateAtttributeValueCount(String attributeValue,int attributeNo)
{
int attribute_value_count=0;
for(int loopCounter=0;loopCounter<=noOfRecords-1;loopCounter++)
{
if(attributeValue.equals(dataSet[loopCounter][attributeNo]))
attribute_value_count++;
}
return attribute_value_count;
}
public int calculateFirstIntervalValueCount(double min,double max,int attributeNo)
{
int interval_value_count=0;
for(int loopCounter=0;loopCounter<=noOfRecords-1;loopCounter++)
{
if(!dataSet[loopCounter][attributeNo].equals("?"))
{
if(min<=Double.valueOf(dataSet[loopCounter][attributeNo])&&max>=Double.valueOf(dataSet[loopCounter][attributeNo]))
interval_value_count++;
}
}
return interval_value_count;
}
public int calculateIntervalValueCount(double min,double max,int attributeNo)
{
int interval_value_count=0;
for(int loopCounter=0;loopCounter<=noOfRecords-1;loopCounter++)
{
if(!dataSet[loopCounter][attributeNo].equals("?"))
{
if(min<Double.valueOf(dataSet[loopCounter][attributeNo])&&max>=Double.valueOf(dataSet[loopCounter][attributeNo]))
interval_value_count++;
}
}
return interval_value_count;
}
public void showInformationGain()
{
for(int attributeNo=0;attributeNo<=noOfAttributes-2;attributeNo++)
{
System.out.println("Information gain of Attribute No"+attributeNo+"="+informationGain[attributeNo]);
}
}
}