This classifier turns any classifier, specifically binary classifiers, into multi-class classifiers. For a problem with k target classes, OneVsALl will create k different classifiers. Each one is a reducing of one class against all other classes. Then all k classifiers's results
| 27 | * @author Edward Raff |
| 28 | */ |
| 29 | public class OneVSAll implements Classifier, Parameterized |
| 30 | { |
| 31 | |
| 32 | private static final long serialVersionUID = -326668337438092217L; |
| 33 | private Classifier[] oneVsAlls; |
| 34 | @ParameterHolder |
| 35 | private Classifier baseClassifier; |
| 36 | private CategoricalData predicting; |
| 37 | private boolean concurrentTraining; |
| 38 | private boolean useScoreIfAvailable = true; |
| 39 | |
| 40 | /** |
| 41 | * Creates a new One VS All classifier. |
| 42 | * |
| 43 | * @param baseClassifier the base classifier to replicate |
| 44 | * @see #setConcurrentTraining(boolean) |
| 45 | */ |
| 46 | public OneVSAll(Classifier baseClassifier) |
| 47 | { |
| 48 | this(baseClassifier, true); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Creates a new One VS All classifier. |
| 53 | * |
| 54 | * @param baseClassifier the base classifier to replicate |
| 55 | * @param concurrentTraining controls whether or not classifiers are trained |
| 56 | * simultaneously or using sequentially using their |
| 57 | * {@link Classifier#trainC(jsat.classifiers.ClassificationDataSet, java.util.concurrent.ExecutorService) } method. |
| 58 | * @see #setConcurrentTraining(boolean) |
| 59 | */ |
| 60 | public OneVSAll(Classifier baseClassifier, boolean concurrentTraining) |
| 61 | { |
| 62 | this.baseClassifier = baseClassifier; |
| 63 | this.concurrentTraining = concurrentTraining; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Controls what method of parallel training to use when |
| 68 | * {@link #trainC(jsat.classifiers.ClassificationDataSet, java.util.concurrent.ExecutorService) } |
| 69 | * is called. If set to true, each of the <i>k</i> classifiers will be trained in parallel, using |
| 70 | * their serial algorithms. If set to false, the <i>k</i> classifiers will be trained sequentially, |
| 71 | * calling the {@link Classifier#trainC(jsat.classifiers.ClassificationDataSet, java.util.concurrent.ExecutorService) } |
| 72 | * for each classifier. <br> |
| 73 | * <br> |
| 74 | * This should be set to true for classifiers that do not support parallel training.<br> |
| 75 | * Setting this to true also uses <i>k</i> times the memory, since each classifier is being created and trained at the same time. |
| 76 | * @param concurrentTraining whether or not to train the classifiers in parallel |
| 77 | */ |
| 78 | public void setConcurrentTraining(boolean concurrentTraining) |
| 79 | { |
| 80 | this.concurrentTraining = concurrentTraining; |
| 81 | } |
| 82 | |
| 83 | |
| 84 | @Override |
| 85 | public CategoricalResults classify(DataPoint data) |
| 86 | { |
nothing calls this directly
no outgoing calls
no test coverage detected