Package Weka4P
Class Weka4P
java.lang.Object
Weka4P.Weka4P
- All Implemented Interfaces:
PConstants
public class Weka4P extends Object implements PConstants
Main class for Weka Machine Learning library for Processing 3
- Author:
- Rong-Hao Liang: r.liang@tue.nl, Janet Huang: Y.C.huang@tue.nl, Wesley Hartogs: wesleyhartogs.nl
-
Field Summary
Fields Modifier and Type Field Description double[][]
accuracyGrid
double
accuracyTest
double
accuracyTrain
ArrayList<weka.core.Attribute>
attributes
ArrayList<weka.core.Attribute>
attributesTest
ArrayList<weka.core.Attribute>
attributesTrain
weka.classifiers.meta.AttributeSelectedClassifier
attrSelCls
double
C
double[]
CList
weka.classifiers.Classifier
cls
int[]
colors
double[][]
confusionMatrixTest
double[][]
confusionMatrixTrain
double
corrCoef
weka.attributeSelection.CorrelationAttributeEval
corrEval
double
corrThld
weka.core.Instances
data
String
dataset
boolean
drawModels
double
epsilon
double[]
EpsList
weka.classifiers.Evaluation
eval
double[]
fnrTest
double[]
fnrTrain
int
fold
double[]
fprTest
double[]
fprTrain
double[]
fTest
double[]
fTrain
double
gamma
double[]
gammaList
String
hiddenLayers
weka.attributeSelection.InfoGainAttributeEval
IGEval
double
intercept
boolean
isRegression
int
K
int[]
KList
double
learningRate
double
maeTest
double
maeTrain
double[]
mccTest
double[]
mccTrain
String
model
PImage[][]
modelImageGrid
int
nAttributesTest
int
nAttributesTrain
int
nClassesTest
int
nClassesTrain
int
nInstancesTest
int
nInstancesTrain
PGraphics
pg
double[]
prcTest
double[]
prcTrain
double[]
precisionTest
double[]
precisionTrain
double
raeTest
double
raeTrain
weka.attributeSelection.Ranker
ranker
double[]
recallTest
double[]
recallTrain
double
rmseTest
double
rmseTrain
double[]
rocTest
double[]
rocTrain
double
rrseTest
double
rrseTrain
double
rSquared
boolean
showEvalDetails
double
slope
weka.core.converters.ConverterUtils.DataSource
source
double
ssr
weka.core.Instances
test
long
timeLapse
long
timeStamp
double[]
tprTest
double[]
tprTrain
weka.core.Instances
train
weka.core.Instances
training
int
trainingTime
int
unit
static String
VERSION
double
weightedFnrTest
double
weightedFnrTrain
double
weightedFprTest
double
weightedFprTrain
double
weightedFTest
double
weightedFTrain
double
weightedMccTest
double
weightedMccTrain
double
weightedPrcTest
double
weightedPrcTrain
double
weightedPrecisionTest
double
weightedPrecisionTrain
double
weightedRecallTest
double
weightedRecallTrain
double
weightedRocTest
double
weightedRocTrain
Fields inherited from interface processing.core.PConstants
ADD, ALPHA, ALT, AMBIENT, ARC, ARGB, ARROW, BACKSPACE, BASELINE, BEVEL, BEZIER_VERTEX, BLEND, BLUR, BOTTOM, BOX, BREAK, BURN, CENTER, CHATTER, CHORD, CLAMP, CLOSE, CODED, COMPLAINT, CONTROL, CORNER, CORNERS, CROSS, CURVE_VERTEX, CUSTOM, DARKEST, DEG_TO_RAD, DELETE, DIAMETER, DIFFERENCE, DILATE, DIRECTIONAL, DISABLE_ASYNC_SAVEFRAME, DISABLE_BUFFER_READING, DISABLE_DEPTH_MASK, DISABLE_DEPTH_SORT, DISABLE_DEPTH_TEST, DISABLE_KEY_REPEAT, DISABLE_NATIVE_FONTS, DISABLE_OPENGL_ERRORS, DISABLE_OPTIMIZED_STROKE, DISABLE_STROKE_PERSPECTIVE, DISABLE_STROKE_PURE, DISABLE_TEXTURE_MIPMAPS, DODGE, DOWN, DXF, ELLIPSE, ENABLE_ASYNC_SAVEFRAME, ENABLE_BUFFER_READING, ENABLE_DEPTH_MASK, ENABLE_DEPTH_SORT, ENABLE_DEPTH_TEST, ENABLE_KEY_REPEAT, ENABLE_NATIVE_FONTS, ENABLE_OPENGL_ERRORS, ENABLE_OPTIMIZED_STROKE, ENABLE_STROKE_PERSPECTIVE, ENABLE_STROKE_PURE, ENABLE_TEXTURE_MIPMAPS, ENTER, EPSILON, ERODE, ESC, EXCLUSION, FX2D, GIF, GRAY, GROUP, HALF_PI, HAND, HARD_LIGHT, HINT_COUNT, HSB, IMAGE, INVERT, JAVA2D, JPEG, LANDSCAPE, LEFT, LIGHTEST, LINE, LINE_LOOP, LINE_STRIP, LINES, LINUX, MACOSX, MAX_FLOAT, MAX_INT, MIN_FLOAT, MIN_INT, MITER, MODEL, MODELVIEW, MOVE, MULTIPLY, NORMAL, OPAQUE, OPEN, OPENGL, ORTHOGRAPHIC, OTHER, OVERLAY, P2D, P3D, PATH, PDF, PERSPECTIVE, PI, PIE, platformNames, POINT, POINTS, POLYGON, PORTRAIT, POSTERIZE, PROBLEM, PROJECT, PROJECTION, QUAD, QUAD_BEZIER_VERTEX, QUAD_STRIP, QUADRATIC_VERTEX, QUADS, QUARTER_PI, RAD_TO_DEG, RADIUS, RECT, REPEAT, REPLACE, RETURN, RGB, RIGHT, ROUND, SCREEN, SHAPE, SHIFT, SOFT_LIGHT, SPAN, SPHERE, SPOT, SQUARE, SUBTRACT, SVG, TAB, TARGA, TAU, TEXT, THIRD_PI, THRESHOLD, TIFF, TOP, TRIANGLE, TRIANGLE_FAN, TRIANGLE_STRIP, TRIANGLES, TWO_PI, UP, VERTEX, WAIT, WHITESPACE, WINDOWS, X, Y, Z
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description void
CSearchLSVC(double[] _CList)
Searches for C of a Linear Support Vector Classifiervoid
drawCSearchModels(float x, float y, float w, float h)
Draws a graphic representation of C listvoid
drawCSearchResults(float x, float y, float w, float h)
Draws the C search results from CList in textvoid
drawDataPoints()
Draws all datapoints form public train variablevoid
drawDataPoints(weka.core.Instances db)
Draws all data pointsvoid
drawEpsSearchModels(float x, float y, float w, float h)
Draws the graphic representation of the Epsilon search from EpsListvoid
drawEpsSearchResults(float x, float y, float w, float h)
Draws the Epsilon Search results in text from Epslistvoid
drawGridSearchModels(float x, float y, float w, float h)
Draws graphic represatations of the grid search, uses the CList and gammaListvoid
drawGridSearchModels_SVR(float x, float y, float w, float h)
Draws graphical representation of grid search model of sthe Support Vector Regression Uses EpsList and gammaListvoid
drawGridSearchResults(float x, float y, float w, float h)
Draws the grid search results uses Clist and gammaListvoid
drawGridSearchResults_SVR(float x, float y, float w, float h)
Draws the grid search results of the Support Vector Regression in textvoid
drawKSearchModels(float x, float y, float w, float h)
Draws a visualization of the K model at specified locationvoid
drawKSearchResults(float x, float y, float w, float h)
Draws results of the K model at specified location in textvoid
drawModel(int x, int y)
Draws a model image on locationvoid
drawPrediction(float[] X, double Y)
Draws a prediction with textvoid
drawPrediction(float[] X, double Y, int c)
Draws a prediction in textvoid
drawPrediction(float[] X, String Y)
Draws a prediction in textvoid
drawPrediction(float[] X, String Y, int c)
Draws a prediction in textvoid
EpsSearchLSVR(double[] _EpsList)
Searches for Epsilon for a Linear Suport Vector Regressorvoid
evaluateTestSet(boolean _isRegression, boolean _showEvalDetails)
Evaluates test set and prints resultsvoid
evaluateTestSet(weka.classifiers.Classifier _cls, weka.core.Instances _insts, boolean _isRegression, boolean _showEvalDetails)
Evaluates test set and prints resultsvoid
evaluateTrainSet(int _fold, boolean _isRegression, boolean _showEvalDetails)
Evaluates training set and prints resultsPGraphics
getModelImage(PGraphics pg, weka.classifiers.Classifier cls, weka.core.Instances training, int w, int h)
Generates the model image graphicString
getPrediction(float[] _features)
Gets the label of the prediction from features arrayString
getPrediction(float[] _features, weka.classifiers.Classifier _cls)
Gets the label of the prediction, with specified classifierString
getPrediction(float[] _features, weka.classifiers.Classifier _cls, ArrayList<weka.core.Attribute> _attrs, weka.core.Instances _insts)
Gets the label of the predictiondouble
getPredictionIndex(float[] _features)
Gets the prediction index from public test data, uses public attributesTraindouble
getPredictionIndex(float[] _features, weka.classifiers.Classifier _cls)
Gets the prediction index from public test data, with specified classifier, uses public attributesTraindouble
getPredictionIndex(float[] _features, weka.classifiers.Classifier _cls, ArrayList<weka.core.Attribute> _attrs)
Gets the prediction index from public test data, with specified classifier and attributesvoid
gridSearchSVC_RBF(double[] _CList, double[] _gammaList)
void
gridSearchSVR_RBF(double[] _EpsList, double[] _gammaList)
void
KSearch(int[] _KList)
Searches for K in arrayArrayList<weka.core.Attribute>
loadAttributesFromInstances(weka.core.Instances _insts)
Loads attributes form instancesvoid
loadCSV(String _filename)
Loads nominal CSV file into global train variablevoid
loadCSVNumeric(String _filename)
Loads numeric CSV file into global train variablevoid
loadModel(String fileName)
Loads model file and loads into public cls variableweka.classifiers.Classifier
loadModelToClassifier(String fileName)
Loads model into classifiervoid
loadTestARFF(String filename)
Loads ARFF file into public test variablevoid
loadTrainARFF(String filename)
Loads ARFF file into public train variableweka.core.Instances
loadTrainARFFToInstances(String filename)
void
printVersion()
Print the version of the Library.void
rankAttrLSVC(double C)
Ranks Linear Suport Vector and prints the resultvoid
readCSVNominal(String fileName)
Reads the CSV file with nominal valuesvoid
saveClassifier(weka.classifiers.Classifier _cls, String _filename)
Saves a model to specified filevoid
saveModel(String _filename)
Combines classifier with filename to save a modelvoid
saveSVC(String _filename)
Combines classifier with filename to save a modelvoid
saveSVM(String fileName)
Saves a Support Vector Machinevoid
setModelDrawing(int pixelSize)
Set te pixel size of model drawingvoid
trainKNN(int K)
Trains K-nearest Neighbors saves it into public clsvoid
trainLinearRegression()
Trains Linear Regression and saves it into public cls variablevoid
trainLinearSVC(double C)
Trains a Linear Support Vector Clasifiervoid
trainLinearSVR(double epsilon)
Trains a Linear Support Vector Regressionvoid
trainMLP(String _hiddenLayers, int _trainingTime)
Trains a Multilayer Perceptron Saves it to public cls variablevoid
trainMLP(String _hiddenLayers, int _trainingTime, double _learningRate)
Trains a Multilayer Perceptron Saves it to public cls variablevoid
trainPolySVC(int exp, double C)
Trains a Poly Support Vector Classifiervoid
trainRBFSVC(double gamma, double C)
void
trainRBFSVR(double epsilon, double gamma)
-
Field Details
-
VERSION
- See Also:
- Constant Field Values
-
source
public weka.core.converters.ConverterUtils.DataSource source -
train
public weka.core.Instances train -
test
public weka.core.Instances test -
attributesTrain
-
attributesTest
-
eval
public weka.classifiers.Evaluation eval -
pg
-
cls
public weka.classifiers.Classifier cls -
attrSelCls
public weka.classifiers.meta.AttributeSelectedClassifier attrSelCls -
corrEval
public weka.attributeSelection.CorrelationAttributeEval corrEval -
ranker
public weka.attributeSelection.Ranker ranker -
IGEval
public weka.attributeSelection.InfoGainAttributeEval IGEval -
nClassesTrain
public int nClassesTrain -
nAttributesTrain
public int nAttributesTrain -
nInstancesTrain
public int nInstancesTrain -
accuracyTrain
public double accuracyTrain -
weightedPrecisionTrain
public double weightedPrecisionTrain -
weightedRecallTrain
public double weightedRecallTrain -
weightedFprTrain
public double weightedFprTrain -
weightedFnrTrain
public double weightedFnrTrain -
weightedFTrain
public double weightedFTrain -
weightedMccTrain
public double weightedMccTrain -
weightedRocTrain
public double weightedRocTrain -
weightedPrcTrain
public double weightedPrcTrain -
precisionTrain
public double[] precisionTrain -
recallTrain
public double[] recallTrain -
tprTrain
public double[] tprTrain -
fprTrain
public double[] fprTrain -
fnrTrain
public double[] fnrTrain -
fTrain
public double[] fTrain -
mccTrain
public double[] mccTrain -
rocTrain
public double[] rocTrain -
prcTrain
public double[] prcTrain -
confusionMatrixTrain
public double[][] confusionMatrixTrain -
maeTrain
public double maeTrain -
rmseTrain
public double rmseTrain -
raeTrain
public double raeTrain -
rrseTrain
public double rrseTrain -
nClassesTest
public int nClassesTest -
nAttributesTest
public int nAttributesTest -
nInstancesTest
public int nInstancesTest -
accuracyTest
public double accuracyTest -
weightedPrecisionTest
public double weightedPrecisionTest -
weightedRecallTest
public double weightedRecallTest -
weightedFprTest
public double weightedFprTest -
weightedFnrTest
public double weightedFnrTest -
weightedFTest
public double weightedFTest -
weightedMccTest
public double weightedMccTest -
weightedRocTest
public double weightedRocTest -
weightedPrcTest
public double weightedPrcTest -
precisionTest
public double[] precisionTest -
recallTest
public double[] recallTest -
tprTest
public double[] tprTest -
fprTest
public double[] fprTest -
fnrTest
public double[] fnrTest -
fTest
public double[] fTest -
mccTest
public double[] mccTest -
rocTest
public double[] rocTest -
prcTest
public double[] prcTest -
confusionMatrixTest
public double[][] confusionMatrixTest -
maeTest
public double maeTest -
rmseTest
public double rmseTest -
raeTest
public double raeTest -
rrseTest
public double rrseTest -
slope
public double slope -
intercept
public double intercept -
corrCoef
public double corrCoef -
ssr
public double ssr -
rSquared
public double rSquared -
dataset
-
model
-
C
public double C -
gamma
public double gamma -
epsilon
public double epsilon -
corrThld
public double corrThld -
learningRate
public double learningRate -
K
public int K -
trainingTime
public int trainingTime -
fold
public int fold -
unit
public int unit -
timeStamp
public long timeStamp -
timeLapse
public long timeLapse -
modelImageGrid
-
accuracyGrid
public double[][] accuracyGrid -
showEvalDetails
public boolean showEvalDetails -
isRegression
public boolean isRegression -
drawModels
public boolean drawModels -
CList
public double[] CList -
gammaList
public double[] gammaList -
EpsList
public double[] EpsList -
KList
public int[] KList -
data
public weka.core.Instances data -
training
public weka.core.Instances training -
attributes
-
colors
public int[] colors
-
-
Constructor Details
-
Weka4P
Weka4P constructor. Use in setup()- Parameters:
parent
- the parent PApplet
-
-
Method Details
-
printVersion
public void printVersion()Print the version of the Library. -
loadTrainARFFToInstances
- Parameters:
filename
- filename of ARFF file in the data folder- Returns:
- instances from the ARFF file
-
loadAttributesFromInstances
Loads attributes form instances- Parameters:
_insts
- instances- Returns:
- Attributes ArrayList
-
loadTrainARFF
Loads ARFF file into public train variable- Parameters:
filename
- filename of ARFF file in the data folder
-
loadTestARFF
Loads ARFF file into public test variable- Parameters:
filename
- filename of ARFF file in the data folder
-
loadCSV
Loads nominal CSV file into global train variable- Parameters:
_filename
- CSV file in data folder
-
loadCSVNumeric
Loads numeric CSV file into global train variable- Parameters:
_filename
- CSV file in data folder
-
saveModel
Combines classifier with filename to save a model- Parameters:
_filename
-
-
saveSVC
Combines classifier with filename to save a model- Parameters:
_filename
-
-
saveClassifier
Saves a model to specified file- Parameters:
_cls
- classifier_filename
- intended filename for model file.
-
getPredictionIndex
public double getPredictionIndex(float[] _features)Gets the prediction index from public test data, uses public attributesTrain- Parameters:
_features
-- Returns:
- prediction index
-
getPredictionIndex
public double getPredictionIndex(float[] _features, weka.classifiers.Classifier _cls, ArrayList<weka.core.Attribute> _attrs)Gets the prediction index from public test data, with specified classifier and attributes- Parameters:
_features
-_cls
-_attrs
-- Returns:
- prediction index
-
getPredictionIndex
public double getPredictionIndex(float[] _features, weka.classifiers.Classifier _cls)Gets the prediction index from public test data, with specified classifier, uses public attributesTrain- Parameters:
_features
-_cls
-- Returns:
- prediction index
-
getPrediction
public String getPrediction(float[] _features, weka.classifiers.Classifier _cls, ArrayList<weka.core.Attribute> _attrs, weka.core.Instances _insts)Gets the label of the prediction- Parameters:
_features
-_cls
-_attrs
-_insts
-- Returns:
- label of the prediction
-
getPrediction
Gets the label of the prediction, with specified classifier- Parameters:
_features
-_cls
-- Returns:
- label of the prediction
-
getPrediction
Gets the label of the prediction from features array- Parameters:
_features
-- Returns:
- label of the prediction
-
loadModel
Loads model file and loads into public cls variable- Parameters:
fileName
- filename of model file in data folder
-
loadModelToClassifier
Loads model into classifier- Parameters:
fileName
-- Returns:
- classifier from model file
-
evaluateTestSet
public void evaluateTestSet(weka.classifiers.Classifier _cls, weka.core.Instances _insts, boolean _isRegression, boolean _showEvalDetails)Evaluates test set and prints results- Parameters:
_cls
-_insts
-_isRegression
-_showEvalDetails
-
-
evaluateTestSet
public void evaluateTestSet(boolean _isRegression, boolean _showEvalDetails)Evaluates test set and prints results- Parameters:
_isRegression
-_showEvalDetails
-
-
evaluateTrainSet
public void evaluateTrainSet(int _fold, boolean _isRegression, boolean _showEvalDetails)Evaluates training set and prints results- Parameters:
_isRegression
-_showEvalDetails
-
-
rankAttrLSVC
public void rankAttrLSVC(double C)Ranks Linear Suport Vector and prints the result- Parameters:
C
-
-
trainMLP
Trains a Multilayer Perceptron Saves it to public cls variable- Parameters:
_hiddenLayers
-_trainingTime
-_learningRate
-
-
trainMLP
Trains a Multilayer Perceptron Saves it to public cls variable- Parameters:
_hiddenLayers
-_trainingTime
-
-
trainLinearRegression
public void trainLinearRegression()Trains Linear Regression and saves it into public cls variable -
trainKNN
public void trainKNN(int K)Trains K-nearest Neighbors saves it into public cls- Parameters:
K
-
-
KSearch
public void KSearch(int[] _KList)Searches for K in array- Parameters:
_KList
- array of K's to search for
-
drawKSearchModels
public void drawKSearchModels(float x, float y, float w, float h)Draws a visualization of the K model at specified location- Parameters:
x
- x coordinatey
- y coordinatew
- widthh
- height
-
drawKSearchResults
public void drawKSearchResults(float x, float y, float w, float h)Draws results of the K model at specified location in text- Parameters:
x
- x coordinatey
- y coordinatew
- widthh
- height
-
trainLinearSVR
public void trainLinearSVR(double epsilon)Trains a Linear Support Vector Regression- Parameters:
epsilon
-
-
trainRBFSVR
public void trainRBFSVR(double epsilon, double gamma) -
trainLinearSVC
public void trainLinearSVC(double C)Trains a Linear Support Vector Clasifier- Parameters:
C
-
-
trainPolySVC
public void trainPolySVC(int exp, double C)Trains a Poly Support Vector Classifier- Parameters:
exp
-C
-
-
trainRBFSVC
public void trainRBFSVC(double gamma, double C) -
saveSVM
Saves a Support Vector Machine- Parameters:
fileName
-
-
setModelDrawing
public void setModelDrawing(int pixelSize)Set te pixel size of model drawing- Parameters:
pixelSize
- Unit of pixels
-
drawModel
public void drawModel(int x, int y)Draws a model image on location- Parameters:
x
-y
-
-
drawPrediction
public void drawPrediction(float[] X, double Y)Draws a prediction with text- Parameters:
X
-Y
-
-
drawPrediction
public void drawPrediction(float[] X, double Y, int c)Draws a prediction in text- Parameters:
X
-Y
-c
- color
-
drawPrediction
Draws a prediction in text- Parameters:
X
-Y
-c
- color
-
drawPrediction
Draws a prediction in text- Parameters:
X
-Y
-
-
drawDataPoints
public void drawDataPoints(weka.core.Instances db)Draws all data points- Parameters:
db
- datapoint instance database
-
drawDataPoints
public void drawDataPoints()Draws all datapoints form public train variable -
getModelImage
public PGraphics getModelImage(PGraphics pg, weka.classifiers.Classifier cls, weka.core.Instances training, int w, int h)Generates the model image graphic- Parameters:
pg
-cls
-training
-w
-h
-- Returns:
- Graphic image
-
CSearchLSVC
public void CSearchLSVC(double[] _CList)Searches for C of a Linear Support Vector Classifier- Parameters:
_CList
- array of C's
-
EpsSearchLSVR
public void EpsSearchLSVR(double[] _EpsList)Searches for Epsilon for a Linear Suport Vector Regressor- Parameters:
_EpsList
-
-
drawCSearchModels
public void drawCSearchModels(float x, float y, float w, float h)Draws a graphic representation of C list- Parameters:
x
-y
-w
-h
-
-
drawCSearchResults
public void drawCSearchResults(float x, float y, float w, float h)Draws the C search results from CList in text- Parameters:
x
-y
-w
-h
-
-
drawEpsSearchModels
public void drawEpsSearchModels(float x, float y, float w, float h)Draws the graphic representation of the Epsilon search from EpsList- Parameters:
x
-y
-w
-h
-
-
drawEpsSearchResults
public void drawEpsSearchResults(float x, float y, float w, float h)Draws the Epsilon Search results in text from Epslist- Parameters:
x
-y
-w
-h
-
-
gridSearchSVR_RBF
public void gridSearchSVR_RBF(double[] _EpsList, double[] _gammaList)- Parameters:
_EpsList
- Epsilon array to search for_gammaList
- gamme array to search for
-
gridSearchSVC_RBF
public void gridSearchSVC_RBF(double[] _CList, double[] _gammaList)- Parameters:
_CList
- C array to search for_gammaList
- Gamma array to search for
-
drawGridSearchModels
public void drawGridSearchModels(float x, float y, float w, float h)Draws graphic represatations of the grid search, uses the CList and gammaList- Parameters:
x
-y
-w
-h
-
-
drawGridSearchModels_SVR
public void drawGridSearchModels_SVR(float x, float y, float w, float h)Draws graphical representation of grid search model of sthe Support Vector Regression Uses EpsList and gammaList- Parameters:
x
-y
-w
-h
-
-
drawGridSearchResults_SVR
public void drawGridSearchResults_SVR(float x, float y, float w, float h)Draws the grid search results of the Support Vector Regression in text- Parameters:
x
-y
-w
-h
-
-
drawGridSearchResults
public void drawGridSearchResults(float x, float y, float w, float h)Draws the grid search results uses Clist and gammaList- Parameters:
x
-y
-w
-h
-
-
readCSVNominal
Reads the CSV file with nominal values- Parameters:
fileName
- filenmae of CSV file in data folder- Throws:
Exception
-