Guest User

Untitled

a guest
Mar 26th, 2019
65
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. server = function(input,output){
  2.  
  3. df = reactive({
  4. req(input$file1)
  5. read.csv(file = input$file1$datapath)
  6. })
  7.  
  8. #Perform Regression
  9.  
  10. output$prediction = renderTable({
  11. req(df())
  12.  
  13. new_data_pre <- transform(df(),
  14. line_change_y = ifelse(line_change == "y", 1, 0),
  15. line_change_n = ifelse(line_change == "n", 1, 0),
  16. #
  17. touch_screen_y = ifelse(touch_screen == "y", 1, 0),
  18. touch_screen_n = ifelse(touch_screen == "n", 1, 0),
  19. #
  20. button_color_b = ifelse(button_color == "blue", 1, 0),
  21. button_color_g = ifelse(button_color == "green", 1, 0),
  22. button_color_o = ifelse(button_color == "orange", 1, 0),
  23. button_color_p = ifelse(button_color == "pink", 1, 0),
  24. button_color_r = ifelse(button_color == "red", 1, 0),
  25. button_color_v = ifelse(button_color == "violet", 1, 0),
  26. button_color_w = ifelse(button_color == "white", 1, 0),
  27. button_color_y = ifelse(button_color == "yellow", 1, 0),
  28. button_color_others = ifelse(button_color != "blue" &
  29. button_color != "green" &
  30. button_color != "orange" &
  31. button_color != "pink" &
  32. button_color != "red" &
  33. button_color != "violet" &
  34. button_color != "white" &
  35. button_color != "yellow", 1, 0),
  36. #
  37. auto_color_bk = ifelse(auto_color == "black", 1, 0),
  38. auto_color_b = ifelse(auto_color == "blue", 1, 0),
  39. auto_color_gd = ifelse(auto_color == "gold", 1, 0),
  40. auto_color_g = ifelse(auto_color == "green", 1, 0),
  41. auto_color_o = ifelse(auto_color == "orange", 1, 0),
  42. auto_color_p = ifelse(auto_color == "pink", 1, 0),
  43. auto_color_r = ifelse(auto_color == "red", 1, 0),
  44. auto_color_v = ifelse(auto_color == "violet", 1, 0),
  45. auto_color_w = ifelse(auto_color == "white", 1, 0),
  46. auto_color_y = ifelse(auto_color == "yellow", 1, 0),
  47. auto_color_another = ifelse(auto_color != "black" &
  48. auto_color != "blue" &
  49. auto_color != "gold" &
  50. auto_color != "green" &
  51. auto_color != "orange" &
  52. auto_color != "pink" &
  53. auto_color != "red" &
  54. auto_color != "violet" &
  55. auto_color != "white" &
  56. auto_color != "yellow", 1, 0),
  57. #
  58. Fruit_y = ifelse(Fruit == "y", 1, 0),
  59. Fruit_n = ifelse(Fruit == "n", 1, 0),
  60. #
  61. poker_y = ifelse(poker == "y", 1, 0),
  62. poker_n = ifelse(poker == "n", 1, 0),
  63. #
  64. BAR_y = ifelse(BAR == "y", 1, 0),
  65. BAR_n = ifelse(BAR == "n", 1, 0),
  66. #
  67. jewel_y = ifelse(jewel == "y", 1, 0),
  68. jewel_n = ifelse(jewel == "n", 1, 0),
  69. #
  70. type_v = ifelse(type == "video", 1, 0),
  71. type_c = ifelse(type == "classic", 1, 0),
  72. #
  73. type_of_image_c = ifelse(type_of_image == "cartoon", 1, 0),
  74. type_of_image_p = ifelse(type_of_image == "photo", 1, 0),
  75. #
  76. entertainer_y = ifelse(entertainer == "y", 1, 0),
  77. entertainer_n = ifelse(entertainer== "n", 1, 0),
  78. #
  79. TV_show_y = ifelse(TV_show == "y", 1, 0),
  80. TV_show_n = ifelse(TV_show== "n", 1, 0),
  81. #
  82. wild_type_m = ifelse(wild_type == "multi", 1, 0),
  83. wild_type_no = ifelse(wild_type == "no", 1, 0),
  84. wild_type_nor = ifelse(wild_type == "normal", 1, 0),
  85. wild_type_s = ifelse(wild_type == "stacked", 1, 0),
  86. wild_type_sm = ifelse(wild_type == "stack & multi", 1, 0),
  87. #
  88. stacked_symbol_y = ifelse(stacked_symbol == "y", 1, 0),
  89. stacked_symbol_n = ifelse(stacked_symbol == "n", 1, 0),
  90. #
  91. tumbling_y = ifelse(tumbling == "y", 1, 0),
  92. tumbling_n = ifelse(tumbling == "n", 1, 0),
  93. #
  94. # seasonal_event_12_y = ifelse(seasonal_event_12 == "y", 1, 0),
  95. # seasonal_event_12_n = ifelse(seasonal_event_12 == "n", 1, 0),
  96. #
  97. seasonal_event_y = ifelse(seasonal_event == "y", 1, 0),
  98. seasonal_event_n = ifelse(seasonal_event == "n", 1, 0),
  99. #
  100. spin_stop_y = ifelse(spin_stop == "y", 1, 0),
  101. spin_stop_n = ifelse(spin_stop == "n", 1, 0)
  102. #
  103.  
  104. )
  105.  
  106. new_data_pre <- subset(new_data_pre, select = colnames(raw_pre_rbind))
  107. new_data_pre <- subset(new_data_pre, select = -revenue)
  108. colnames(new_data_pre)
  109. colnames(raw_pre_rbind)
  110.  
  111. normalizing <- function(x){
  112. (x-min(x))/(max(x)-min(x))
  113. }
  114.  
  115. scale_info <- apply(raw_pre_rbind[1:34], 2, max)
  116. scale_info <- rbind(scale_info, apply(raw_pre_rbind[1:34], 2, min))
  117. scale_info <- as.data.frame(scale_info)
  118. class(scale_info)
  119.  
  120. temp <- 0
  121. for(i in 1:34){
  122. if(i == 1){
  123. temp <- (new_data_pre[, i] - scale_info[2, i]) / (scale_info[1, i] - scale_info[2, i])
  124. }
  125. else{
  126. temp <- cbind(temp, (new_data_pre[, i] - scale_info[2, i]) / (scale_info[1, i] - scale_info[2, i]))
  127. }
  128.  
  129. }
  130. colnames(temp) <- colnames(new_data_pre[1:34])
  131.  
  132. new_data_pre_scaled <- cbind(temp, new_data_pre[, 35:87])
  133.  
  134. prediction <- predict(load_model, as.matrix(new_data_pre_scaled[1:3, ]))
  135.  
  136. plot.new()
  137. #plot(Actual$Class,type = "l",lty= 1.8,col = "red")
  138. lines(prediction, type = "l", col = "blue")
  139. plot(prediction,type = "l",lty= 1.8,col = "blue")
  140.  
  141. predict_df = data.frame(Revenue = prediction)
  142. output_df = cbind(predict_df)
  143. return(output_df)
  144. })
  145. }
RAW Paste Data