Advertisement
Guest User

Untitled

a guest
Dec 15th, 2017
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. ---
  2.  
  3. ---
  4.  
  5. ```{r setup, include=FALSE}
  6. knitr::opts_chunk$set(echo = TRUE)
  7. set.seed(5678)
  8. ```
  9.  
  10. ## R Markdown
  11.  
  12. This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
  13.  
  14. When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
  15.  
  16. ```{r}
  17. library(neuralnet)
  18.  
  19.  
  20. setwd("C:\\Chapter 06")
  21. myvalues <- read.csv("insurance.csv")
  22. hist(myvalues$expenses, 100) # Example: 100 breaks, but you can specify them at will
  23.  
  24. pairs(~age+bmi+children+expenses,data=myvalues,
  25. main="Simple Scatterplot Matrix")
  26.  
  27. nums <- sapply(myvalues, is.numeric)
  28. head(nums)
  29.  
  30. filtered <- subset( myvalues, select = -c(sex, smoker, region ) )
  31.  
  32. filtered
  33.  
  34. maxs <- apply(filtered, 2, max)
  35. mins <- apply(filtered, 2, min)
  36.  
  37. scaled <- as.data.frame(scale(filtered, center = mins, scale = maxs - mins))
  38.  
  39. train_ <- scaled[index,]
  40. test_ <- scaled[-index,]
  41.  
  42. n <- names(train_)
  43.  
  44. nn <- neuralnet(expenses ~ age + bmi + children ,data=train_,hidden=1)
  45.  
  46. plot(nn, rep ="best")
  47.  
  48. net.result <- neuralnet::compute(
  49. nn, train_[,c("age",
  50. "bmi", "children")])
  51. net.result
  52.  
  53. nn5 <- neuralnet(expenses ~ age + bmi + children ,data=train_,hidden=5)
  54.  
  55. plot(nn5, rep ="best")
  56.  
  57. net.result <- neuralnet::compute(
  58. nn5, train_[,c("age",
  59. "bmi", "children")])
  60. net.result
  61.  
  62.  
  63. ```
  64.  
  65. ```{r cars}
  66. summary(cars)
  67. ```
  68.  
  69. ## Including Plots
  70.  
  71. You can also embed plots, for example:
  72.  
  73. ```{r pressure, echo=FALSE}
  74. plot(pressure)
  75. ```
  76.  
  77. Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement