Hello,
I have started working on a Random Forests implementation in OCaml recently.
The classifier is supposed to work now.
Some caveats:
this is pretty slow (and I don’t know so much how to accelerate it).
This is probably two orders of magnitude slower than sklearn ! Shame on me.
this is not super generic (integer class labels, int IntMap sparse features) only
there is no regressor yet (only the classifier)
If you know how to make this significantly faster, I am interested.
The interface file, implementation and test files might be of interest
(* Copyright (C) 2021, Francois Berenger
Tsuda laboratory, Tokyo university,
5-1-5 Kashiwa-no-ha, Kashiwa-shi, Chiba-ken, 277-8561, Japan. *)
(* Random Forets Classifier *)
module A = BatArray
module Ht = BatHashtbl
module IntMap = BatMap.Int
module IntSet = BatSet.Int
module L = BatList
module Log = Dolog.Log
module Rand = BatRandom.State
open Printf
type features = int IntMap.t
type class_label = int
This file has been truncated. show original
(* Copyright (C) 2021, Francois Berenger
Tsuda laboratory, Tokyo university,
5-1-5 Kashiwa-no-ha, Kashiwa-shi, Chiba-ken, 277-8561, Japan. *)
module A = BatArray
module CLI = Minicli.CLI
module IntMap = BatMap.Int
module L = BatList
module LO = Line_oriented
module Log = Dolog.Log
module RFC = Orf.RFC
module S = BatString
open Printf
let label_of_string = int_of_string
let features_of_str_tokens toks =
L.fold_left (fun acc tok_str ->
This file has been truncated. show original
I don’t claim this code is completely free from bugs.
I felt it was quite hard to write (or, I just wasn’t in my best programming shape).
Regards,
F.
7 Likes
n4323
June 16, 2021, 8:42am
2
2x slower than sklearn means 2x slower than a state of the art C implementation, no? isn’t that the kind of performance we should expect to be able to get at best?
1 Like
I corrected this sentence: my implementation is about “two orders of magnitude” slower than sklearn.
n4323
June 17, 2021, 12:11pm
4
ouch… in case someone figures out how to optimize this i would sure like to learn how to do that!