flink-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kürşat Kurt <kur...@kursatkurt.com>
Subject SVM Multiclass classification
Date Thu, 13 Oct 2016 18:52:20 GMT
Hi;

 

I am trying to classify documents. 

When i try to predict (same of training set) there is only 1 and -1
predictions.

Accuracy is 0%.

 

 

Can you help me please?

 

val env = ExecutionEnvironment.getExecutionEnvironment

    val training = Seq(

      new LabeledVector(1.0, new SparseVector(10, Array(0, 2, 3), Array(1.0,
1.0, 1.0))),

      new LabeledVector(1.0, new SparseVector(10, Array(0, 1, 5, 9),
Array(1.0, 1.0, 1.0, 1.0))),

      new LabeledVector(0.0, new SparseVector(10, Array(0, 2), Array(0.0,
1.0))),

      new LabeledVector(0.0, new SparseVector(10, Array(0), Array(0.0))),

      new LabeledVector(2.0, new SparseVector(10, Array(0, 2), Array(0.0,
1.0))),

      new LabeledVector(2.0, new SparseVector(10, Array(0), Array(0.0))),

      new LabeledVector(1.0, new SparseVector(10, Array(0, 3), Array(1.0,
1.0))),

      new LabeledVector(0.0, new SparseVector(10, Array(0, 2, 3), Array(0.0,
1.0, 1.0))),

      new LabeledVector(2.0, new SparseVector(10, Array(0, 7, 9), Array(0.0,
1.0))),

      new LabeledVector(2.0, new SparseVector(10, Array(2,3,4),
Array(0.0,1.0,1.0))),

      new LabeledVector(2.0, new SparseVector(10, Array(0, 3), Array(1.0,
1.0))),

      new LabeledVector(0.0, new SparseVector(10, Array(2, 3,9), Array(1.0,
0.0, 1.0)))

    

    );

    val trainingDS = env.fromCollection(training)

    val testingDS = env.fromCollection(training)

    val svm = new SVM().setBlocks(env.getParallelism)

    svm.fit(trainingDS)    

    val predictions = svm.evaluate(testingDS.map(x => (x.vector, x.label)))

    predictions.print();

 

Sample output:

 

(1.0,1.0)

(1.0,1.0)

(0.0,1.0)

(0.0,-1.0)

(2.0,1.0)

(2.0,-1.0)

(1.0,1.0)

(0.0,1.0)

(2.0,1.0)

(2.0,1.0)

(2.0,1.0)

(0.0,1.0)


Mime
View raw message