Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(tree)
- setwd("C:/Users/Alexandre/Downloads")
- salaire<-as.data.frame(read.csv(file = "Salaries.csv", header = T, sep = ",", dec="."))[,-1]
- summary(data)
- tree.Lin <- tree( salary ~ yrs.service + yrs.since.phd , data=salaire)
- plot( tree.Lin )
- text( tree.Lin , cex=.75)
- #a) phd > 32 ans
- #b) 4
- #c)
- tree.model<-tree(log(salary) ~ yrs.service + yrs.since.phd , data=salaire)
- plot( tree.model )
- text( tree.model , cex=.75)
- #d) les salaires suivent une loi Log-Normale. Il est donc normal de le passer au log
- ## 1.3
- salar.deciles <- quantile( salaire$salary, 0:10/10)
- cut.prices <- cut( salaire$salary , salar.deciles , include.lowest = TRUE )
- plot( salaire$yrs.service , salaire$yrs.since.phd , col = grey(10:2/11)[cut.prices], pch =20 , xlab ="yrs.service" , ylab ="yrs.since . phd ")
- partition.tree( tree.model , ordvars = c("yrs.service" ,"yrs.since.phd") , add = TRUE )
- plot ( salaire$yrs.since.phd , salaire$salary , pch =19 , col = as.numeric (salaire$rank ) )
- partition.tree( tree.model , label ="Species" , add = TRUE )
- legend("topright" , legend = unique(salaire$rank) , col = unique ( as.numeric( salaire$rank ) ) , pch =19)
- ## 1.4
- summary ( tree.model )
- tree.model2 <- tree( log( salary ) ~ yrs.service + yrs.since.phd , data = salaire , mindev =0.001)
- plot ( tree.model2 )
- text ( tree.model2 , cex =.75)
- summary ( tree.model2 )
- pruned.tree <- prune.tree( tree.model , best =4)
- plot(pruned.tree)
- text(pruned.tree)
- ### II
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement