g3rv4 / RandomForest

A tiny library to run in C# random forests created in R
MIT License
12 stars 2 forks source link

Request? #1

Closed codemasta14 closed 5 years ago

codemasta14 commented 5 years ago

Hello! I'm not sure how much work you are interested in doing on this package, but something that would be extremely helpful is if the predict function had a input such as in R

predict(my_model,training,type = 'prob')

To return the probability of a random forest. I would offer to work on it myself, but I do not do c#.

g3rv4 commented 5 years ago

Hey there! As you've probably seen, I haven't worked on this on a long time. I just wanted to see if I could make this fairly efficiently, but I never ended up using it anywhere.

Are you using it somehow?

And... if you had all the trees, how would you calculate the "probability of a random forest"?

codemasta14 commented 5 years ago

I see, I am using it, just with it's intended use, to take a model I trained in R, to move it into c#. Calculating the probability of a random forest means if you have 40 trees voting true and 60 false, your random forest would return a false prediction. If it returned a probability, it would return .4, or 40%.

g3rv4 commented 5 years ago

oh, so for your particular data, return that probability... that should be fairly straightforward :) I'll see if I can find out some time to work on it.

g3rv4 commented 5 years ago

Alright, I was able to put together a proof of concept. I'll work on it on the weekend :)

codemasta14 commented 5 years ago

That's amazing! Thank you so much! This is helping me out a great deal, and so I really appreciate it!

g3rv4 commented 5 years ago

Done! This has been implemented on the 0.2.2 version (available for update on nuget), and the way you use it is as if you wanted to get a prediction,

var cSharpProbabilities = classificationRF.GetProbabilities(item);

You can see an example here, where I verified that the results obtained by the c# code match what R returns.

codemasta14 commented 5 years ago

That's amazing! Thank you so much!

g3rv4 commented 5 years ago

<3