MCPcopy Create free account
hub / github.com/EdwardRaff/JSAT / PriorClassifier

Class PriorClassifier

JSAT/src/jsat/classifiers/PriorClassifier.java:12–73  ·  view source on GitHub ↗

A Naive classifier that simply returns the prior probabilities as the classification decision. @author Edward Raff

Source from the content-addressed store, hash-verified

10 * @author Edward Raff
11 */
12public class PriorClassifier implements Classifier
13{
14
15 private static final long serialVersionUID = 7763388716880766538L;
16 private CategoricalResults cr;
17
18 /**
19 * Creates a new PriorClassifeir
20 */
21 public PriorClassifier()
22 {
23 }
24
25 /**
26 * Creates a new Prior Classifier that is given the results it should be
27 * returning
28 *
29 * @param cr the prior probabilities for classification
30 */
31 public PriorClassifier(CategoricalResults cr)
32 {
33 this.cr = cr;
34 }
35
36 @Override
37 public CategoricalResults classify(DataPoint data)
38 {
39 if(cr == null)
40 throw new UntrainedModelException("PriorClassifier has not been trained");
41 return cr;
42 }
43
44 @Override
45 public void trainC(ClassificationDataSet dataSet, ExecutorService threadPool)
46 {
47 trainC(dataSet);
48 }
49
50 @Override
51 public void trainC(ClassificationDataSet dataSet)
52 {
53 cr = new CategoricalResults(dataSet.getPredicting().getNumOfCategories());
54 for(int i = 0; i < dataSet.getSampleSize(); i++)
55 cr.incProb(dataSet.getDataPointCategory(i), dataSet.getDataPoint(i).getWeight());
56 cr.normalize();
57 }
58
59 @Override
60 public boolean supportsWeightedData()
61 {
62 return true;
63 }
64
65 @Override
66 public Classifier clone()
67 {
68 PriorClassifier clone = new PriorClassifier();
69 if(this.cr != null)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected