com.actelion.research.calc.regression.randomforest.RandomForestRegression Maven / Gradle / Ivy
Show all versions of openchemlib Show documentation
package com.actelion.research.calc.regression.randomforest;
import com.actelion.research.calc.Matrix;
import com.actelion.research.calc.regression.ARegressionMethod;
import com.actelion.research.util.datamodel.ModelXYIndex;
import smile.regression.RandomForest;
/**
* RandomForestRegression
* Modest v. Korff
*
* Created by korffmo1 on 14.01.19.
*/
public class RandomForestRegression extends ARegressionMethod implements Comparable {
public static final int MIN_NUM_VAR_SPLIT = 3;
private RandomForest forest;
public RandomForestRegression() {
setParameterRegressionMethod(new ParameterRandomForest());
// To prevent multi-core execution on Random Forest level
// On the grid permission is denied.
try {
System.setProperty("smile.threads", "1");
} catch (Exception e) {
e.printStackTrace();
}
}
public RandomForestRegression(ParameterRandomForest parameterRandomForest) {
setParameterRegressionMethod(parameterRandomForest);
}
@Override
public Matrix createModel(ModelXYIndex modelXYIndexTrain) {
Matrix YHat = null;
try {
ParameterRandomForest parameterRandomForest = getParameter();
int mTry = (int)(modelXYIndexTrain.X.cols() * parameterRandomForest.getFractionMTry()+0.5);
if(mTry