/**
* 最小二乘回归树 缺失属性还没想好怎么处理好
* @author ysh 1208706282
*
*/
public class Cart {
static double MISSINGDATA = -111111111;
int mMaxDepth; //设定的最大深度
int mMinLeaf; //节点最小样本数
double mFeatureRate; //属性选择比率
List<Sample> mSamples;
Random mRandom;
Node mParent; //回归树根节点
static class Sample{
Double label;
List<Double> feature;
}
static class Node{
List<Sample> samples;
int depth;
int featureId;
double splitValue;
double fitness;
double predict;
Node childs[];
boolean leaf;
}
/**
* 加载数据 回归树
* @param path
* @param regex
* @throws Exception
*/
public void loadData(String path,String regex) throws Exception{
mSamples = new ArrayList<Sample>();
BufferedReader reader = new BufferedReader(new FileReader(path));
String line = null;
String splits[] = null;
Sample sample = null;
while(null != (line=reader.readLine())){
splits = line.split(regex);
sample = new Sample();
sample.label = Double.valueOf(splits[0]);
sample.feature = new ArrayList<Double>(splits.length-1);
for(int i=0;i<splits.length-1;i++){
sample.feature.add(new Double(splits[i+1]));
}
mSamples.add(sample);
}
reader.close();
}
public void setData(List<Sample> samples){
this.mSamples = samples;
}
/**
* 加载验证测试集
* @param path
* @param regex
* @throws Exception
*/
public static List<Sample> loadTestData(String path,boolean hasLabel,String regex) throws Exception{
List<Sample> samples = new ArrayList<Sample>();
BufferedReader reader = new BufferedReader(new FileReader(path));
String line = null;
String splits[] = null;
Sample sample = null;
while(null != (line=reader.readLine())){
splits = line.split(regex);
sample
* 最小二乘回归树 缺失属性还没想好怎么处理好
* @author ysh 1208706282
*
*/
public class Cart {
static double MISSINGDATA = -111111111;
int mMaxDepth; //设定的最大深度
int mMinLeaf; //节点最小样本数
double mFeatureRate; //属性选择比率
List<Sample> mSamples;
Random mRandom;
Node mParent; //回归树根节点
static class Sample{
Double label;
List<Double> feature;
}
static class Node{
List<Sample> samples;
int depth;
int featureId;
double splitValue;
double fitness;
double predict;
Node childs[];
boolean leaf;
}
/**
* 加载数据 回归树
* @param path
* @param regex
* @throws Exception
*/
public void loadData(String path,String regex) throws Exception{
mSamples = new ArrayList<Sample>();
BufferedReader reader = new BufferedReader(new FileReader(path));
String line = null;
String splits[] = null;
Sample sample = null;
while(null != (line=reader.readLine())){
splits = line.split(regex);
sample = new Sample();
sample.label = Double.valueOf(splits[0]);
sample.feature = new ArrayList<Double>(splits.length-1);
for(int i=0;i<splits.length-1;i++){
sample.feature.add(new Double(splits[i+1]));
}
mSamples.add(sample);
}
reader.close();
}
public void setData(List<Sample> samples){
this.mSamples = samples;
}
/**
* 加载验证测试集
* @param path
* @param regex
* @throws Exception
*/
public static List<Sample> loadTestData(String path,boolean hasLabel,String regex) throws Exception{
List<Sample> samples = new ArrayList<Sample>();
BufferedReader reader = new BufferedReader(new FileReader(path));
String line = null;
String splits[] = null;
Sample sample = null;
while(null != (line=reader.readLine())){
splits = line.split(regex);
sample