Guest User

Untitled

a guest
May 23rd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. > str(DATABASE)
  2. 'data.frame': 1667 obs. of 28 variables:
  3. $ YEAR_SALES : num 2 1 2 2 1 1 1 1 1 1 ...
  4. $ MONTH_SALES : num 9 9 2 9 3 3 11 12 3 6 ...
  5. $ DAY_SALES : num 13 3 10 23 12 10 26 4 18 9 ...
  6. $ HOURS_INS : num 17 14 18 16 23 18 16 12 17 16 ...
  7. $ CREATION_YEAR_SALES : num 2 1 2 2 2 1 1 2 1 1 ...
  8. $ CREATION_MONTH_SALES : num 9 9 2 10 12 3 11 2 3 6 ...
  9. $ CREATION_DAY_SALES : num 13 11 15 31 5 10 27 7 18 9 ...
  10. $ VALIDATION_YEAR_SALES : num 2 1 2 2 2 1 1 2 1 1 ...
  11. $ VALIDATION_MONTH_SALES: num 9 9 2 11 12 3 12 2 3 6 ...
  12. $ VALIDATION_DAY_SALES : num 15 14 16 3 6 19 1 8 21 10 ...
  13. $ AGE_CUSTUMER : num 32 37 23 32 44 33 29 30 56 48 ...
  14. $ MEAN_Sales : num 0 71 50 0 0 83 0 25 23 35 ...
  15. $ NBR_GIFTS : num 1 1 1 1 1 1 1 1 4 3 ...
  16. $ TYPE_PEAU : num 2 3 4 2 2 3 2 2 2 2 ...
  17. $ SENSIBILITE : num 3 3 3 2 1 3 3 2 2 2 ...
  18. $ IMPERFECTIONS : num 2 3 2 1 3 2 2 1 2 1 ...
  19. $ BRILLANCE : num 3 1 1 3 3 3 3 3 3 3 ...
  20. $ GRAIN_PEAU : num 3 3 3 3 1 3 1 1 1 3 ...
  21. $ RIDES_VISAGE : num 1 1 1 3 3 3 3 1 3 1 ...
  22. $ ALLERGIES : num 1 1 1 1 1 1 1 1 1 1 ...
  23. $ MAINS : num 2 3 3 3 2 2 2 2 2 2 ...
  24. $ PEAU_CORPS : num 1 2 2 1 1 1 1 1 1 1 ...
  25. $ INTERET_ALIM_NATURELLE: num 1 3 3 1 3 1 1 1 3 1 ...
  26. $ INTERET_ORIGINE_GEO : num 1 2 1 1 3 1 3 1 1 3 ...
  27. $ INTERET_VACANCES : num 2 3 1 2 1 2 1 1 2 3 ...
  28. $ INTERET_ENVIRONNEMENT : num 1 3 3 3 3 1 1 1 1 1 ...
  29. $ INTERET_COMPOSITION : num 1 1 1 3 3 1 1 1 1 1 ...
  30. $ OUTCOME : num 3 4 7 3 3 6 3 9 26 17 ...
  31.  
  32. > set.seed(123)
  33. > smp_size <- floor(0.75 * nrow(DATABASE))
  34. > train_ind <- sample(seq_len(nrow(DATABASE)),size =smp_size)
  35. >
  36. > train <- DATABASE[train_ind, ]
  37. > test <- DATABASE[-train_ind, ]
  38. > reg<-lm(OUTCOME~.-1,data=train)
  39.  
  40. > y.test<-test$OUTCOME
  41. > NBR_Achat=predict(reg,newdata=test)
  42. > round(sqrt(mean(((1-NBR_Achat/y.test)^2))),4)
  43. [1] 0.4523
  44.  
  45. y<-train$OUTCOME
  46. x<-as.matrix(train[,1:27])
  47. lambdas <- 10^seq(3,-2,by=-.1)
  48. fit<-glmnet(x,y,alpha =0,lambda=lambdas)
  49.  
  50. > cv_fit <- cv.glmnet(x,y,alpha = 0,lambda=lambdas)
  51. > plot(cv_fit)
  52. > opt_lambda <- cv_fit$lambda.min
  53. > opt_lambda
  54. [1] 0.1
  55.  
  56. > x<-as.matrix(test[,1:27])
  57. > y_predicted <- predict(cv_fit,s = opt_lambda,newx=x)
  58. > y.test<-test$OUTCOME
  59. > round(sqrt(mean(((1-y_predicted/y.test)^2))),4)
  60. [1] 0.4605
Add Comment
Please, Sign In to add comment