Package weka.classifiers.trees.j48
Class Distribution
java.lang.Object
weka.classifiers.trees.j48.Distribution
- All Implemented Interfaces:
Serializable
,Cloneable
,RevisionHandler
Class for handling a distribution of class values.
- Version:
- $Revision: 15122 $
- Author:
- Eibe Frank (eibe@cs.waikato.ac.nz)
- See Also:
-
Constructor Summary
ConstructorDescriptionDistribution
(double[][] table) Creates and initializes a new distribution using the given array.Distribution
(int numBags, int numClasses) Creates and initializes a new distribution.Distribution
(Distribution toMerge) Creates distribution with only one bag by merging all bags of given distribution.Distribution
(Distribution toMerge, int index) Creates distribution with two bags by merging all bags apart of the indicated one.Distribution
(Instances source) Creates a distribution with only one bag according to instances in source.Distribution
(Instances source, ClassifierSplitModel modelToUse) Creates a distribution according to given instances and split model. -
Method Summary
Modifier and TypeMethodDescriptionfinal int
Returns number of non-empty bags of distribution.final int
Returns number of classes actually occuring in distribution.final int
actualNumClasses
(int bagIndex) Returns number of classes actually occuring in given bag.final void
add
(int bagIndex, double[] counts) Adds counts to given bag.final void
Adds given instance to given bag.final void
addInstWithUnknown
(Instances source, int attIndex) Adds all instances with unknown values for given attribute, weighted according to frequency of instances in each bag.final void
Adds all instances in given range to given bag.final void
addWeights
(Instance instance, double[] weights) Adds given instance to all bags weighting it according to given weights.final boolean
check
(double minNoObj) Checks if at least two bags contain a minimum number of instances.final Object
clone()
Clones distribution (Deep copy of distribution).final void
Deletes given instance from given bag.final void
Deletes all instances in given range from given bag.final String
Prints distribution.Returns the revision string.final void
Sets all counts to zero.final double
laplaceProb
(int classIndex) Returns relative frequency of class over all bags with Laplace correction.final double
laplaceProb
(int classIndex, int intIndex) Returns relative frequency of class for given bag.final double[][]
matrix()
Returns matrix with distribution of class values.final int
maxBag()
Returns index of bag containing maximum number of instances.final int
maxClass()
Returns class with highest frequency over all bags.final int
maxClass
(int index) Returns class with highest frequency for given bag.final int
numBags()
Returns number of bags.final int
Returns number of classes.final double
Returns perClass(maxClass()).final double
numCorrect
(int index) Returns perClassPerBag(index,maxClass(index)).final double
Returns total-numCorrect().final double
numIncorrect
(int index) Returns perBag(index)-numCorrect(index).final double
perBag
(int bagIndex) Returns number of (possibly fractional) instances in given bag.final double
perClass
(int classIndex) Returns number of (possibly fractional) instances of given class.final double
perClassPerBag
(int bagIndex, int classIndex) Returns number of (possibly fractional) instances of given class in given bag.final double
prob
(int classIndex) Returns relative frequency of class over all bags.final double
prob
(int classIndex, int intIndex) Returns relative frequency of class for given bag.final void
Shifts given instance from one bag to another one.final void
shiftRange
(int from, int to, Instances source, int startIndex, int lastPlusOne) Shifts all instances in given range from one bag to another one.final void
Subtracts given instance from given bag.final Distribution
subtract
(Distribution toSubstract) Subtracts the given distribution from this one.final double
total()
Returns total number of (possibly fractional) instances.
-
Constructor Details
-
Distribution
public Distribution(int numBags, int numClasses) Creates and initializes a new distribution. -
Distribution
public Distribution(double[][] table) Creates and initializes a new distribution using the given array. WARNING: it just copies a reference to this array. -
Distribution
Creates a distribution with only one bag according to instances in source.- Throws:
Exception
- if something goes wrong
-
Distribution
Creates a distribution according to given instances and split model.- Throws:
Exception
- if something goes wrong
-
Distribution
Creates distribution with only one bag by merging all bags of given distribution. -
Distribution
Creates distribution with two bags by merging all bags apart of the indicated one.
-
-
Method Details
-
actualNumBags
public final int actualNumBags()Returns number of non-empty bags of distribution. -
actualNumClasses
public final int actualNumClasses()Returns number of classes actually occuring in distribution. -
actualNumClasses
public final int actualNumClasses(int bagIndex) Returns number of classes actually occuring in given bag. -
add
Adds given instance to given bag.- Throws:
Exception
- if something goes wrong
-
sub
Subtracts given instance from given bag.- Throws:
Exception
- if something goes wrong
-
add
public final void add(int bagIndex, double[] counts) Adds counts to given bag. -
addInstWithUnknown
Adds all instances with unknown values for given attribute, weighted according to frequency of instances in each bag.- Throws:
Exception
- if something goes wrong
-
addRange
public final void addRange(int bagIndex, Instances source, int startIndex, int lastPlusOne) throws Exception Adds all instances in given range to given bag.- Throws:
Exception
- if something goes wrong
-
addWeights
Adds given instance to all bags weighting it according to given weights.- Throws:
Exception
- if something goes wrong
-
check
public final boolean check(double minNoObj) Checks if at least two bags contain a minimum number of instances. -
clone
Clones distribution (Deep copy of distribution). -
del
Deletes given instance from given bag.- Throws:
Exception
- if something goes wrong
-
delRange
public final void delRange(int bagIndex, Instances source, int startIndex, int lastPlusOne) throws Exception Deletes all instances in given range from given bag.- Throws:
Exception
- if something goes wrong
-
dumpDistribution
Prints distribution. -
initialize
public final void initialize()Sets all counts to zero. -
matrix
public final double[][] matrix()Returns matrix with distribution of class values. -
maxBag
public final int maxBag()Returns index of bag containing maximum number of instances. -
maxClass
public final int maxClass()Returns class with highest frequency over all bags. -
maxClass
public final int maxClass(int index) Returns class with highest frequency for given bag. -
numBags
public final int numBags()Returns number of bags. -
numClasses
public final int numClasses()Returns number of classes. -
numCorrect
public final double numCorrect()Returns perClass(maxClass()). -
numCorrect
public final double numCorrect(int index) Returns perClassPerBag(index,maxClass(index)). -
numIncorrect
public final double numIncorrect()Returns total-numCorrect(). -
numIncorrect
public final double numIncorrect(int index) Returns perBag(index)-numCorrect(index). -
perClassPerBag
public final double perClassPerBag(int bagIndex, int classIndex) Returns number of (possibly fractional) instances of given class in given bag. -
perBag
public final double perBag(int bagIndex) Returns number of (possibly fractional) instances in given bag. -
perClass
public final double perClass(int classIndex) Returns number of (possibly fractional) instances of given class. -
laplaceProb
public final double laplaceProb(int classIndex) Returns relative frequency of class over all bags with Laplace correction. -
laplaceProb
public final double laplaceProb(int classIndex, int intIndex) Returns relative frequency of class for given bag. -
prob
public final double prob(int classIndex) Returns relative frequency of class over all bags. -
prob
public final double prob(int classIndex, int intIndex) Returns relative frequency of class for given bag. -
subtract
Subtracts the given distribution from this one. The results has only one bag. -
total
public final double total()Returns total number of (possibly fractional) instances. -
shift
Shifts given instance from one bag to another one.- Throws:
Exception
- if something goes wrong
-
shiftRange
public final void shiftRange(int from, int to, Instances source, int startIndex, int lastPlusOne) throws Exception Shifts all instances in given range from one bag to another one.- Throws:
Exception
- if something goes wrong
-
getRevision
Returns the revision string.- Specified by:
getRevision
in interfaceRevisionHandler
- Returns:
- the revision
-