### Our Services

Get 15% Discount on your First Order

# check the attachements Please read the instructions and questions carefully in ” Assignment_4_2023_Fall.pdf” file and use “Auto.csv” to

check the attachements

Please read the instructions and questions carefully in ” Assignment_4_2023_Fall.pdf” file and use “Auto.csv” to finish the assignment. You should submit both 1) an R code ; 2) A PDF report with answers through the link “Submit Assignment 4 Here”

Guidelines:

· Use only R for this assignment

· Submit both R code and Report on findings

· Work is to be done individually for this assignment

Fitting a Classification Tree

1.
This problem involves the OJ data set which is part of the ISLR package (
Hint: the first three lines of codes should be: library (tree), library (ISLR), attach (OJ)).

1.1 Create a training set containing a random sample of 800 observations, and a test set containing the remaining observations. Take a screenshot of your code. (Hint: set.seed (2), train=sample())

1.2 Fit a tree to
the training data, with
Purchase as the response and the other variables as predictors. Use the summary( ) function to produce summary statistics about the tree. Take a screenshot of the summary statistics. How many terminal nodes does the tree have? What is the training misclassification error rate?

1.3 Plot the tree and take a screenshot of the tree (Hint: plot() and text())

1.4 Predict the response on the test data, and produce a confusion matrix comparing the test labels to the predicted test labels. What is the accuracy rate?

1.5 Apply the cv.tree() function to the training set in order to determine the optimal tree size. (Use set.seed(7)). Print the results (Hint: the results should contain the size, k, method etc).

1.6 Produce a plot with tree size (i.e. size) on the x-axis and cross-validated classification error rate (i.e. dev) on the y-axis.

1.7 Which tree size corresponds to the lowest cross-validated classification error rate (i.e. dev)?

1.8 Produce a pruned tree corresponding to the optimal tree size obtained using cross-validation. Take a screenshot of a pruned tree. What is the accuracy rate for the pruned tree? Is it improved compared to the accuracy rate in (1.4)?

1.9 If cross-validation does not lead to selection of a pruned tree (i.e. the accuracy rate produced in (1.8) is lower than the one in (1.4)), then create a pruned tree with five terminal nodes. What is the accuracy rate now?

1

Fitting a Regression Tree

2.
In the lab, a classification tree was applied to the Carseats data set after converting Sales into a qualitative response variable. Now we will seek to predict Sales using regression trees and related approaches, treating the response as a quantitative variable.

2.1 Using the validation-set approach to split the data set into a training set and a test set (Hint:
use set.seed(2); validation-set approach: half of the observations are selected as the training dataset while half of observations are treated as the test dataset). Take a screenshot of your code.

2.2 Fit a regression tree to the training set.

a) Use summary () to print out the results. How many terminal nodes do you get? What is RMD (Residual Mean Deviance)?

b) Plot the tree and take a screenshot of the tree;

c) What test MSE do you obtain?

2.3 Use cross-validation in order to determine the optimal level of tree complexity (use set.seed(2)).

a) Produce a plot with tree size on the x-axis and cross-validated classification error rate on the y-axis.

b) What is the optimal level of tree complexity?

c) Using the optimal level of tree size to prune the tree, does pruning the tree improve the test MSE?

2.4 Use the bagging approach in order to analyze this data. Take a screenshot of the results. What test MSE do you obtain? (Hint: use set.seed (1);
mtry=10 since we have 10 predictors in Carseats dataset and we use all of the predictors in the bagging approach).

2.5 Use random forests to analyze this data.

a) What test MSE do you obtain? (Hint: use set.seed(1);
mtry=10/3 since we usually use 1/3 of the predictors when building a random forest of regression trees)

b) Use the importance() function to determine which variables are most important. Take a screenshot of your results.

c) Plots of these importance measures can be produced using the varImpPlot() function. Take a screenshot of your output.

d) So which variables are most important?

What to submit:

1. R code.

a.

b.

c.

d.

2. Report.

a.

b.

c.

d.

e.

Should include all the code to accomplish the tasks.

Clear and concise comments to indicate what part of the assignment each code chunk pertains to.

Filename should be in the format of: LastnameFirstname_A4.R

Take screenshots of your outputs in R Studio and answer all the questions. Submit in PDF format.

Includes appropriate plots. Make sure the plots are properly labeled.

The assignment will be graded on the correctness of the answers, comprehensiveness of the analysis, clarity of results’ presentation and neatness of the report.

Order a Similar Paper and get 15% Discount on your First Order

## Related Questions

### Why is an update/patch process crucial for any organization to have and follow?  Discuss some issues that may arise when patching and updating

Why is an update/patch process crucial for any organization to have and follow?  Discuss some issues that may arise when patching and updating machines.

### Imagine you work in a correctional institution and have been asked to create a strategic plan for working with specific correctional populations served by

Imagine you work in a correctional institution and have been asked to create a strategic plan for working with specific correctional populations served by your institution. Your supervisor would like you to submit your idea and strategy for implementation. Select 1 correctional population to focus on. Write a 525- to

### Use the resources linked below to help complete this assessment. Collapse All Assessment Assessment · Kiekens, A., Dierckx de

Use the resources linked below to help complete this assessment. Collapse All Assessment Assessment · Kiekens, A., Dierckx de Casterlé, D. & Vandamme, A. (2022).  Qualitative systems mapping for complex public health problems: A practical guide.   PLoS One, 17(2). · Iglesias, F. H., Celada, C. A., Navarro, C. B.,

### This must be Virginia standards Elementary 2nd grade EDLC 530 Lesson Plan Assignment Instructions Overview

This must be Virginia standards Elementary 2nd grade EDLC 530 Lesson Plan Assignment Instructions Overview Lesson planning is a key aspect of effective instruction. Lesson planning ranges from long-term planning (such as yearly or unit planning) to short-term planning (such as weekly or daily planning). You will complete this assignment

### Post the critical review of one scholarly article covering best practices (procedures, tools, templates, and metrics) that you found for executing or

Post the critical review of one scholarly article covering best practices (procedures, tools, templates, and metrics) that you found for executing or monitoring and controlling process groups.

### science stands as a unique and unparalleled human endeavor, characterized by its distinctive methods, systematic inquiry, and the pursuit of

science stands as a unique and unparalleled human endeavor, characterized by its distinctive methods, systematic inquiry, and the pursuit of objective truths. In this reflection, I’ll explore the factors that set science apart from other activities, its role in knowledge expansion, the deliberate limitations on methods, and the crucial roles

### Complete additional research on the restrictions surrounding the insanity defense in many states. In your initial post, address the following: Do you

Complete additional research on the restrictions surrounding the insanity defense in many states. In your initial post, address the following: Do you think these restrictions are a good idea? Do you think the insanity plea has a place in the courtroom? What could the repercussions be if it is

### In your journal, reflect on ethical issues that you can foresee coming up as a forensic psychologist who does civil commitment assessments. How can you

In your journal, reflect on ethical issues that you can foresee coming up as a forensic psychologist who does civil commitment assessments. How can you as an assessment psychologist be cognizant of them, work through them, or avoid them? Also, consider the special populations mentioned in the article. How

### Unveiling the Mosaic: A Personal Exploration of Ethnic Oppression in the US Healthcare System Assignment Overview: This solo written

Unveiling the Mosaic: A Personal Exploration of Ethnic Oppression in the US Healthcare System Assignment Overview: This solo written assignment invites you to delve into the complex and often invisible realities of ethnic oppression within the US healthcare system. Through introspection, research, and critical analysis, you will explore the specific

### In Chapter 4 of the Reimagining Collaboration text, the author argues that email is not an effective tool for collaboration. Do you agree or disagree?

In Chapter 4 of the Reimagining Collaboration text, the author argues that email is not an effective tool for collaboration. Do you agree or disagree? Is there a time and place for email? Explain. As you’ve worked on your first assignment for your group project, have there been instances where

### Please don’t copy past anything from the internet or don’t use AI , and citation should be right   or any website like course hero or Wikipedia that a red

Please don’t copy past anything from the internet or don’t use AI , and citation should be right   or any website like course hero or Wikipedia that a red flag all work must be original!!! Write your own thoughts not the internet or someone else thoughts!!   Required Text: Finance: Applications

### Review the criteria for civil commitment from this module’s materials. Then, research the legislation in your home state addressing a person with a

Review the criteria for civil commitment from this module’s materials. Then, research the legislation in your home state addressing a person with a mental illness or the diagnosis of dangerousness and the criteria for civil commitment. In your initial post, address the following: Describe the risks of this legislation.

### Please don’t copy past anything from the internet or don’t use AI , and citation should be right   or any website like course hero or Wikipedia that a red

Please don’t copy past anything from the internet or don’t use AI , and citation should be right   or any website like course hero or Wikipedia that a red flag all work must be original!!! Write your own thoughts not the internet or someone else thoughts!!   Required Text: Finance: Applications

### This week, explore the relationship between strategic goals and alignment with projects and best practices from the five process groups, especially

This week, explore the relationship between strategic goals and alignment with projects and best practices from the five process groups, especially focusing on executing, monitoring, and controlling projects. This assessment is the first component of your course project.   In this assessment, you will write a topic definition statement for your

### Please don’t copy past anything from the internet or don’t use AI , and citation should be right   or any website like course hero or Wikipedia that a red

Please don’t copy past anything from the internet or don’t use AI , and citation should be right   or any website like course hero or Wikipedia that a red flag all work must be original!!! Write your own thoughts not the internet or someone else thoughts!!   Required Text: Finance: Applications

### I need two paragraphs on the following question What is the Watergate Scandal and how did it lead to the end of President Nixon’s career? Only need

I need two paragraphs on the following question What is the Watergate Scandal and how did it lead to the end of President Nixon’s career? Only need about 1 reference and 2 paragraphs

### Please don’t copy past anything from the internet or don’t use AI , and citation should be right   or any website like course hero or Wikipedia that a red

Please don’t copy past anything from the internet or don’t use AI , and citation should be right   or any website like course hero or Wikipedia that a red flag all work must be original!!! Write your own thoughts not the internet or someone else thoughts!!   Required Text: Finance: Applications

### 1 Financial Section: Lutheran Social Services of the South Student’s Name Institutional

1 Financial Section: Lutheran Social Services of the South Student’s Name Institutional Affiliation Course Details Instructor’s Name Date Financial Section: Lutheran Social Services of the South The budget for the program at Lutheran Social Services of the South (LSSS) is crucial for achieving its mission of breaking the cycle of