Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. library(tree)
  2.  
  3. setwd("C:/Users/Alexandre/Downloads")
  4. salaire<-as.data.frame(read.csv(file = "Salaries.csv", header = T, sep = ",", dec="."))[,-1]
  5. summary(data)
  6.  
  7. tree.Lin <- tree( salary ~ yrs.service + yrs.since.phd , data=salaire)
  8. plot( tree.Lin )
  9. text( tree.Lin , cex=.75)
  10.  
  11. #a) phd > 32 ans
  12. #b) 4
  13.  
  14. #c)
  15. tree.model<-tree(log(salary) ~ yrs.service + yrs.since.phd , data=salaire)
  16. plot( tree.model )
  17. text( tree.model , cex=.75)
  18.  
  19. #d) les salaires suivent une loi Log-Normale. Il est donc normal de le passer au log
  20.  
  21.  
  22. ## 1.3
  23.  
  24. salar.deciles <- quantile( salaire$salary, 0:10/10)
  25. cut.prices <- cut( salaire$salary , salar.deciles , include.lowest = TRUE )
  26. plot( salaire$yrs.service , salaire$yrs.since.phd , col = grey(10:2/11)[cut.prices], pch =20 , xlab ="yrs.service" , ylab ="yrs.since . phd ")
  27. partition.tree( tree.model , ordvars = c("yrs.service" ,"yrs.since.phd") , add = TRUE )
  28. plot ( salaire$yrs.since.phd , salaire$salary , pch =19 , col = as.numeric (salaire$rank ) )
  29. partition.tree( tree.model , label ="Species" , add = TRUE )
  30. legend("topright" , legend = unique(salaire$rank) , col = unique ( as.numeric( salaire$rank ) ) , pch =19)
  31.  
  32.  
  33. ## 1.4
  34.  
  35. summary ( tree.model )
  36. tree.model2 <- tree( log( salary ) ~ yrs.service + yrs.since.phd , data = salaire , mindev =0.001)
  37. plot ( tree.model2 )
  38. text ( tree.model2 , cex =.75)
  39. summary ( tree.model2 )
  40. pruned.tree <- prune.tree( tree.model , best =4)
  41. plot(pruned.tree)
  42. text(pruned.tree)
  43.  
  44. ### II
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement