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;
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;
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.\nNote: If your file has no headers, specify \"field:1\" - \"field:n\".");
}
} else {
this.targetField = this.script
.findAnalystField(this.targetFieldName);
if (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.getName());
final DataField field = this.analyst.getScript().findDataField(
this.targetField.getName());
if ((field != null) && field.isClass()) {
final int countPer = field.getMinClassCount();
this.script.getProperties().setProperty(
ScriptProperties.BALANCE_CONFIG_COUNT_PER, countPer);
} else {
throw new AnalystError("Balance currently may only be used on a nominal/class field, not a numeric field.");
}
}
// determine output field
if (this.methodType != WizardMethodType.BayesianNetwork) {
// 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 == this.targetField) {
if ((af == null)
|| (af.getTimeSlice() < field.getTimeSlice())) {
af = field;
}
}
}
/* If we found the output field, then flip its status to output */
if (af != null) {
af.setOutput(true);
/* However, if we are including the target field in the input, for time series,
* then we must create an input field for it.
*/
if( this.includeTargetField ) {
AnalystField af2 = new AnalystField(af);
af.setOutput(false);
this.script.getNormalize().getNormalizedFields().add(af2);
}
}
}
// set the clusters count
if (this.taskCluster) {
if ((this.targetField == null)
|| (this.goal != AnalystGoal.Classification)) {
this.script.getProperties().setProperty(
ScriptProperties.CLUSTER_CONFIG_CLUSTERS, 2);
} else {
final DataField tf = this.script.findDataField(this.targetField
.getName());
this.script.getProperties().setProperty(
ScriptProperties.CLUSTER_CONFIG_CLUSTERS,
tf.getClassMembers().size());
}
}
}