Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How to solve this question by using R Language? You can attach the Boston data s

ID: 3812949 • Letter: H

Question

How to solve this question by using R Language?

You can attach the Boston data set in the MASS package.

library(MASS)

attach(Boston)

For the Boston data set, we are interested in predicting whether a given suburb has a

crime rate above or below the median given other information in the data.

(a) Conduct the logistic regression analysis using all the predictors. To do the pre-

diction, use the first 405 rows as the training set and the rest as the test set.

Describe your result, include the error table and report the test error rate.

(b) Employ the LDA method using all the predictors. To do the prediction, use the

first 405 rows as the training set and the rest as the test set. Describe your result,

include the error table and report the test error rate.

(c) Employ KNN method using all the predictors. To do the prediction, use the first

405 rows as the training set and the rest as the test set. Use 5 fold cross-validation

to choose k by splitting the training set into 5 equal-sized subsets. What is the

optimal value of k? Describe your result, include the error table and report the

test error rate.

(d) Which method is the best? Logistic regression, LDA or KNN? Why?

(e) For the logistic regression in (a), perform forward and backward model selections

[Hint: you can use the step() function in R]. Repeat (a) using only the selected

predictors. Compare the full model and selected model(s), which model is better

and why?

Explanation / Answer

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+")";
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote