In: Statistics and Probability
Make a set of boosted predictions on the response variable medv for the Boston dataset in the MASS package, by first fitting the KNN model, then correcting the residuals using a singlelayer neural network with the shrinkage parameter λ = 0.1, then correcting the residuals using a random forest with shrinkage λ = 0.1. In each step, use 5-fold cross validation to tune the parameters: k (k = 5, 10, 20) in KNN, number of neurons in the hidden layer (hidden = 3, 5, 7) in the single-layer neural network, and mtry (m = 3, 6, 9, 12) in the random forest. At the end, compare the three sets of residuals by some plots.
import java.util.ArrayList;
import java.util.List;
public category Cluster purpose centroid;
public int id;
//Creates a replacement Cluster
public Cluster(int id)
public List getPoints() come points;
}
public void addPoint(Point point)
public void setPoints(List points)
public purpose getCentroid() come centroid;
}
public void setCentroid(Point centroid) ;
}
public int getId()
public void clear()
public void plotCluster()
System.out.println("]");
}
}
Point.java
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public category purpose non-public double x = 0;
personal double y = 0;
personal int cluster_number = 0;
public Point(double x, double y)
public void setX(double x)
public double getX() come back this.x;
}
public void setY(double y)
public double getY() come back this.y;
}
public void setCluster(int n)
public int getCluster() come back this.cluster_number;
}
//Calculates the space between 2 points.
protected static double distance(Point p, purpose centroid) come
back science.sqrt(Math.pow((centroid.getY() - p.getY()), 2) +
Math.pow((centroid.getX() - p.getX()), 2));
}
//Creates random purpose
protected static purpose createRandomPoint(int min, int max) come
back new Point(x,y);
}
protected static List createRandomPoints(int min, int max, int
number)
come points;
}
public String toString() come "("+x+","+y+")";
}
}
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public category purpose {
personal double x = 0;
personal double y = 0;
personal int cluster_number = 0;
public Point(double x, double y)
public void setX(double x)
public double getX() come back this.x;
}
public void setY(double y)
public double getY() come back this.y;
}
public void setCluster(int n)
public int getCluster() come back this.cluster_number;
}
//Calculates the space between 2 points.
protected static double distance(Point p, purpose centroid) come
back science.sqrt(Math.pow((centroid.getY() - p.getY()), 2) +
Math.pow((centroid.getX() - p.getX()), 2));
}
//Creates random purpose
protected static purpose createRandomPoint(int min, int max) come
back new Point(x,y);
}
protected static List createRandomPoints(int min, int max, int
number)
come points;
}
public String toString() come "("+x+","+y+")";
}
}