i have this dataset:
String[][] trainData= {
//featIdx////////classInfo
{"s", "y", "r"},//0
{"s", "n", "r"},//1
{"w", "y", "r"},//0
{"r", "y", "p"},//0
{"r", "n", "r"},//2
{"r", "y", "p"},//0
{"w", "n", "p"},//0
{"w", "n", "r"},//3
{"w", "y", "r"},//0
{"s", "n", "r"}};//1
int[] trainClassInfo = {0, 1, 0, 0, 2, 0, 0, 3, 0, 1};
i want to check if the elements of trainClassInfo is all same at the indexes when trainData[0]=="s"
i wrote this method but it doesnt perform correctly, i'm confused ... :confused:
public boolean allSame(int featIdx, String featVal)
{
boolean allSame = false;
int classInfo =-1;
for(int i=0; i<trainData.length; i++){
if(trainData[i][featIdx]==featVal){//when trainData element equals "s"
classInfo = trainClassInfo[i];//save classInfo temporarily
}
}
for(int i=0; i<trainData.length; i++){
if(trainData[i][featIdx]==featVal && trainClassInfo[i]==classInfo )
allSame = true;
else
allSame = false;
}
return allSame;
}
it must return FALSE when i put this method like this: allSame(0, "s")
, but it returns TRUE