apache-ignite
54 строки · 2.8 Кб
1// Licensed to the Apache Software Foundation (ASF) under one or more
2// contributor license agreements. See the NOTICE file distributed with
3// this work for additional information regarding copyright ownership.
4// The ASF licenses this file to You under the Apache License, Version 2.0
5// (the "License"); you may not use this file except in compliance with
6// the License. You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15= Multiclass Classification
16
17In machine learning, multiclass or multinomial classification is the problem of classifying instances into one of three or more classes.
18
19Currently, Apache Ignite ML support the most popular method of Multiclass classification known as One-vs-Rest.
20
21One-vs-Rest strategy involves training a single classifier per class, with the samples of that class as positive samples and all other samples as negatives.
22
23Internally it uses one dataset but with the different changed labels for each trained classifier. If you have N classes, the N classifiers will be trained to become a MultiClassModel.
24
25MultiClassModel uses soft-margin technique to predict the real label. It means that the MultiClassModel returns the label of the class which is better suited for the predicted vector.
26
27
28== Example
29
30To see how One-vs-Rest trainer parametrized by binary SVM classifier can be used in practice, try this https://github.com/apache/ignite/blob/master/examples/src/main/java/org/apache/ignite/examples/ml/multiclass/OneVsRestClassificationExample.java[example] that is available on GitHub and delivered with every Apache Ignite distribution.
31
32The preprocessed Glass dataset is from the https://archive.ics.uci.edu/ml/datasets/Glass+Identification[UCI Machine Learning Repository].
33
34There are 3 classes with labels: 1 (building_windows_float_processed), 3 (vehicle_windows_float_processed), 7 (headlamps) and feature names: 'Na-Sodium', 'Mg-Magnesium', 'Al-Aluminum', 'Ba-Barium', 'Fe-Iron'.
35
36
37[source, java]
38----
39OneVsRestTrainer<SVMLinearClassificationModel> trainer
40= new OneVsRestTrainer<>(new SVMLinearClassificationTrainer()
41.withAmountOfIterations(20)
42.withAmountOfLocIterations(50)
43.withLambda(0.2)
44.withSeed(1234L)
45);
46
47MultiClassModel<SVMLinearClassificationModel> mdl = trainer.fit(
48ignite,
49dataCache,
50new DummyVectorizer<Integer>().labeled(0)
51);
52
53double prediction = mdl.predict(inputVector);
54----
55
56