0
$\begingroup$

Used a RandomForestClassifier for my prediciton model. But the output printed is either 0 or in decimals. What do I need to do for my model to show me 0 and 1's instead of decimals?

Note: used feature importance and removed the least important columns,still the accuracy is the same and the output hasn't changed much.

Also, i have my estimators equal to 1000. do i increase or decrease this?

edit:

target col
1
0
0
1

output col
0.994
0
0.355
0.768

thanks for reading this, if you did!

$\endgroup$
3
  • $\begingroup$ Welcome to DataScienceSE. Please provide details, in particular code or example (what do you mean by 'decimal output'?), details about the data/task like size. number of classes, distribution,.. $\endgroup$
    – Erwan
    Jun 4 at 15:22
  • $\begingroup$ @Erwan edited the question. does this help? $\endgroup$
    – Pavan
    Jun 4 at 16:42
  • $\begingroup$ Please read: stackoverflow.com/help/minimal-reproducible-example $\endgroup$
    – Rob
    Jun 15 at 8:39

2 Answers 2

1
$\begingroup$

Take the numbers given by the model and threshold them. Everything above X (usually .5) is mapped to 0, everything greater than X is mapped to 1.

$\endgroup$
2
  • $\begingroup$ okay, thanks for this! $\endgroup$
    – Pavan
    Jun 4 at 16:27
  • $\begingroup$ after thresholding, for some reason even the id column changes to the model output. any idea on how to stop this? $\endgroup$
    – Pavan
    Jun 4 at 17:50
1
$\begingroup$

On what data are you training on? Is your training data binary?

If not, then set a treshold when your target variable should be 1 and 0 otherwise. Then train your RandomForestClassifier on the binary labels. Could be that you are training your classifier on a continuous target variable and thats why your performance is so bad.

The generalization error for forests converges a.s. to a limit as the number of trees in the forest becomes large (Breiman, 2001)

More trees = better. However, it's also computationally more expensive. There is a trade-off. Start low ~64 trees and then work your way up, if the generalization error is still high

$\endgroup$
2
  • $\begingroup$ yup, the training data is binary. $\endgroup$
    – Pavan
    Jun 4 at 16:27
  • $\begingroup$ please provide some code $\endgroup$ Jun 4 at 18:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.