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

Class RegressorToClassifier

JSAT/src/jsat/classifiers/RegressorToClassifier.java:24–109  ·  view source on GitHub ↗

This meta algorithm wraps a Regressor to perform binary classification. This is done my labeling class 0 data points as "-1" and class 1 points as "1". The sign of the outputs then determines the class. Not all regression algorithms will work well in this setting, and standard parameter valu

Source from the content-addressed store, hash-verified

22 * @author Edward Raff
23 */
24public class RegressorToClassifier implements BinaryScoreClassifier, Parameterized
25{
26
27 private static final long serialVersionUID = -2607433019826385335L;
28 private Regressor regressor;
29
30 /**
31 * Creates a new Binary Classifier by using the given regressor
32 * @param regressor the regressor to wrap as a binary classifier
33 */
34 public RegressorToClassifier(Regressor regressor)
35 {
36 this.regressor = regressor;
37 }
38
39 @Override
40 public double getScore(DataPoint dp)
41 {
42 return regressor.regress(dp);
43 }
44
45 @Override
46 public RegressorToClassifier clone()
47 {
48 return new RegressorToClassifier(regressor.clone());
49 }
50
51 @Override
52 public CategoricalResults classify(DataPoint data)
53 {
54 CategoricalResults cr = new CategoricalResults(2);
55 if(getScore(data) > 0)
56 cr.setProb(1, 1.0);
57 else
58 cr.setProb(0, 1.0);
59
60 return cr;
61 }
62
63 @Override
64 public void trainC(ClassificationDataSet dataSet, ExecutorService threadPool)
65 {
66 RegressionDataSet rds = getRegressionDataSet(dataSet);
67 regressor.train(rds, threadPool);
68 }
69
70 @Override
71 public void trainC(ClassificationDataSet dataSet)
72 {
73 RegressionDataSet rds = getRegressionDataSet(dataSet);
74 regressor.train(rds);
75 }
76
77 @Override
78 public boolean supportsWeightedData()
79 {
80 return regressor.supportsWeightedData();
81 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected