Table of Contents
Example A.1. Generating scoring code:
if not tableExists('cholesterol'):
raise "Table 'cholesterol' does not exists. Please run cholesterol.py script from data directory first"
# loading data
pd = PhysicalData('cholesterol')
save('pd', pd)
ld = LogicalData(pd)
save('ld', ld)
# first transformation - replace missing
replacesettings = ReplaceMissingSettings()
replacesettings.setLogicalData(ld)
save('replace_ss', replacesettings)
# Define task to build transformation
bt = TransformationBuildTask()
bt.setPhysicalDataName('pd')
bt.setTransformationName('replace_tr')
bt.setTransformationSettingsName('replace_ss')
save('replace_bt', bt)
execute('replace_bt')
# apply task to create outtable
save('pd_out',PhysicalData('cholesterol_out1'))
tat=TransformationApplyTask()
tat.replaceExistingData = TRUE
tat.setTransformationName('replace_tr')
tat.setSourceDataName('pd')
tat.setTargetDataName('pd_out')
save('replace_at', tat)
execute('replace_at')
# set physical data as replaced missing table (cholesterol_out1)
pd = PhysicalData('cholesterol_out1')
save('pd', pd)
ld = LogicalData(pd)
save('ld', ld)
# second transformation - settings
binarizeSettings = BinarizeSettings()
binarizeSettings.setLogicalData(ld)
binarizeSettings.getAttributeUsageSet().getAttribute('sex').setUsage(TransformationUsageOption.transform)
binarizeSettings.getAttributeUsageSet().getAttribute('cp').setUsage(TransformationUsageOption.transform)
binarizeSettings.getAttributeUsageSet().getAttribute('fbs').setUsage(TransformationUsageOption.transform)
binarizeSettings.getAttributeUsageSet().getAttribute('restecg').setUsage(TransformationUsageOption.transform)
binarizeSettings.getAttributeUsageSet().getAttribute('exang').setUsage(TransformationUsageOption.transform)
binarizeSettings.getAttributeUsageSet().getAttribute('slope').setUsage(TransformationUsageOption.transform)
binarizeSettings.getAttributeUsageSet().getAttribute('thal').setUsage(TransformationUsageOption.transform)
binarizeSettings.allRandomRedundant()
save('binarize_ss', binarizeSettings)
# define build task to build second transformation
bt = TransformationBuildTask()
bt.setPhysicalDataName('pd')
bt.setTransformationName('binarize_tr')
bt.setTransformationSettingsName('binarize_ss')
save('binarize_bt', bt)
execute('binarize_bt')
save('pd_out',PhysicalData('cholesterol_out2'))
# apply task to create binarized table
tat2=TransformationApplyTask()
tat2.replaceExistingData =TRUE
tat2.setTransformationName('binarize_tr')
tat2.setSourceDataName('pd')
tat2.setTargetDataName('pd_out')
save('binarize_at', tat2)
execute('binarize_at')
# building regression model from transformed data
pd = PhysicalData('cholesterol_out2')
ld = LogicalData(pd)
#------ Approximation function settings ------
fs = ApproximationFunctionSettings()
fs.setLogicalData(ld)
#fs.logicalData = ld
fs.targetAttributeName = 'chol'
#------ Linear Regression algorithm settings ------
as = LinearRegressionSettings()
as.preselection = TRUE
as.intercept = TRUE
vss = VariableSelectionSettings()
vss.variableSelectionMethod = VariableSelectionMethod.forward
vss.modelEntryLevel = 0.05
as.variableSelectionSettings = vss
fs.algorithmSettings = as
save('pd', pd)
save('ld', ld)
save('fs', fs)
#------ model building ------
bt = MiningBuildTask('pd', 'fs', 'model')
save('bt', bt)
execute('bt')
# creation of Scoring code build task
ScoringCodebt = ScoringCodeBuildTask()
ScoringCodebt.setInputModelName( 'model' )
ScoringCodebt.setOutputModelName( 'ScoringCode' )
ScoringCodebt.setCanGenerateWithCompilationErrors( TRUE )
save('ScoringCode_bt',ScoringCodebt)
execute('ScoringCode_bt')
# loading built model
scCode = load('ScoringCode')
#printing the scoring code
print scCode.getCodeBody()
Output:
import java.util.HashMap;
public class ScoringCode {
public java.lang.Object NOT_MAPPED = new Object() {
public String toString() {
return "Value unknown - this attribute was not mapped.";
}
};
private java.util.HashMap tempInput = new HashMap();
private java.util.HashMap tempOutput = new HashMap();
private __Transformation__ trans = new __Transformation__();
public ScoringCode(){
//i.e. y = beta[0] + beta[1]*input[0] + beta[2]*input[1] if intercept = 1
//and: y = beta[0]*input[0] + beta[1]*input[1] + beta[2]*input[2] if intercept = 0
beta[0] = 195.6026931746182;
beta[1] = 0.9590824479984242;
beta[2] = -15.415481786998711;
beta[3] = 20.495430290654568;
}
private void scoreData(Object[] input, OutputStructure output){
processRow(prepareData(input), output);
}
public double getCategoricalValueCode(java.util.HashMap data, java.lang.String attrName, int attrIndex){
double output=Double.NaN;
for(int i=0; i< Signature.INPUT_ATTRIBUTES_VALUE_SET[attrIndex].length; i++){
Object v = data.get(attrName);
Object m = Signature.INPUT_ATTRIBUTES_VALUE_SET[attrIndex][i];
if( v instanceof Number && m instanceof Number) {
if( ((Number) m).doubleValue() == ((Number) v).doubleValue() ){
output=i;
break;
}
} else {
if( m.equals(v) ){
output=i;
break;
}
}
}
if( Double.isNaN(output) )
throw new RuntimeException("Value "+tempOutput.get(attrName).toString()+" is not in input attributes value set");
return output;
}
public double[] prepareData(java.lang.Object[] inputData){
tempInput.clear();
/*Input attributes mapping*/
if (inputData[0] == NOT_MAPPED)
throw new RuntimeException("Attribute 'num' is not mapped with input data. Can't continue.");
tempInput.put("num", inputData[0]);
if (inputData[1] == NOT_MAPPED)
throw new RuntimeException("Attribute 'ca' is not mapped with input data. Can't continue.");
tempInput.put("ca", inputData[1]);
if (inputData[2] == NOT_MAPPED)
throw new RuntimeException("Attribute 'trestbps' is not mapped with input data. Can't continue.");
tempInput.put("trestbps", inputData[2]);
if (inputData[3] == NOT_MAPPED)
throw new RuntimeException("Attribute 'age' is not mapped with input data. Can't continue.");
tempInput.put("age", inputData[3]);
if (inputData[4] == NOT_MAPPED)
throw new RuntimeException("Attribute 'chol' is not mapped with input data. Can't continue.");
tempInput.put("chol", inputData[4]);
if (inputData[5] == NOT_MAPPED)
throw new RuntimeException("Attribute 'oldpeak' is not mapped with input data. Can't continue.");
tempInput.put("oldpeak", inputData[5]);
if (inputData[6] == NOT_MAPPED)
throw new RuntimeException("Attribute 'thalach' is not mapped with input data. Can't continue.");
tempInput.put("thalach", inputData[6]);
if (inputData[7] == NOT_MAPPED)
throw new RuntimeException("Attribute '__restecg__1' is not mapped with input data. Can't continue.");
tempInput.put("__restecg__1", inputData[7]);
if (inputData[8] == NOT_MAPPED)
throw new RuntimeException("Attribute '__restecg__0' is not mapped with input data. Can't continue.");
tempInput.put("__restecg__0", inputData[8]);
if (inputData[9] == NOT_MAPPED)
throw new RuntimeException("Attribute '__sex__0' is not mapped with input data. Can't continue.");
tempInput.put("__sex__0", inputData[9]);
if (inputData[10] == NOT_MAPPED)
throw new RuntimeException("Attribute '__cp__2' is not mapped with input data. Can't continue.");
tempInput.put("__cp__2", inputData[10]);
if (inputData[11] == NOT_MAPPED)
throw new RuntimeException("Attribute '__cp__1' is not mapped with input data. Can't continue.");
tempInput.put("__cp__1", inputData[11]);
if (inputData[12] == NOT_MAPPED)
throw new RuntimeException("Attribute '__cp__4' is not mapped with input data. Can't continue.");
tempInput.put("__cp__4", inputData[12]);
if (inputData[13] == NOT_MAPPED)
throw new RuntimeException("Attribute '__slope__2' is not mapped with input data. Can't continue.");
tempInput.put("__slope__2", inputData[13]);
if (inputData[14] == NOT_MAPPED)
throw new RuntimeException("Attribute '__slope__1' is not mapped with input data. Can't continue.");
tempInput.put("__slope__1", inputData[14]);
if (inputData[15] == NOT_MAPPED)
throw new RuntimeException("Attribute '__exang__0' is not mapped with input data. Can't continue.");
tempInput.put("__exang__0", inputData[15]);
if (inputData[16] == NOT_MAPPED)
throw new RuntimeException("Attribute '__thal__7' is not mapped with input data. Can't continue.");
tempInput.put("__thal__7", inputData[16]);
if (inputData[17] == NOT_MAPPED)
throw new RuntimeException("Attribute '__thal__6' is not mapped with input data. Can't continue.");
tempInput.put("__thal__6", inputData[17]);
if (inputData[18] == NOT_MAPPED)
throw new RuntimeException("Attribute '__fbs__0' is not mapped with input data. Can't continue.");
tempInput.put("__fbs__0", inputData[18]);
tempOutput = trans.transformRow(tempInput);
/*Output attributes mapping*/
double [] output = new double[3];
/*Initialize output array with Double.NaN's*/
java.util.Arrays.fill(output, Double.NaN);
Object tmpAttr;
tmpAttr = tempOutput.get("age");
if (tmpAttr != null ) {
if (tmpAttr instanceof Number)
output[0]=((Number)tmpAttr).doubleValue();
else
throw new RuntimeException("Data type ("+tmpAttr.getClass()+") doesn't match to data type (Number) specified in inputSignature for attribute 'age'. Can't continue. ");
}
tmpAttr = tempOutput.get("__restecg__0");
if (tmpAttr != null ) {
if (tmpAttr instanceof Number)
output[1]=((Number)tmpAttr).doubleValue();
else
throw new RuntimeException("Data type ("+tmpAttr.getClass()+") doesn't match to data type (Number) specified in inputSignature for attribute '__restecg__0'. Can't continue. ");
}
tmpAttr = tempOutput.get("__sex__0");
if (tmpAttr != null ) {
if (tmpAttr instanceof Number)
output[2]=((Number)tmpAttr).doubleValue();
else
throw new RuntimeException("Data type ("+tmpAttr.getClass()+") doesn't match to data type (Number) specified in inputSignature for attribute '__sex__0'. Can't continue. ");
}
return output;
}
public static class InputSignature {
public static java.lang.Object[][] INPUT_ATTRIBUTES = new Object [][] {
{"num", Double.class }, /* inputRow[0]*/
{"ca", Double.class }, /* inputRow[1]*/
{"trestbps", Double.class }, /* inputRow[2]*/
{"age", Double.class }, /* inputRow[3]*/
{"chol", Double.class }, /* inputRow[4]*/
{"oldpeak", Double.class }, /* inputRow[5]*/
{"thalach", Double.class }, /* inputRow[6]*/
{"__restecg__1", Double.class }, /* inputRow[7]*/
{"__restecg__0", Double.class }, /* inputRow[8]*/
{"__sex__0", Double.class }, /* inputRow[9]*/
{"__cp__2", Double.class }, /* inputRow[10]*/
{"__cp__1", Double.class }, /* inputRow[11]*/
{"__cp__4", Double.class }, /* inputRow[12]*/
{"__slope__2", Double.class }, /* inputRow[13]*/
{"__slope__1", Double.class }, /* inputRow[14]*/
{"__exang__0", Double.class }, /* inputRow[15]*/
{"__thal__7", Double.class }, /* inputRow[16]*/
{"__thal__6", Double.class }, /* inputRow[17]*/
{"__fbs__0", Double.class } /* inputRow[18]*/
};
;
}
public static class Signature {
public static java.lang.Object[][] INPUT_ATTRIBUTES = new Object [][] {
{"age", double.class }, /* inputRow[0]*/
{"__restecg__0", double.class }, /* inputRow[1]*/
{"__sex__0", double.class }/* inputRow[2]*/
};
public static java.lang.Object[][] INPUT_ATTRIBUTES_VALUE_SET = new Object [][] {
{ null }, /* age value set -> inputRow [0]*/
{ null }, /* __restecg__0 value set -> inputRow [1]*/
{ null }/* __sex__0 value set -> inputRow [2]*/
};
;
}
public static class __Transformation__ {
private java.util.HashMap directMapping = new java.util.HashMap();
public static final int COPY = 1;
public static final int DROP = 2;
public static final int EXCEPTION = 3;
private int unknownAttributePolicy = DROP;
private java.util.HashSet toCopy;
private java.util.HashSet toTransform;
private java.util.HashSet toDrop;
private InternalTransformation1 internalTransformation1 = new InternalTransformation1();
private InternalTransformation2 internalTransformation2 = new InternalTransformation2();
public __Transformation__(){
toCopy = new java.util.HashSet();
toTransform = new java.util.HashSet();
toTransform.add("__sex__0");
toTransform.add("age");
toTransform.add("__restecg__0");
toDrop = new java.util.HashSet();
}
public java.util.HashMap processRow(java.util.HashMap inputRow){
java.util.HashMap outputRow = transformRow(inputRow);
java.util.Iterator i = directMapping.entrySet().iterator();
while (i.hasNext()) {
java.util.Map.Entry entry = (java.util.Map.Entry)i.next();
String mapping = (String)entry.getKey();
String mapped = (String)entry.getValue();
if (inputRow.keySet().contains(mapped))
outputRow.put(mapping, inputRow.get(mapped));
}
return outputRow;
}
public java.util.HashMap transformRow(java.util.HashMap inputRow){
HashMap outputRow = new HashMap();
java.util.HashMap attributesToTransform = new java.util.HashMap();
java.util.Iterator i = inputRow.entrySet().iterator();
while (i.hasNext()) {
java.util.Map.Entry entry = (java.util.Map.Entry)i.next();
String name = (String)entry.getKey();
Object value = entry.getValue();
if (toCopy.contains(name))
outputRow.put(name, value);
else if (toTransform.contains(name))
attributesToTransform.put(name, value);
else if (!toDrop.contains(name)) {
switch (unknownAttributePolicy) {
case COPY:
outputRow.put(name, value);
break;
case DROP:
break;
case EXCEPTION:
throw new IllegalArgumentException("Unknown attribute '"+name+"'");
default:
throw new IllegalStateException("Unknown policy: "+unknownAttributePolicy);
}
}
}
outputRow.putAll(transform(attributesToTransform));
return outputRow;
}
public java.util.List processAttributesList(java.util.List attributes){
java.util.ArrayList outputList = new java.util.ArrayList();
java.util.Iterator i = directMapping.entrySet().iterator();
while (i.hasNext()) {
java.util.Map.Entry entry = (java.util.Map.Entry)i.next();
String mapping = (String)entry.getKey();
String mapped = (String)entry.getValue();
java.util.Iterator ia = attributes.iterator();
while (ia.hasNext()) {
Attribute att = (Attribute)ia.next();
if (att.name.equals(mapped)) {
Attribute dmatt = new Attribute();
dmatt.name = mapping;
dmatt.type = att.type;
outputList.add(dmatt);
break;
}
}
}
outputList.addAll(transformAttributesList(attributes));
return outputList;
}
public java.util.List transformAttributesList(java.util.List attributes){
java.util.ArrayList outputList = new java.util.ArrayList();
java.util.ArrayList attributesToTransform = new java.util.ArrayList();
java.util.Iterator i = attributes.iterator();
while (i.hasNext()) {
Attribute attribute = (Attribute)i.next();
String name = attribute.name;
if (toCopy.contains(name))
outputList.add(attribute);
else if (toTransform.contains(name))
attributesToTransform.add(attribute);
else if (!toDrop.contains(name)) {
switch (unknownAttributePolicy) {
case COPY:
outputList.add(attribute);
break;
case DROP:
break;
case EXCEPTION:
throw new IllegalArgumentException("Unknown attribute '"+name+"'");
default:
throw new IllegalStateException("Unknown policy: "+unknownAttributePolicy);
}
}
}
outputList.addAll(transformTransformableAttributesList(attributesToTransform));
return outputList;
}
public java.util.HashMap transform(java.util.HashMap attributes){
return internalTransformation2.transformRow(internalTransformation1.transformRow(attributes));
}
public java.util.List transformTransformableAttributesList(java.util.List attributes){
return internalTransformation2.transformAttributesList(internalTransformation1.transformAttributesList(attributes));
}
public static class Attribute {
public java.lang.String name;
public java.lang.Class type;
}
public static class InternalTransformation1 {
private java.util.HashMap directMapping = new java.util.HashMap();
public static final int COPY = 1;
public static final int DROP = 2;
public static final int EXCEPTION = 3;
private int unknownAttributePolicy = DROP;
private java.util.HashSet toCopy;
private java.util.HashSet toTransform;
private java.util.HashSet toDrop;
public InternalTransformation1(){
toCopy = new java.util.HashSet();
toTransform = new java.util.HashSet();
toTransform.add("__sex__0");
toTransform.add("age");
toTransform.add("__restecg__0");
toDrop = new java.util.HashSet();
}
public java.util.HashMap processRow(java.util.HashMap inputRow){
java.util.HashMap outputRow = transformRow(inputRow);
java.util.Iterator i = directMapping.entrySet().iterator();
while (i.hasNext()) {
java.util.Map.Entry entry = (java.util.Map.Entry)i.next();
String mapping = (String)entry.getKey();
String mapped = (String)entry.getValue();
if (inputRow.keySet().contains(mapped))
outputRow.put(mapping, inputRow.get(mapped));
}
return outputRow;
}
public java.util.HashMap transformRow(java.util.HashMap inputRow){
HashMap outputRow = new HashMap();
java.util.HashMap attributesToTransform = new java.util.HashMap();
java.util.Iterator i = inputRow.entrySet().iterator();
while (i.hasNext()) {
java.util.Map.Entry entry = (java.util.Map.Entry)i.next();
String name = (String)entry.getKey();
Object value = entry.getValue();
if (toCopy.contains(name))
outputRow.put(name, value);
else if (toTransform.contains(name))
attributesToTransform.put(name, value);
else if (!toDrop.contains(name)) {
switch (unknownAttributePolicy) {
case COPY:
outputRow.put(name, value);
break;
case DROP:
break;
case EXCEPTION:
throw new IllegalArgumentException("Unknown attribute '"+name+"'");
default:
throw new IllegalStateException("Unknown policy: "+unknownAttributePolicy);
}
}
}
outputRow.putAll(transform(attributesToTransform));
return outputRow;
}
public java.util.List processAttributesList(java.util.List attributes){
java.util.ArrayList outputList = new java.util.ArrayList();
java.util.Iterator i = directMapping.entrySet().iterator();
while (i.hasNext()) {
java.util.Map.Entry entry = (java.util.Map.Entry)i.next();
String mapping = (String)entry.getKey();
String mapped = (String)entry.getValue();
java.util.Iterator ia = attributes.iterator();
while (ia.hasNext()) {
Attribute att = (Attribute)ia.next();
if (att.name.equals(mapped)) {
Attribute dmatt = new Attribute();
dmatt.name = mapping;
dmatt.type = att.type;
outputList.add(dmatt);
break;
}
}
}
outputList.addAll(transformAttributesList(attributes));
return outputList;
}
public java.util.List transformAttributesList(java.util.List attributes){
java.util.ArrayList outputList = new java.util.ArrayList();
java.util.ArrayList attributesToTransform = new java.util.ArrayList();
java.util.Iterator i = attributes.iterator();
while (i.hasNext()) {
Attribute attribute = (Attribute)i.next();
String name = attribute.name;
if (toCopy.contains(name))
outputList.add(attribute);
else if (toTransform.contains(name))
attributesToTransform.add(attribute);
else if (!toDrop.contains(name)) {
switch (unknownAttributePolicy) {
case COPY:
outputList.add(attribute);
break;
case DROP:
break;
case EXCEPTION:
throw new IllegalArgumentException("Unknown attribute '"+name+"'");
default:
throw new IllegalStateException("Unknown policy: "+unknownAttributePolicy);
}
}
}
outputList.addAll(transformTransformableAttributesList(attributesToTransform));
return outputList;
}
public java.util.HashMap transform(java.util.HashMap attributes){
java.util.HashMap outputRow = new java.util.HashMap();
java.util.Iterator i = attributes.entrySet().iterator();
while (i.hasNext()) {
java.util.Map.Entry entry = (java.util.Map.Entry)i.next();
String name = (String)entry.getKey();
Object value = entry.getValue();
outputRow.put(name, transformAttribute(name, value));
}
return outputRow;
}
public java.util.List transformTransformableAttributesList(java.util.List attributes){
java.util.List outputList = new java.util.ArrayList();
java.util.Iterator i = attributes.iterator();
while (i.hasNext()) {
Attribute attribute = (Attribute)i.next();
outputList.add(transformAttribute2(attribute));
}
return outputList;
}
public java.lang.Object transformAttribute(java.lang.String name, java.lang.Object value){
if (value != null)
return value;
java.util.Random random = new java.util.Random();
if (name.equals("__sex__0")) {
return new Double(0.3201320132013201);
}
if (name.equals("age")) {
return new Double(54.43894389438944);
}
if (name.equals("__restecg__0")) {
return new Double(0.49834983498349833);
}
throw new IllegalArgumentException("Attribute '"+name+"' is unknown and cannot be transformed.");
}
public Attribute transformAttribute2(Attribute attribute){
if(long.class.isAssignableFrom(attribute.type)){
attribute.type = double.class;
}
return attribute;
}
}
public static class InternalTransformation2 {
private java.util.HashMap directMapping = new java.util.HashMap();
public static final int COPY = 1;
public static final int DROP = 2;
public static final int EXCEPTION = 3;
private int unknownAttributePolicy = DROP;
private java.util.HashSet toCopy;
private java.util.HashSet toTransform;
private java.util.HashSet toDrop;
public InternalTransformation2(){
toCopy = new java.util.HashSet();
toCopy.add("__sex__0");
toCopy.add("age");
toCopy.add("__restecg__0");
toTransform = new java.util.HashSet();
toDrop = new java.util.HashSet();
}
public java.util.HashMap processRow(java.util.HashMap inputRow){
java.util.HashMap outputRow = transformRow(inputRow);
java.util.Iterator i = directMapping.entrySet().iterator();
while (i.hasNext()) {
java.util.Map.Entry entry = (java.util.Map.Entry)i.next();
String mapping = (String)entry.getKey();
String mapped = (String)entry.getValue();
if (inputRow.keySet().contains(mapped))
outputRow.put(mapping, inputRow.get(mapped));
}
return outputRow;
}
public java.util.HashMap transformRow(java.util.HashMap inputRow){
HashMap outputRow = new HashMap();
java.util.HashMap attributesToTransform = new java.util.HashMap();
java.util.Iterator i = inputRow.entrySet().iterator();
while (i.hasNext()) {
java.util.Map.Entry entry = (java.util.Map.Entry)i.next();
String name = (String)entry.getKey();
Object value = entry.getValue();
if (toCopy.contains(name))
outputRow.put(name, value);
else if (toTransform.contains(name))
attributesToTransform.put(name, value);
else if (!toDrop.contains(name)) {
switch (unknownAttributePolicy) {
case COPY:
outputRow.put(name, value);
break;
case DROP:
break;
case EXCEPTION:
throw new IllegalArgumentException("Unknown attribute '"+name+"'");
default:
throw new IllegalStateException("Unknown policy: "+unknownAttributePolicy);
}
}
}
outputRow.putAll(transform(attributesToTransform));
return outputRow;
}
public java.util.List processAttributesList(java.util.List attributes){
java.util.ArrayList outputList = new java.util.ArrayList();
java.util.Iterator i = directMapping.entrySet().iterator();
while (i.hasNext()) {
java.util.Map.Entry entry = (java.util.Map.Entry)i.next();
String mapping = (String)entry.getKey();
String mapped = (String)entry.getValue();
java.util.Iterator ia = attributes.iterator();
while (ia.hasNext()) {
Attribute att = (Attribute)ia.next();
if (att.name.equals(mapped)) {
Attribute dmatt = new Attribute();
dmatt.name = mapping;
dmatt.type = att.type;
outputList.add(dmatt);
break;
}
}
}
outputList.addAll(transformAttributesList(attributes));
return outputList;
}
public java.util.List transformAttributesList(java.util.List attributes){
java.util.ArrayList outputList = new java.util.ArrayList();
java.util.ArrayList attributesToTransform = new java.util.ArrayList();
java.util.Iterator i = attributes.iterator();
while (i.hasNext()) {
Attribute attribute = (Attribute)i.next();
String name = attribute.name;
if (toCopy.contains(name))
outputList.add(attribute);
else if (toTransform.contains(name))
attributesToTransform.add(attribute);
else if (!toDrop.contains(name)) {
switch (unknownAttributePolicy) {
case COPY:
outputList.add(attribute);
break;
case DROP:
break;
case EXCEPTION:
throw new IllegalArgumentException("Unknown attribute '"+name+"'");
default:
throw new IllegalStateException("Unknown policy: "+unknownAttributePolicy);
}
}
}
outputList.addAll(transformTransformableAttributesList(attributesToTransform));
return outputList;
}
public java.util.HashMap transform(java.util.HashMap attributes){
java.util.HashMap outputRow = new java.util.HashMap();
java.util.Iterator i = attributes.entrySet().iterator();
while (i.hasNext()) {
java.util.Map.Entry entry = (java.util.Map.Entry)i.next();
String name = (String)entry.getKey();
Object value = entry.getValue();
outputRow.putAll(transformAttribute(name, value));
}
return outputRow;
}
public java.util.List transformTransformableAttributesList(java.util.List attributes){
java.util.List outputList = new java.util.ArrayList();
java.util.Iterator i = attributes.iterator();
while (i.hasNext()) {
Attribute attribute = (Attribute)i.next();
outputList.addAll(transformAttribute2(attribute));
}
return outputList;
}
public java.util.HashMap transformAttribute(java.lang.String name, java.lang.Object value){
java.util.HashMap out = new java.util.HashMap();
Object transValue;
return out;
}
public java.util.List transformAttribute2(Attribute attribute){
java.util.ArrayList outputList = new java.util.ArrayList();
Attribute att;
return outputList;
}
}
}
/** * OutputStructure encloses information about names and types which can be obtained from processRow method
* This structure can contain the following types: double, int, String, double [], int [].
* OutputStructure is used by AdvancedMiner to determine the output.
*/
public static class OutputStructure {
public double predictedTargetValue;
}
/////////////////////////// DATA TAKEN FROM GORNIK MODEL //////////////////////////////////////
//Values assigned to variables listed below are taken from model
public final int varNo = 3;
public final int intercept = 1; // 0 for model without intercept
/** vector of estimated parameters from the model */
protected double[] beta = new double[varNo+intercept];
///////////////////////////////////// SCORING CODE ////////////////////////////////////////////
/** computes predicted target value: y=sum_i(beta[i]*input[i])
* @param input scoring data row */
protected double linearScore(double[] input) {
double prediction = (intercept > 0 ? beta[0] : 0);
for(int k=0; k<varNo; k++) {
if (Double.isNaN(input[k]))
throw new RuntimeException("Missing values are not supported.");
prediction += beta[k+intercept]*input[k];
}
return prediction;
}
//Input data row processing
/** * processRow - works with a single data row.
* Data returned by processRow method is placed in OutputStructure output
* <b>Remarks:<b>
* Do not use this function, it uses mapped, and coded values in double array. Better use scoreData method.
* @param input - array of double data
* @param output - this structure will be the scoring output.
*/
public void processRow(double[] inputRow, OutputStructure output) {
//Input data checking
if(inputRow.length != varNo)
throw new RuntimeException("Input array size doesn't match the number of variables in the model [" + varNo + "]");
output.predictedTargetValue = linearScore(inputRow);
}
/////////////////////////////////// END OF SCORING CODE //////////////////////////////////////////
}