(* KNN version simple *) let nb_cl = 3;; (* nombre de classes ; de 0 à nb_cl - 1 *) let data = [| (* ensemble d'entrainement *) ([| 149. ; 304. |], 0); ([| 207. ; 346. |], 0); ([| 79. ; 155. |], 0); ([| 257. ; 287. |], 0); ([| 499. ; 86. |], 0); ([| 432. ; 309. |], 0); ([| 498. ; 343. |], 0); ([| 356. ; 178. |], 0); ([| 401. ; 224. |], 0); ([| 75. ; 119. |], 0); ([| 334. ; 338. |], 0); ([| 374. ; 242. |], 0); ([| 608. ; 378. |], 1); ([| 310. ; 496. |], 1); ([| 610. ; 485. |], 1); ([| 544. ; 298. |], 1); ([| 550. ; 483. |], 1); ([| 670. ; 227. |], 1); ([| 719. ; 237. |], 1); ([| 673. ; 386. |], 1); ([| 319. ; 359. |], 1); ([| 560. ; 252. |], 1); ([| 395. ; 250. |], 1); ([| 299. ; 529. |], 1); ([| 449. ; 533. |], 1); ([| 463. ; 387. |], 1); ([| 265. ; 324. |], 1); ([| 716. ; 429. |], 1); ([| 481. ; 371. |], 1); ([| 502. ; 280. |], 1); ([| 428. ; 623. |], 1); ([| 355. ; 424. |], 1); ([| 796. ; 301. |], 2); ([| 938. ; 430. |], 2); ([| 507. ; 320. |], 2); ([| 519. ; 336. |], 2); ([| 573. ; 269. |], 2); ([| 557. ; 198. |], 2); ([| 761. ; 285. |], 2); ([| 829. ; 434. |], 2); ([| 522. ; 182. |], 2); ([| 766. ; 105. |], 2); ([| 803. ; 124. |], 2); ([| 884. ; 420. |], 2); ([| 769. ; 235. |], 2); ([| 912. ; 151. |], 2); ([| 833. ; 387. |], 2); |];; (* distance entre deux points *) let dist pt1 pt2 = ();; (* classifieur knn *) let classifie k data pt = ();; (* couleurs associées aux classes / zones*) let cz0 = Graphics.rgb 50 250 50;; let cp0 = Graphics.rgb 35 175 35;; let cz1 = Graphics.rgb 250 50 50;; let cp1 = Graphics.rgb 175 35 35;; let cz2 = Graphics.rgb 50 50 250;; let cp2 = Graphics.rgb 35 35 175;; let set_color_of_classe cl z = let couleur = match cl with | 0 -> if z then cz0 else cp0 | 1 -> if z then cz1 else cp1 | 2 -> if z then cz2 else cp2 | _ -> Graphics.white in Graphics.set_color couleur;; (* affichage d'un ensemble d'entraînement *) let affichage_points data = Graphics.set_line_width 3; for i = 0 to Array.length data - 1 do let coord, cl = data.(i) in set_color_of_classe cl false; Graphics.draw_rect (int_of_float coord.(0)-1) (int_of_float coord.(1)-1) 3 3 done;; (* Affichage *) Graphics.open_graph " 1000x700" ; (* ouverture de la fenetre graphique *) affichage_points data;; Graphics.read_key ();; (* attente d'une saisie clavier *)