-- DataSource is an inner (embedded class) of the ConverterUtils class
call bsf.import "weka.core.converters.ConverterUtils$DataSource", DataSource
call bsf.import "weka.core.Instances", Instances

-- load packages
.bsf~new("weka.core.WekaPackageManager") ~loadPackages(.false) -- .false: quiet

-- import data set
weather = .DataSource~new("./weather.nominal.arff") ~getDataSet
seed    = 0
weather~randomize( .bsf~new("java.util.Random",seed) )

trainPercentage = 60
trainSize = format(weather~numInstances * trainPercentage / 100,,0)
testSize  = weather~numInstances - trainSize
trainData = .Instances~new(weather, 0, trainSize)
testData  = .Instances~new(weather, trainSize, testSize)

-- Compute Logistic Regression
svm = .bsf~new("weka.classifiers.functions.SMO")
-- set the dependant variable of the training data (in this case the last column)
trainData~setClassIndex(trainData~numAttributes-1);
svm~buildClassifier(trainData)   -- build the model
say svm~toString                 -- print out the result

-- Evaluate Model
eval = .bsf~new("weka.classifiers.Evaluation",trainData)
testData~setClassIndex(testData~numAttributes-1)   -- set the dependant variable of the testing data (in this case the last column)

-- this version of evaluateModel expects three (!) arguments
noPredictions=bsf.createJavaArray("java.lang.Object",0)  -- create a 0 capacity Java array
eval~evaluateModel(svm, testData, noPredictions)    -- evaluate the model
say "=== toSummaryString ===" eval~toSummaryString
say eval~toMatrixString          -- print out the confusion matrix

::requires "BSF.CLS"	-- get Java-ooRexx bridge
