The scripts below present the abilities of the Feed Forward Neural Networks module in AdvancedMiner. Please note that these scripts are divided into functional parts and do not include the data required to run the scripts in AdvancedMiner Client . The full source with the data can be found in the Examples appendix.
Example 34.1. Data preparation example
# Description:
# This example shows, how to prepare data for
# neural networks using standardization.
#
# All other examples for neural networks
# are based on the data objects prepared by this script.
#
# Remarks:
# This script uses data which was generated by the
# "iris" script from the "data" folder
# Table names
input_data_name = 'iris'
input_std_data_name = input_data_name + '_std'
# Checking whether the required table exists
if not tableExists(input_data_name):
raise "Table "+input_data_name+" does not exists. " \
"Please run "+input_data_name+".gy script from data directory first"
# --- Data Standardization Begin ---
# Creating and saving physical data
print "Creating physical data...\t\t\t\t\t",
input_pd = PhysicalData(input_data_name)
save('input_physical_data', input_pd)
print "done"
# Generating logical data from physical data
print "Creating logical data...\t\t\t\t\t",
input_ld = LogicalData(input_pd)
save('input_logical_data', input_ld)
print "done"
# Creating and saving transformation settings for standardization
print "Creating transformation settings...\t\t\t\t",
std_set = StandardizeSettings()
std_set.logicalData=input_ld
save('std_set',std_set)
print "done"
# Creating, saving and executing transformation build task for standardization
# The created transformation (after execution of tbt) is called transformation_name
print "Building standardization transformation...\t\t\t",
transformation_name = 'standardize'
tbt = TransformationBuildTask()
tbt.physicalDataName = 'input_physical_data'
tbt.transformationName = transformation_name
tbt.transformationSettingsName = 'std_set'
save('tbt',tbt)
execute('tbt')
print "done"
# Creating, saving and executing transformation apply task for standardization
# The data from input_data_name is standardized and saved in input_std_data_name
print "Applying standardization transformation for data '"+input_data_name+"'...\t",
save('pd_out',PhysicalData(input_std_data_name))
tat = TransformationApplyTask()
tat.replaceExistingData = TRUE
tat.setTransformationName(transformation_name)
tat.setSourceDataName('input_physical_data')
tat.setTargetDataName('pd_out')
save('tat',tat)
execute('tat')
print "done"
# Cleaning temporary objects
print "Cleaning temporal objects...\t\t\t\t\t",
delete(transformation_name)
delete('tat')
delete('tbt')
delete('std_set')
delete('input_physical_data')
delete('input_logical_data')
print "done"
# --- Data Standarization End ---
# --- Data Splitting Begin ---
# Table name with data for training
train_data_name = input_std_data_name + '_trn'
# Table name with data for testing
test_data_name = input_std_data_name + '_tst'
# Random splitting data into training and testing set.
# 60% data is put into the training set and 40% into the testing set.
print "Splitting data into training and testing sets...\t\t",
tableSplit(input_std_data_name,split=[6,4],output=[train_data_name,test_data_name],seed=7777)
print "done"
# Creating and saving physical and logical data for the training set
print "Creating physical and logical data for training...\t\t",
train_pd = PhysicalData(train_data_name)
save('physical_train_data', train_pd)
train_ld = LogicalData(train_pd)
save('logical_train_data', train_ld)
print "done"
# Creating and saving physical and logical data for the testing set
print "Creating physical and logical data for testing...\t\t",
test_pd = PhysicalData(test_data_name)
save('physical_test_data', test_pd)
test_ld = LogicalData(test_pd)
save('logical_test_data', test_ld)
print "done"
Output:
Creating physical data... done Creating logical data... done Creating transformation settings... done Building standardization transformation... done Applying standardization transformation for data 'iris'... done Cleaning temporal objects... done Splitting data into training and testing sets... done Creating physical and logical data for training... done Creating physical and logical data for testing... done
Example 34.2. Model building examples - classification
# Description:
# This example shows how to create a neural network classifier.
# The data used is iris. The predicted target id is 'Class'.
# The algorithm tries to learn on other attributes what is the
# type of each flower.
#
# Remarks:
# This script uses the data generated by the example
# script preparing standarized data for neural networks.
# Loading previously prepared physical and logical data for training
print "Loading physical data...\t\t",
pd = load('physical_train_data')
print "done"
print "Loading logical data...\t\t\t",
ld = load('logical_train_data')
print "done"
# Name of the model
NET_model_name = 'NET_model_class'
# Name of target attribute
target = "Class"
# --- Algorithm Settings Preparation Begin ---
print "Preparing neural network settings...\t",
# New classification function settings
net_cfs = ClassificationFunctionSettings()
# Assigning the selected logical data
net_cfs.logicalData = ld
# Setting the target attribute
net_cfs.getAttributeUsageSet().getAttribute(target).setUsage(UsageOption.target)
# Using FeedforwardNeuralNet settings
net_set = FeedforwardNeuralNetSettings()
net_set.automaticDataTransformations = TRUE
# [0] - replace missing
# [1] - standardize
# [2] - binarization
binarizationSettings = net_set.transformationSettings.internalTransformationsSettings[2]
# Setting bipolar (i.e. {-1, 1}) binarization for categorical attributes on
binarizationSettings.setDefaultBinarizedValues(BinarizedValues.bipolar)
# Setting Standard error function which is the sum of squared diffrernces between
# required and obtained values at output.
net_set.errorFunction = FeedforwardErrorFunctionType.sumSquared
# Setting maximum number of iterations
net_set.maxNumberOfIterations=1000
# Setting minimum error tolerance
net_set.minErrorTolerance=0.001
# Setting the variace of noise to 0 - no noise is used
net_set.noise = 0
# Setting the logistic activation function for neurons in output layer
net_set.outputLayerActivationFunction=NeuronActivationFunctionType.logistic
# Setting randomization for training examples to 'on'
net_set.randomization = TRUE
# Setting the seed
net_set.seed = 1234
# Setting one hidden layer with 3 neurons
hidden_layers = []
hidden_layers.append(NeuralLayer(3))
net_set.setNeuralLayers(hidden_layers)
# New learning algorithm - standard backpropagation
net_la = FeedforwardLearningAlgorithm(FeedforwardLearningAlgorithmType.backProp)
# Setting the learning rate for training
net_la.learningRate = 0.3
# Setting the value of momentum
net_la.momentum = 0.1
# Assigning the specified algorithm to neural network settings
net_set.learningAlgorithm=net_la
# Assignin the specified neural network settings to function settings
net_cfs.algorithmSettings=net_set
# Saving the prepared function settings
save('net_cfs',net_cfs)
print "done"
# --- Algorithm Settings Preparation End ---
# --- Model Building Begin ---
print "Building model '"+NET_model_name+"'...\t",
# Creating, saving and execuiting build task for neural network
# with the specified training data and function settings.
net_mbt = MiningBuildTask('physical_train_data' , 'net_cfs' , NET_model_name)
save('NET_mbt',net_mbt)
execute('NET_mbt')
print "done"
# --- Model Building End ---
# --- Weights of Model Displaying Begin ---
# Loading the just built model
model = load(NET_model_name)
print "\nWeights of neurons in built model:\n"
# Loop by layers
for l in range(1, model.modelStatistics.getNumberOfLayers()) :
print "connections to layer",l,"from layer",(l-1)
# Loop by neurons in current layer
for pn in range(0, model.modelStatistics.getNumberOfNeurons(l)) :
# Printing the value of threshold for the current neuron
print "to neuron",pn,": thres =%6.2f "%model.modelStatistics.getThreshold(l, pn),
# Loop by neurons in previous layer
for nn in range(0, model.modelStatistics.getNumberOfNeurons(l-1)) :
# Printing the value of current weight
print "from",nn,"=%6.2f "%model.modelStatistics.getWeight(l, pn, nn),
print
print
# --- Weights of Model Displaying End ---
Output:
Loading physical data... done Loading logical data... done Preparing neural network settings... done Building model 'NET_model_class'... done Weights of neurons in built model: connections to layer 1 from layer 0 to neuron 0 : thres = 1.31 from 0 = 2.38 from 1 = 1.98 from 2 = 0.14 from 3 = -0.97 to neuron 1 : thres = -7.15 from 0 = 8.08 from 1 = 4.49 from 2 = -0.95 from 3 = -0.61 to neuron 2 : thres = -1.86 from 0 = -2.35 from 1 = -2.29 from 2 = -1.02 from 3 = 1.37 connections to layer 2 from layer 1 to neuron 0 : thres = -0.92 from 0 = -2.90 from 1 = -0.75 from 2 = 3.03 to neuron 1 : thres = -4.52 from 0 = 3.01 from 1 = -6.62 from 2 = -4.39 to neuron 2 : thres = -2.68 from 0 = 0.15 from 1 = 6.60 from 2 = 0.26
Example 34.3. Model building examples - approximation
# Description:
# This example shows how to create a neural network approximator.
# The data used is iris. The predicted value is 'sepalwidth'.
# The algorithm tries to learn on other attributes what is the
# proper value of sepalwidth of each flower.
#
# Attribute 'Class' is turned off
# (by setting its usage to inactive)
#
# Remarks:
# This script uses the data generated by the example
# script preparing standarized data for neural networks.
# Loading previously prepared physical and logical data for training
print "Loading physical data...\t\t",
pd = load('physical_train_data')
print "done"
print "Loading logical data...\t\t\t",
ld = load('logical_train_data')
print "done"
# Name of the model
NET_model_name = 'NET_model_approx'
# Name of the attribute to ommit
inactive = "Class"
# Name of the target attribute
target = "sepalwidth"
# --- Algorithm Settings Preparation Begin ---
print "Preparing neural network settings...\t",
# New approximation function settings
net_cfs = ApproximationFunctionSettings()
# Assigning selected logical data
net_cfs.logicalData = ld
# Setting inactive attribute
net_cfs.getAttributeUsageSet().getAttribute(inactive).\
setUsage(UsageOption.inactive)
# Setting the target attribute
net_cfs.getAttributeUsageSet().getAttribute(target).\
setUsage(UsageOption.target)
# Using FeedforwardNeuralNet settings
net_set = FeedforwardNeuralNetSettings()
# Setting maximum number of iterations
net_set.maxNumberOfIterations=1000
# Setting minimum error tolerance
net_set.minErrorTolerance=0.001
# Setting linear activation function for neurons in the output layer
net_set.outputLayerActivationFunction=NeuronActivationFunctionType.linear
# Setting randomization for training examples to 'on'
net_set.randomization = TRUE
# Setting the seed
net_set.seed = 1234
# New learning algorithm - RProp
net_la = FeedforwardLearningAlgorithm(FeedforwardLearningAlgorithmType.rProp)
# Setting the learning rate for training
net_la.learningRate = 0.3
# Assigning the specified algorithm to neural network settings
net_set.learningAlgorithm=net_la
# Assignin the specified neural network settings to function settings
net_cfs.algorithmSettings=net_set
# Saving the prepared function settings
save('net_cfs',net_cfs)
print "done"
# --- Algorithm Settings Preparation End ---
# --- Model Building Begin ---
print "Building model '"+NET_model_name+"'...\t",
# Creating, saving and execuiting build task for neural network
# with specified training data and function settings.
net_mbt = MiningBuildTask('physical_train_data' , 'net_cfs' , NET_model_name)
save('NET_mbt',net_mbt)
execute('NET_mbt')
print "done"
# --- Model Building End ---
# --- Weights of Model Displaying Begin ---
# Loading the just built model
model = load(NET_model_name)
print "\nWeights of neurons in built model:\n"
# Loop by layers
for l in range(1, model.modelStatistics.getNumberOfLayers()) :
print "connections to layer",l,"from layer",(l-1)
# Loop by neurons in current layer
for pn in range(0, model.modelStatistics.getNumberOfNeurons(l)) :
# Printing value of treshold for current neuron
print "to neuron",pn,": thres =%6.2f "%model.modelStatistics.getThreshold(l, pn),
# Loop by neurons in previous layer
for nn in range(0, model.modelStatistics.getNumberOfNeurons(l-1)) :
# Printing the value of current weight
print "from",nn,"=%6.2f "%model.modelStatistics.getWeight(l, pn, nn),
print
print
# --- Weights of Model Displaying End ---
Output:
Loading physical data... done Loading logical data... done Preparing neural network settings... done Building model 'NET_model_approx'... done Weights of neurons in built model: connections to layer 1 from layer 0 to neuron 0 : thres = 1.08 from 0 = 1.58 from 1 = 0.98 from 2 = -2.00 to neuron 1 : thres = 0.92 from 0 = 0.34 from 1 = -1.72 from 2 = 1.81 to neuron 2 : thres = 0.46 from 0 = -1.28 from 1 = 1.27 from 2 = 0.06 to neuron 3 : thres = -8.08 from 0 = 24.15 from 1 = 0.39 from 2 = -9.44 to neuron 4 : thres = -7.90 from 0 = -3.78 from 1 = 9.48 from 2 = -8.28 connections to layer 2 from layer 1 to neuron 0 : thres = 0.51 from 0 = -2.95 from 1 = -1.54 from 2 = 1.46 from 3 = 0.57 from 4 = -1.07
Example 34.4. Model application examples - classification
# Description:
# This example shows, how to create a neural network applier for
# a classification model. The predicted target id is 'Class'.
# The data used is iris. The testing set of data is used to apply
# the built model and to find the right type of each flower.
#
# The ral target is saved in the column 'real_target',
# the predicted target is saved in the column 'predicted_target',
# and the probability of prediction is saved in the column 'prediction_probability'.
#
# Remarks:
# This script uses the data generated by the example
# script preparing standarized data for neural networks.
# This script also uses the neural network model built by
# example script.
# Name of the model
NET_model_name = 'NET_model_class'
# Name of the target attribute
target = "Class"
# Name of the output table
table_name = 'NET_apply_output_for_' + NET_model_name
# Name of apply output
app_output_name = 'NET_apply_output'
# --- Model Application Begin ---
# Creating physical data for output
print "Creating output physical data...\t\t",
net_ao_pd = PhysicalData(table_name)
save(app_output_name, net_ao_pd )
print "done"
print "Creating apply task...\t\t\t\t",
# New mining apply task
net_mat = MiningApplyTask()
# Assigning model for applying
net_mat.modelName = NET_model_name
# Assigning data for applying
net_mat.sourceDataName = 'physical_test_data'
# Assigning ouptut physical data
net_mat.targetDataName = app_output_name
# Replace data in output physical data if any is present
net_mat.replaceExistingData = TRUE
# Creating direct mapping with real target
directMapping = java.util.ArrayList()
directMapping.add(ApplySourceItem(target,'real_target'))
net_mat.setDirectMapping(directMapping)
# Creating apply output with predicted target and its probability
net_cao = ClassificationApplyOutput()
net_cao.item.add(ClassificationRankItem('predicted_target', ClassificationOutputType.\
predictedCategory , 0))
net_cao.item.add(ClassificationRankItem('prediction_probability', \
ClassificationOutputType.probability , 0))
net_mat.applyOutput = net_cao
# Saving the created mining apply task
save('NET_apply_task', net_mat)
print "done"
# Executing mining apply task
print "Applying data for model",NET_model_name,"...\t",
execute('NET_apply_task')
print "done\n"
# --- Model Application End ---
# --- Printing Data after Applying Begin ---
# Selecting data from the output table
sql output :
select * from $table_name order by `real_target`
# Printing the ouput data
print "%16s%20s%25s"%("real target","predicted target","prediction probability")
for i in range(0, len(output)) :
# for j in range(0, len(output[i])) :
print "%16s%18s%12.6f"%(output[i][0],output[i][1],output[i][2])
#print
# --- Printing Data after Applying End ---
Output:
Creating output physical data... done
Creating apply task... done
Applying data for model NET_model_class ... done
real target predicted target prediction probability
Iris-setosa Iris-setosa 0.994294
Iris-setosa Iris-setosa 0.994594
Iris-setosa Iris-setosa 0.994566
Iris-setosa Iris-setosa 0.994555
Iris-setosa Iris-setosa 0.994770
Iris-setosa Iris-setosa 0.994583
Iris-setosa Iris-setosa 0.994756
Iris-setosa Iris-setosa 0.994277
Iris-setosa Iris-setosa 0.994142
Iris-setosa Iris-setosa 0.994573
Iris-setosa Iris-setosa 0.994905
Iris-setosa Iris-setosa 0.994366
Iris-setosa Iris-setosa 0.994533
Iris-setosa Iris-setosa 0.994642
Iris-setosa Iris-setosa 0.994385
Iris-setosa Iris-setosa 0.994652
Iris-setosa Iris-setosa 0.994608
Iris-setosa Iris-setosa 0.994520
Iris-versicolor Iris-versicolor 0.997321
Iris-versicolor Iris-versicolor 0.997031
Iris-versicolor Iris-versicolor 0.997414
Iris-versicolor Iris-versicolor 0.997398
Iris-versicolor Iris-versicolor 0.996660
Iris-versicolor Iris-versicolor 0.996393
Iris-versicolor Iris-versicolor 0.997139
Iris-versicolor Iris-versicolor 0.995532
Iris-versicolor Iris-versicolor 0.996343
Iris-versicolor Iris-virginica 0.919259
Iris-versicolor Iris-versicolor 0.996687
Iris-versicolor Iris-virginica 0.703354
Iris-versicolor Iris-versicolor 0.997279
Iris-versicolor Iris-virginica 0.866702
Iris-versicolor Iris-versicolor 0.992836
Iris-versicolor Iris-versicolor 0.996415
Iris-versicolor Iris-versicolor 0.996181
Iris-versicolor Iris-versicolor 0.996057
Iris-versicolor Iris-versicolor 0.997079
Iris-versicolor Iris-versicolor 0.995362
Iris-versicolor Iris-versicolor 0.984976
Iris-virginica Iris-virginica 0.974319
Iris-virginica Iris-virginica 0.975621
Iris-virginica Iris-virginica 0.976294
Iris-virginica Iris-virginica 0.976213
Iris-virginica Iris-virginica 0.976323
Iris-virginica Iris-virginica 0.974604
Iris-virginica Iris-virginica 0.975892
Iris-virginica Iris-virginica 0.976165
Iris-virginica Iris-virginica 0.976352
Iris-virginica Iris-virginica 0.973878
Iris-virginica Iris-virginica 0.976257
Iris-virginica Iris-virginica 0.976246
Iris-virginica Iris-virginica 0.928473
Iris-virginica Iris-virginica 0.976199
Iris-virginica Iris-virginica 0.972294
Iris-virginica Iris-virginica 0.976147
Iris-virginica Iris-virginica 0.976243
Iris-virginica Iris-virginica 0.976250
Iris-virginica Iris-virginica 0.976403
Iris-virginica Iris-virginica 0.974568
Iris-virginica Iris-virginica 0.974319
Iris-virginica Iris-virginica 0.976305
Iris-virginica Iris-virginica 0.973861
Iris-virginica Iris-virginica 0.976414
Iris-virginica Iris-virginica 0.969826
Example 34.5. Model application examples - approximation
# Description:
# This example shows how to create a neural network applier for
# the approximation model. The approximated value is 'sepalwidth'.
# The data used is iris. The testing set of data is used to apply
# the built model and to find the right width of sepal of each flower.
#
# The real value is saved in the column 'real_value',
# the predicted value is saved in the column 'predicted_value'.
#
# Remarks:
# This script uses the data generated by the example
# script preparing standarized data for neural networks.
# This script also uses neural network model built by
# example script.
# Name of the model
NET_model_name = 'NET_model_approx'
# Name of the target attribute
target = "sepalwidth"
# Name of the output table
table_name = 'NET_apply_output_for_' + NET_model_name
# Name of apply output
app_output_name = 'NET_apply_output'
# --- Model Application Begin ---
# Creating physical data for output
print "Creating output physical data...\t\t",
net_ao_pd = PhysicalData(table_name)
save(app_output_name, net_ao_pd )
print "done"
print "Creating apply task...\t\t\t\t",
# New mining apply task
net_mat = MiningApplyTask()
# Assigning model for applying
net_mat.modelName = NET_model_name
# Assigning data for applying
net_mat.sourceDataName = 'physical_test_data'
# Assigning ouptut physical data
net_mat.targetDataName = app_output_name
# Replace data in output physical data if any is present
net_mat.replaceExistingData = TRUE
# Creating direct mapping with the real value
directMapping = java.util.ArrayList()
directMapping.add(ApplySourceItem(target,'real_value'))
net_mat.setDirectMapping(directMapping)
# Creating apply output with the approximated value
net_aao = ApproximationApplyOutput()
net_aao.item.add(ApproximationOutputItem('approximated_value', ApproximationOutputType.predictedValue))
net_mat.applyOutput = net_aao
# Saving the created mining apply task
save('NET_apply_task', net_mat)
print "done"
# Executing mining apply task
print "Applying data for model",NET_model_name,"...\t",
execute('NET_apply_task')
print "done\n"
# --- Model Application End ---
# --- Printing Data after Applying Begin ---
# Selecting data from the output table
sql output :
select * from $table_name
# Printing ouput data
print "real value \t approximated value"
for i in range(0, len(output)) :
for j in range(0, len(output[i])) :
print "%.4f"%output[i][j]," \t ",
print
# --- Printing Data after Applying End ---Output:
Creating output physical data... done Creating apply task... done Applying data for model NET_model_approx ... done real value approximated value 0.1061 -0.0682 0.7980 -0.0505 0.7980 0.7897 0.7980 0.1613 1.9511 2.1279 1.0286 1.2778 1.7205 1.0855 0.7980 1.3510 0.7980 0.7368 0.7980 1.4344 2.4124 1.1977 0.1061 0.4889 0.3367 1.3718 1.0286 2.1469 -0.1245 -0.6822 1.0286 1.2482 0.3367 -0.6822 0.5674 0.9859 0.3367 0.6020 0.3367 -0.7844 -1.7390 -0.3564 -0.3552 -0.4721 -0.8164 -0.9238 -2.4308 -0.9541 0.1061 0.1819 -0.8164 -1.4651 -1.2777 -1.2645 0.3367 0.0543 -0.5858 -0.7469 -1.2777 -0.5494 -0.1245 -0.1367 -0.1245 -0.1396 -0.3552 -0.3562 -1.5083 -1.1848 -0.8164 -1.1172 -0.1245 -0.5627 -0.8164 -0.3404 -0.1245 -0.7205 -1.2777 -1.3473 -0.8164 -0.1002 -0.3552 -0.9152 -0.1245 -0.3452 -0.3552 -0.3623 1.2592 -0.0838 -0.8164 -0.4026 -0.1245 -0.1313 0.3367 0.3308 1.7205 0.0806 -0.5858 -1.0832 -0.5858 0.1717 0.5674 -0.4583 -0.5858 -0.0383 -0.5858 -0.3146 -0.1245 0.2969 -0.5858 0.2937 -0.5858 -0.0955 -0.1245 1.1239 0.7980 0.1537 0.1061 -0.8092 -0.8164 -0.1002 0.3367 -0.3390 -0.1245 -0.0965 0.7980 0.1184 -0.1245 -0.1860
Example 34.6. Model testing examples - classification
# Description:
# This example shows, how to create a neural network tester for
# classification model. The predicted target id is 'Class'.
# The data used is iris. The testing set of data is used to test
# built model and analyze its propriety. The target value
# 'Iris-versicolor' is used as positive target value.
#
# Remarks:
# This script uses the data generated by the example
# script preparing standarized data for neural networks.
# This script also uses neural network model built by
# example script.
# Name of the model
NET_model_name = 'NET_model_class'
# Name of the result
result_name = 'results_'+NET_model_name
# --- Model Testing Begin ---
print "Preparing classification test task...\t\t",
# New classification test task
net_ctt = ClassificationTestTask()
# Setting the target attribute
net_ctt.testDataTargetAttributeName="Class"
# Setting the positive value of the target
net_ctt.positiveTargetValue="Iris-versicolor"
# Assigning model name
net_ctt.modelName=NET_model_name
# Assigning data for testing
net_ctt.testDataName='physical_test_data'
# Setting result name
net_ctt.testResultName=result_name
# Saving the prepared test task
save('NET_ctt',net_ctt)
print "done"
# Executing the created test task
print "Executing test task for model",NET_model_name,"\t",
execute('NET_ctt')
print "done\n"
# --- Model Testing End ---
# --- Results Printing Begin ---
# Loading result object
result = load(result_name)
# Getting the number of properly assigned cases
prop = result.properlyAssignedCases
# Getting the total number of cases
total = result.totalCases
# Calculating percentage
perc = round(prop/total * 100)
# Printing some info
print "Properly predicted target values:",prop,"of",total,"(",perc,"%)"
# --- Results Printing End ---Output:
Preparing classification test task... done Executing test task for model NET_model_class done Properly predicted target values: 61.0 of 64.0 ( 95.0 %)
Example 34.7. Model testing - approximation
# Description:
# This example shows how to create a neural network tester for
# a classification model. The predicted target id is 'Class'.
# The data used is iris. The testing set of data is used to test
# built model and analyze its propriety. The target value
# 'Iris-versicolor' is used as positive target value.
#
# Remarks:
# This script uses the data generated by the example
# script preparing standarized data for neural networks.
# This script also uses the neural network model built by
# example script.
# Name of the model
NET_model_name = 'NET_model_approx'
# Name of the result
result_name = 'results_'+NET_model_name
# --- Model Testing Begin ---
print "Preparing approximation test task...\t\t",
# New classification test task
net_att = ApproximationTestTask()
# Setting the target attribute
net_att.testDataTargetAttributeName="sepalwidth"
# Assigning model name
net_att.modelName=NET_model_name
# Assigning data for testing
net_att.testDataName='physical_test_data'
# Setting result name
net_att.testResultName=result_name
# Saving the prepared test task
save('NET_att',net_att)
print "done"
# Executing the created test task
print "Executing test task for model",NET_model_name,"\t",
execute('NET_att')
print "done\n"
# --- Model Testing End ---
# --- Results Printing Begin ---
# Loading the result object
result = load(result_name)
# Getting the mean of real values
mReal = result.meanActualValue
# Getting the mean of approximated values
mApprox = result.meanPredictedValue
# Getting the root of the mean squared errors
rms = result.RMSError
# Printing some info
print "Mean of real values is %.4f whereas mean of approximated values is %.4f"%(mReal,mApprox)
print "Root of the mean squared errors is %.4f" % rms
# --- Results Printing End ---Output:
Preparing approximation test task... done Executing test task for model NET_model_approx done Mean of real values is 0.0052 whereas mean of approximated values is -0.0149 Root of the mean squared errors is 0.6684