Commits

Oliver Gu  committed 783f6da

Updated xor example.

  • Participants
  • Parent commits 3c48ae6

Comments (0)

Files changed (1)

File examples/xor.ml

-open Core.Std
 open Lacaml.D
 open Libsvm
 
       [| 1.; 1. |];
     |]
   in
-  let target = Vec.of_array [| 0.; 1.; 1.; 0. |] in
-  let problem = Svm.Problem.create ~x ~y:target in
-  let model = Svm.train problem in
-  let preds = Svm.predict model ~x in
-  Array.iter2_exn (Mat.to_array x) (Vec.to_array preds) ~f:(fun x y ->
-    printf "(%1.0f, %1.0f) -> %1.0f\n" x.(0) x.(1) y)
+  let targets = Vec.of_array [| 0.; 1.; 1.; 0. |] in
+  let problem = Svm.Problem.create ~x ~y:targets in
+  let model = Svm.train ~kernel:`RBF problem in
+  let y = Svm.predict model ~x in
+  for i = 1 to 4 do
+    Printf.printf "(%1.0f, %1.0f) -> %1.0f\n" x.{i,1} x.{i,2} y.{i}
+  done