}
String[] nextLine;
while ((nextLine = reader.readNext()) != null) {
BasicData data = new BasicData(TitanicConfig.InputFeatureCount, 1);
String name = nextLine[nameIndex];
String sex = nextLine[sexIndex];
String embarked = nextLine[indexEmbarked];
String id = nextLine[indexId];
// Add record the passenger id, if requested
if (ids != null) {
ids.add(id);
}
boolean isMale = sex.equalsIgnoreCase("male");
// age
double age;
// do we have an age for this person?
if (nextLine[ageIndex].length() == 0) {
// age is missing, interpolate using name
if (name.contains("Master.")) {
age = stats.getMeanMaster().calculate();
} else if (name.contains("Mr.")) {
age = stats.getMeanMr().calculate();
} else if (name.contains("Miss.") || name.contains("Mlle.")) {
age = stats.getMeanMiss().calculate();
} else if (name.contains("Mrs.") || name.contains("Mme.")) {
age = stats.getMeanMrs().calculate();
} else if (name.contains("Col.") || name.contains("Capt.") || name.contains("Major.")) {
age = stats.getMeanMiss().calculate();
} else if (name.contains("Countess.") || name.contains("Lady.") || name.contains("Sir.") || name.contains("Don.") || name.contains("Dona.") || name.contains("Jonkheer.")) {
age = stats.getMeanNobility().calculate();
} else if (name.contains("Dr.")) {
age = stats.getMeanDr().calculate();
} else if (name.contains("Rev.")) {
age = stats.getMeanClergy().calculate();
} else {
if (isMale) {
age = stats.getMeanMale().calculate();
} else {
age = stats.getMeanFemale().calculate();
}
}
} else {
age = Double.parseDouble(nextLine[ageIndex]);
}
data.getInput()[0] = rangeNormalize(age, 0, 100, inputLow, inputHigh);
// sex-male
data.getInput()[1] = isMale ? inputHigh : inputLow;
// pclass
double pclass = Double.parseDouble(nextLine[indexPclass]);
data.getInput()[2] = rangeNormalize(pclass, 1, 3, inputLow, inputHigh);
// sibsp
double sibsp = Double.parseDouble(nextLine[indexSibsp]);
data.getInput()[3] = rangeNormalize(sibsp, 0, 10, inputLow, inputHigh);
// parch
double parch = Double.parseDouble(nextLine[indexParch]);
data.getInput()[4] = rangeNormalize(parch, 0, 10, inputLow, inputHigh);
// fare
String strFare = nextLine[indexFare];
double fare;
if (strFare.length() == 0) {
if (((int) pclass) == 1) {
fare = stats.getMeanFare1().calculate();
} else if (((int) pclass) == 2) {
fare = stats.getMeanFare2().calculate();
} else if (((int) pclass) == 3) {
fare = stats.getMeanFare3().calculate();
} else {
// should not happen, we would have a class other than 1,2,3.
// however, if that DID happen, use the median class (2).
fare = stats.getMeanFare2().calculate();
}
} else {
fare = Double.parseDouble(nextLine[indexFare]);
}
data.getInput()[5] = rangeNormalize(fare, 0, 500, inputLow, inputHigh);
// embarked-c
data.getInput()[6] = embarked.trim().equalsIgnoreCase("c") ? inputHigh : inputLow;
// embarked-q
data.getInput()[7] = embarked.trim().equalsIgnoreCase("q") ? inputHigh : inputLow;
// embarked-s
data.getInput()[8] = embarked.trim().equalsIgnoreCase("s") ? inputHigh : inputLow;
// name-mil
data.getInput()[9] = (name.contains("Col.") || name.contains("Capt.") || name.contains("Major.")) ? inputHigh : inputLow;
// name-nobility
data.getInput()[10] = (name.contains("Countess.") || name.contains("Lady.") || name.contains("Sir.") || name.contains("Don.") || name.contains("Dona.") || name.contains("Jonkheer.")) ? inputHigh : inputLow;
// name-dr
data.getInput()[11] = (name.contains("Dr.")) ? inputHigh : inputLow;
// name-clergy
data.getInput()[12] = (name.contains("Rev.")) ? inputHigh : inputLow;
// add the new row
result.add(data);
// add survived, if it exists
if (survivedIndex != -1) {
int survived = Integer.parseInt(nextLine[survivedIndex]);
data.getIdeal()[0] = (survived == 1) ? predictSurvive : predictPerish;
}
}
return result;