boolean success = false;
if (this.goal == AnalystGoal.Classification) {
// first try to the last classify field
for (final AnalystField field : fields) {
final DataField df = this.script.findDataField(field
.getName());
if (field.getAction().isClassify() && df.isClass()) {
this.targetField = field.getName();
success = true;
}
}
} else {
// otherwise, just return the last regression field
for (final AnalystField field : fields) {
final DataField df = this.script.findDataField(field
.getName());
if (!df.isClass() && (df.isReal() || df.isInteger())) {
this.targetField = field.getName();
success = true;
}
}
}
if (!success) {
throw new AnalystError(
"Can't determine target field automatically, "
+ "please specify one.\nThis can also happen if you "
+ "specified the wrong file format.");
}
} else {
if (this.script.findDataField(this.targetField) == null) {
throw new AnalystError("Invalid target field: "
+ this.targetField);
}
}
this.script.getProperties().setProperty(
ScriptProperties.DATA_CONFIG_GOAL, this.goal);
if (!this.timeSeries && this.taskBalance) {
this.script.getProperties().setProperty(
ScriptProperties.BALANCE_CONFIG_BALANCE_FIELD,
this.targetField);
final DataField field = this.analyst.getScript().findDataField(
this.targetField);
if ((field != null) && field.isClass()) {
final int countPer = field.getMinClassCount();
this.script.getProperties().setProperty(
ScriptProperties.BALANCE_CONFIG_COUNT_PER, countPer);
}
}
// now that the target field has been determined, set the analyst fields
AnalystField af = null;
for (final AnalystField field : this.analyst.getScript().getNormalize()
.getNormalizedFields()) {
if ((field.getAction() != NormalizationAction.Ignore)
&& field.getName().equalsIgnoreCase(this.targetField)) {
if ((af == null) || (af.getTimeSlice() < field.getTimeSlice())) {
af = field;
}
}
}
if (af != null) {
af.setOutput(true);
}
// set the clusters count
if (this.taskCluster) {
if ((this.targetField.length() == 0)
|| (this.goal != AnalystGoal.Classification)) {
this.script.getProperties().setProperty(
ScriptProperties.CLUSTER_CONFIG_CLUSTERS, 2);
} else {
final DataField tf = this.script
.findDataField(this.targetField);
this.script.getProperties().setProperty(
ScriptProperties.CLUSTER_CONFIG_CLUSTERS,
tf.getClassMembers().size());
}
}
}