This is R programming - stat/machine learning question. My codeshould give me the mean and standard deviation
Fantastic news! We've Found the answer you've been seeking!
Question:
This is R programming - stat/machine learning question. My codeshould give me the mean and standard deviation of the RSME but onlymy mean is correct, my sd of 0.1180 or 0.12 appears to beincorrect. Thank you for helping.
Transcribed Image Text:
Create a data set using the following code: set.seed (1) n < 100 Sigma <- 9*matrix(c(1.0, 0.5, 0.5, 1.0), 2, 2) dat <- MASS::mvrnorm(n = 100, c(69, 69), Sigma) %>% data.frame() %>% setNames (c("x", "y")) We will build 100 linear models using the data above and calculate the mean and standard deviation of the combined models. First, set the seed to 1. Within a replicate loop, (1) partition the dataset into test and training sets of equal size using datsy to generate your indices, (2) train a linear model predicting y from x, (3) generate predictions on the test set, and (4) calculate the RMSE of that model. Then, report the mean and standard deviation of the RMSEs from all 100 models. Mean: 2.48 2.48 SD: 0.118 0.118 120 121 f <-function(data) { 122- 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 rmse <- replicate (100, { 142 143 144 }) 138 } 139 set.seed (1) 140 141 test_index <- createDataPartition (datasy, list = FALSE) train set <- data [-test_index,] data[test_index,] test set < ## Train a linear model fit - 1m(yx, data = train_set) y_hat <- predict (fit, test_set) ## Squared loss... sqrt (mean((y_hat - test_setsy) ^ 2)) structure(c(mean (rmse), sd(rmse)), names = c('mean', 'sd')) n - 100 Sigma < 9 matrix(c(1.0, 0.5, 0.5, 1.0), 2, 2) dat < MASS::mvrnorm (n = 100, c(69, 69), Sigma) %>% data.frame() %>% setNames (c("x", "y")) 145 results < f (dat) 146 results 147 148 Create a data set using the following code: set.seed (1) n < 100 Sigma <- 9*matrix(c(1.0, 0.5, 0.5, 1.0), 2, 2) dat <- MASS::mvrnorm(n = 100, c(69, 69), Sigma) %>% data.frame() %>% setNames (c("x", "y")) We will build 100 linear models using the data above and calculate the mean and standard deviation of the combined models. First, set the seed to 1. Within a replicate loop, (1) partition the dataset into test and training sets of equal size using datsy to generate your indices, (2) train a linear model predicting y from x, (3) generate predictions on the test set, and (4) calculate the RMSE of that model. Then, report the mean and standard deviation of the RMSEs from all 100 models. Mean: 2.48 2.48 SD: 0.118 0.118 120 121 f <-function(data) { 122- 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 rmse <- replicate (100, { 142 143 144 }) 138 } 139 set.seed (1) 140 141 test_index <- createDataPartition (datasy, list = FALSE) train set <- data [-test_index,] data[test_index,] test set < ## Train a linear model fit - 1m(yx, data = train_set) y_hat <- predict (fit, test_set) ## Squared loss... sqrt (mean((y_hat - test_setsy) ^ 2)) structure(c(mean (rmse), sd(rmse)), names = c('mean', 'sd')) n - 100 Sigma < 9 matrix(c(1.0, 0.5, 0.5, 1.0), 2, 2) dat < MASS::mvrnorm (n = 100, c(69, 69), Sigma) %>% data.frame() %>% setNames (c("x", "y")) 145 results < f (dat) 146 results 147 148
Expert Answer:
Related Book For
Statistics For Business Decision Making And Analysis
ISBN: 9780321890269
2nd Edition
Authors: Robert Stine, Dean Foster
Posted Date:
Students also viewed these mathematics questions
-
The mean and standard deviation of a sample may change if data are rescaled (for instance, temperature changed from Fahrenheit to Celsius). For a sample with mean, adding a constant c to each...
-
The accompanying table gives the mean and standard deviation of reaction times (in seconds) for each of two different stimuli: If your reaction time is 4.2 seconds for the first stimulus and 1.8...
-
The accompanying table gives the mean and standard deviation of reaction times (in seconds) for each of two different stimuli: Suppose your reaction time is 4.2 seconds for the first stimulus and 1.8...
-
List at least one "real life" situation that may arise out of each category. Be sure to explain how you think each issue should be handled, policy-wise. 1. Relationships with citizens and others over...
-
Pacific Fixtures lists the following accounts as part of its balance sheet. Total assets $................................................... 10,000,000 Accounts payable...
-
The adjusted trial balance of Bertrand Irrigation System at December 31, 2016, follows: Requirements 1. Prepare the companys income statement for the year ended December 31, 2016. 2. Prepare the...
-
Lessee Company enters into a 6-year finance lease of non-specialized equipment with Lessor Company on January 1,2020 . Lessee has agreed to pay \(\$ 28,000\) annually beginning immediately on January...
-
David James is a cost accountant and business analyst for Doorknob Design Company (DDC), which manufactures expensive brass doorknobs. DDC uses two direct cost categories: direct materials and direct...
-
What is the answer ?. Kennedy, Inc. reported the following data: Net income $160,097 Depreciation expense 16,585 Loss on disposal of equipment 10,584 Gain on sale of building 18,025 Increase in...
-
Retro Productions Ltd. is a Vancouver-based furniture manufacturer. The company reported the following information on its trial balance for 11 months of the year ended November 30, 2018. Retro...
-
A vertical curve joins a -1.2% grade to a +0.8% grade. The P.I. of the vertical curve is at station 75 +00 and elevation 50.90 m above sea level. The centerline of the roadway must clear a pipe...
-
Greer Utsey earned $47,500 in 2022 for a company in Kentucky. Greer is single with one dependent under 17 and is paid weekly. The FUTA rate in Kentucky for 2022 is 0.6 percent on the first $7,000 of...
-
Ques.3: Using Terzaghi's theory, determine the ultimate bearing capacity of a strip footing 1.5 m wide resting on a saturated clay (cu 30 kN/m, D= 0, and Ysat 20 kN/m), at a depth of 2 m below ground...
-
Weldon Corporation's fiscal year ends December 31. The following is a list of transactions involving receivables that occurred during 2021: Mar. 17 Accounts receivable of $3,600 were written off as...
-
Ques.4: Using Terzaghi's theory: Determine the ultimate bearing capacity of a strip footing 2 m in width, with its base at a depth of 1.5 m below ground surface and resting on a saturated clay soil...
-
Marine security is nothing more than additional administrative duties on an already over-worked marine officer. There is really no 'meat' to the policy in Canadian waters and really only has 'teeth'...
-
Puvo, Incorporated, manufactures a single product in which variable manufacturing overhead is assigned on the basis of standard direct labor-hours. The company uses a standard cost system and has...
-
7. FALSE DILEMMA 8. GANDWAGON Definition: Fallacy example: How to revise argument: Definition: Fallacy example: How to revise argument:
-
1. The sample space S for this experiment has 10 elements. 2. The assumption of independence implies that each shopper has the same probability for carrying a bag. 3. P (A) + P (B) = P (A or B). 4....
-
The electronic components used to assemble a cellular phone have been exceptionally reliable, with more than 99.9% working correctly. The head of procurement believes that the current supplier meets...
-
An importer of electronic goods is considering packaging a new, easy-to-read instruction booklet with DVD players. It wants to package this booklet only if it helps customers more than the current...
-
Lessor Co. enters into an operating lease of property with Lessee Co. on January 1, 2020, for a five-year term at an annual fixed lease payment of \(\$ 10,000\) (beginning of period payments)....
-
Solutions Inc. signs a 10-year lease for a building owned by Property Inc. that is appropriately classified as an operating lease by both the lessee and lessor. Lease payments are \(\$ 150,000\) per...
-
Gomez Inc. leases a vehicle from CareMax Inc. on January 1, 2020, for a three-year period, appropriately classified by Gomez Inc. as an operating lease. Gomez agrees to make \(\$ 6,000\) annual...
Study smarter with the SolutionInn App