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...
-
a. Using the financial statements shown below, calculate net operating working capital, total net operating capital, net operating profit after taxes, free cash flow, and return on invested capital...
-
Show that in the fixed-effects model analysis of variance E (MS E ) = 2 . How would your development change if the random-effects model had been specified?
-
An asset is classified as current if it a. was purchased within the last six months. b. will become cash, be sold, or be used up within 12 months. C. was purchased with cash. d. will last longer than...
-
Selected transactions completed by Hirata Company during its first fiscal year ending December 31 were as follows: Jan. 2. Issued a check to establish a petty cash fund of $1,400. Mar. 1. Replenished...
-
Mountain Man, a sporting goods store, is trying to figure out continuous review order policy for infuser water bottle. The bottle has following characteristics: Length of a year 52 weeks Demand per...
-
Margie Frump is employed as a teacher. She occasionally purchases items that she uses in the course of her employment that are subject to depreciation. Assets held by Margie at 30 June 2021: Margie...
-
1. Why does there exist a paradox of.. achieving cost efficiencies whilst improving customer and supplier relationships. 2. How do the desired skills set differ between say, Australia, S.E. Asia, and...
-
5. a) In a marathon, the median finishing time was 3:35:04 (three hours, 35 minutes, and four seconds). You finished in 3:34:10. Provide the interpretation and meaning of the median time, and discuss...
-
An individual transfers property to a new corporation with an adjusted basis of $90,000 and a market value of $100,000. In exchange, the individual received shares with a market value of $20,000. For...
-
On January 1, 2025, Carla Vista Company purchased 6% bonds, having a maturity value of $600,000 for $518,458. The bonds provide the bondholders with a 8% yield. They are dated January 1, 2025, and...
-
A Government Bond pays $4,500 per quarter in perpetuity. If the required rate of return is 8%, the price of the bond today is closest to:
-
25. If a current of 0.40 A is used to electrolyze a 0.50 M solution of Au3+(aq) for 35.0 minutes, how much Au(s) will be electroplated onto to a ring immersed in this solution? (Assume 100% current...
-
2018 2017 Accounts receivable $40,000 $36,000 Inventory 28,000 35,000 Net sales 190,000 186,000 Cost of goods sold 114,000 108,000 Total assets 425,000 405,000 Total stockholders equity 240,000...
-
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...
-
The following table is a life table, reproduced from the chapter introduction. With an understanding of some basic concepts of probability, one can use the life table to compute the probability that...
-
In Example 5.4, what is the probability that the oldest child and the youngest child are of the same gender? Example 5.4 Computing probabilities A family has three children. Denoting a boy by B and a...
-
A quiz consists of three truefalse questions and two multiple-choice questions with five choices each. How many different sets of answers are there?
Study smarter with the SolutionInn App