Optimize weighted random forest