konstantint / SKompiler

A tool for compiling trained SKLearn models into other representations (such as SQL, Sympy or Excel formulas)
MIT License
171 stars 10 forks source link

Export weights of a Random Forest #10

Closed PARODBE closed 2 years ago

PARODBE commented 2 years ago

With this library, would be possible extract the weights of a Random Fores as for example in suppor vector machine or PLS or Neural Network? In this case, could you provide me some code, for after load the weights and training your model.

Thanks! Pablo

konstantint commented 2 years ago

I am not sure I completely understand the question. A couple of possibly related remarks:

PARODBE commented 2 years ago

Thanks for so rapid answer!. When I do this:

image

Being my dataset, the iris_dataset. I obtain the next error:

image

However the shape of my inputs is:

image

Could you help me please?

Thanks!

konstantint commented 2 years ago

SKompiler expects the inputs argument to provide a list of symbolic arguments that will be referred to in the expression being generated. E.g.

from skompiler.dsl import ident
inputs = [ident('a'), ident('b'), ident('c'), ident('d')]

could probably work out in your case.

I don't see however how your current actions will help you in your quest. I suggested you to look at SKompiler code in the sense that it might help you better understand the internal data structures of SKLearn (e.g. you can see that the loop in the function goes over model.estimators_ which can be a useful hint here). Just running it is probably not going to help.