Guest User

Untitled

a guest
Sep 14th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.35 KB | None | 0 0
  1. array([[ 0. , 0.33178298, 0.26865475, 0. , -0.72870151,
  2. 0. , 1. , 0. , 0. , 1. ],
  3. [ 0. , -1.59016455, -1.05162249, 0. , -0.88503151,
  4. 0. , 0. , 1. , 0. , 1. ],
  5. [ 1. , -0.50119857, -1.42884455, 0. , -1.04136151,
  6. 1. , 0. , 0. , 0. , 1. ],
  7. [ 0. , 2.0321526 , 0.77161751, 0. , -0.74172901,
  8. 0. , 1. , 0. , 0. , 1. ],
  9. [ 0. , 1.80988656, 1.21170993, 0. , -0.70264651,
  10. 0. , 0. , 1. , 0. , 1. ],
  11. [ 0. , -0.76509649, -0.61153007, 0. , 1.40780853,
  12. 0. , 0. , 0. , 1. , 1. ],
  13. [ 0. , 1.45653173, 1.71467268, 1. , -1.11952651,
  14. 0. , 0. , 1. , 0. , 1. ],
  15. [ 0. , 2.70376764, 1.58893199, 0. , -0.5202615 ,
  16. 0. , 1. , 0. , 0. , 1. ],
  17. [ 0. , 0.384769 , 1.71467268, 1. , 0.76946102,
  18. 1. , 0. , 0. , 0. , 1. ],
  19. [ 0. , -0.63022298, -1.4917149 , 1. , -0.272739 ,
  20. 0. , 0. , 1. , 0. , 1. ],
  21. [ 0. , 0.90568353, 0.64587682, 0. , -0.97622401,
  22. 0. , 0. , 0. , 0. , 1. ],
  23. [ 0. , 0.20929581, -0.234308 , 1. , -1.08044401,
  24. 0. , 0. , 0. , 1. , 1. ],
  25. [ 1. , -0.73550689, -0.48578938, 0. , -0.74172901,
  26. 1. , 0. , 0. , 0. , 1. ],
  27. [ 0. , -0.94401033, -0.61153007, 1. , -1.01530651,
  28. 0. , 0. , 1. , 0. , 1. ],
  29. [ 0. , 0.53615764, -0.42291904, 1. , 0.53496601,
  30. 0. , 0. , 1. , 0. , 1. ],
  31. [ 0. , -0.28134099, -0.67440042, 1. , -0.87200401,
  32. 0. , 0. , 1. , 0. , 1. ],
  33. [ 0. , -0.53113224, -0.48578938, 1. , 1.68138603,
  34. 0. , 0. , 0. , 1. , 1. ],
  35. [ 0. , 0.34416932, -0.61153007, 0. , 1.52505603,
  36. 0. , 0. , 0. , 1. , 1. ],
  37. [ 1. , -1.27362468, -1.68032593, 1. , 1.18634102,
  38. 0. , 0. , 0. , 1. , 1. ],
  39. [ 0. , 0.10951694, -0.234308 , 0. , 1.87679853,
  40. 0. , 0. , 1. , 0. , 1. ],
  41. [ 0. , 1.28966016, 0.45726579, 1. , -0.5463165 ,
  42. 0. , 1. , 0. , 0. , 1. ],
  43. [ 1. , -1.67618082, -1.4917149 , 1. , -0.91108651,
  44. 0. , 1. , 0. , 0. , 1. ],
  45. [ 0. , 0.025221 , -0.54865973, 1. , 0.13111351,
  46. 0. , 0. , 0. , 1. , 1. ],
  47. [ 0. , 0.04001579, -0.61153007, 1. , -0.72870151,
  48. 1. , 0. , 0. , 0. , 1. ],
  49. [ 0. , -0.99424383, -0.80014111, 0. , -0.481179 ,
  50. 0. , 1. , 0. , 0. , 1. ],
  51. [ 0. , 0.70337327, 0.8973582 , 0. , -1.06741651,
  52. 0. , 0. , 1. , 0. , 1. ],
  53. [ 1. , -1.39404746, -1.11449283, 0. , 1.65533103,
  54. 0. , 0. , 0. , 0. , 1. ],
  55. [ 0. , -0.86418723, -0.42291904, 1. , -1.06741651,
  56. 0. , 0. , 0. , 0. , 1. ],
  57. [ 0. , -1.69751285, -1.24023352, 1. , 0.73037852,
  58. 1. , 0. , 0. , 0. , 1. ],
  59. [ 0. , -0.17949773, -0.73727076, 0. , -0.5202615 ,
  60. 0. , 0. , 1. , 0. , 1. ],
  61. [ 0. , -0.1571335 , -0.54865973, 0. , -0.97622401,
  62. 0. , 0. , 0. , 1. , 1. ],
  63. [ 0. , -0.42378393, -0.86301145, 1. , -0.168519 ,
  64. 0. , 1. , 0. , 0. , 1. ],
  65. [ 0. , 0.4074773 , 1.65180234, 1. , 1.10817602,
  66. 0. , 0. , 0. , 1. , 1. ],
  67. [ 0. , 0.37135047, -0.80014111, 0. , -0.66356401,
  68. 0. , 0. , 0. , 0. , 1. ],
  69. [ 0. , 1.74795485, 0.64587682, 0. , -0.012189 ,
  70. 0. , 1. , 0. , 0. , 1. ],
  71. [ 0. , 1.82020851, 1.02309889, 0. , -0.376959 ,
  72. 0. , 1. , 0. , 0. , 1. ],
  73. [ 1. , -0.97015928, -1.4917149 , 0. , -0.97622401,
  74. 1. , 0. , 0. , 0. , 1. ],
  75. [ 0. , 1.55390214, 1.40032096, 1. , -0.0773265 ,
  76. 0. , 0. , 1. , 0. , 1. ],
  77. [ 0. , 0.38132835, -0.10856731, 1. , -0.74172901,
  78. 0. , 1. , 0. , 0. , 1. ],
  79. [ 1. , -0.68974624, -0.17143766, 1. , -0.75475651,
  80. 0. , 1. , 0. , 0. , 1. ],
  81. [ 0. , 2.27093377, 1.33745062, 1. , 0.96487352,
  82. 0. , 0. , 0. , 1. , 1. ],
  83. [ 0. , -1.43533526, -1.05162249, 0. , -0.78081151,
  84. 0. , 0. , 0. , 1. , 1. ],
  85. [ 1. , -1.85647092, -1.61745559, 0. , 0.53496601,
  86. 0. , 0. , 1. , 0. , 1. ],
  87. [ 0. , 0.48867666, 1.58893199, 1. , -0.376959 ,
  88. 0. , 1. , 0. , 0. , 1. ],
  89. [ 0. , -0.31643563, 0.39439544, 1. , -0.96319651,
  90. 0. , 0. , 0. , 0. , 1. ],
  91. [ 0. , 0.02350067, 0.8973582 , 1. , 0.99092852,
  92. 0. , 0. , 1. , 0. , 1. ],
  93. [ 0. , -0.10724406, 0.8973582 , 0. , 0.95184602,
  94. 0. , 1. , 0. , 0. , 1. ],
  95. [ 1. , -1.59016455, -0.73727076, 1. , 0.33955351,
  96. 1. , 0. , 0. , 0. , 1. ],
  97. [ 0. , 0.09437808, 0.58300648, 1. , -0.5463165 ,
  98. 1. , 0. , 0. , 0. , 1. ],
  99. [ 0. , 2.3720889 , 1.52606165, 0. , -1.09347151,
  100. 1. , 0. , 0. , 0. , 1. ],
  101. [ 0. , -0.66875827, -0.234308 , 0. , -0.1554915 ,
  102. 0. , 1. , 0. , 0. , 1. ],
  103. [ 0. , -0.72828153, -0.29717835, 1. , -0.84594901,
  104. 0. , 1. , 0. , 0. , 1. ],
  105. [ 0. , 2.67073739, 1.33745062, 0. , 0.83459852,
  106. 1. , 0. , 0. , 0. , 1. ],
  107. [ 0. , -0.36185222, -0.10856731, 0. , -0.012189 ,
  108. 0. , 0. , 0. , 0. , 1. ],
  109. [ 0. , 2.10303001, 0.96022855, 0. , 1.70744103,
  110. 1. , 0. , 0. , 0. , 1. ],
  111. [ 0. , -0.05219365, -0.10856731, 1. , -0.89805901,
  112. 0. , 0. , 1. , 0. , 1. ],
  113. [ 0. , -0.90203439, -0.73727076, 1. , 1.19936852,
  114. 0. , 0. , 0. , 1. , 1. ],
  115. [ 0. , 0.62492643, 0.45726579, 1. , 1.82468853,
  116. 1. , 0. , 0. , 0. , 1. ],
  117. [ 1. , -0.77266592, -0.48578938, 1. , -0.5463165 ,
  118. 0. , 0. , 1. , 0. , 1. ],
  119. [ 0. , -0.21183984, -0.54865973, 1. , -0.5463165 ,
  120. 0. , 0. , 0. , 0. , 1. ],
  121. [ 0. , 0.55164057, 0.83448786, 0. , 1.98101854,
  122. 0. , 1. , 0. , 0. , 1. ],
  123. [ 0. , 1.1217564 , 0.8973582 , 0. , 0.33955351,
  124. 0. , 0. , 0. , 1. , 1. ],
  125. [ 0. , -1.10640905, -1.11449283, 1. , -1.02833401,
  126. 0. , 0. , 1. , 0. , 1. ],
  127. [ 1. , -1.22201492, -1.36597421, 0. , -0.533289 ,
  128. 0. , 0. , 0. , 1. , 1. ],
  129. [ 0. , -0.38180799, -1.4917149 , 1. , -0.5984265 ,
  130. 0. , 0. , 1. , 0. , 1. ],
  131. [ 0. , 0.26778688, 0.08004372, 1. , 1.94193604,
  132. 0. , 0. , 1. , 0. , 1. ],
  133. [ 0. , -0.14337089, 0.20578441, 1. , -0.4160415 ,
  134. 0. , 1. , 0. , 0. , 1. ],
  135. [ 0. , 2.46154582, 1.27458027, 0. , 0.41771851,
  136. 0. , 0. , 0. , 0. , 1. ],
  137. [ 1. , -1.30321427, -1.55458524, 1. , -1.11952651,
  138. 0. , 0. , 0. , 1. , 1. ],
  139. [ 1. , -0.78161161, -0.73727076, 0. , -0.70264651,
  140. 0. , 0. , 0. , 0. , 1. ],
  141. [ 0. , 1.58762052, 0.70874717, 0. , -0.298794 ,
  142. 1. , 0. , 0. , 0. , 1. ],
  143. [ 0. , -1.00181326, -0.86301145, 1. , -0.83292151,
  144. 1. , 0. , 0. , 0. , 1. ],
  145. [ 0. , -0.38800116, -0.98875214, 1. , -1.13255401,
  146. 1. , 0. , 0. , 0. , 1. ],
  147. [ 0. , 0.77872352, 1.21170993, 0. , -0.93714151,
  148. 0. , 0. , 0. , 0. , 1. ],
  149. [ 1. , -1.28807541, -0.36004869, 1. , 1.92890854,
  150. 0. , 0. , 1. , 0. , 1. ],
  151. [ 1. , -0.50704768, -0.17143766, 0. , -0.116409 ,
  152. 0. , 0. , 0. , 0. , 1. ],
  153. [ 0. , 0.42949746, 1.14883958, 0. , 0.82157102,
  154. 0. , 0. , 0. , 0. , 1. ],
  155. [ 0. , 0.46940901, -0.61153007, 1. , -0.96319651,
  156. 1. , 0. , 0. , 0. , 1. ],
  157. [ 0. , 0.29187143, 0.52013613, 0. , -1.04136151,
  158. 0. , 1. , 0. , 0. , 1. ],
  159. [ 0. , 1.92136365, 1.21170993, 0. , -0.68961901,
  160. 0. , 1. , 0. , 0. , 1. ],
  161. [ 0. , -1.33624452, -1.24023352, 0. , -0.87200401,
  162. 0. , 0. , 1. , 0. , 1. ],
  163. [ 1. , -0.45474979, -0.73727076, 0. , 1.87679853,
  164. 0. , 1. , 0. , 0. , 1. ],
  165. [ 0. , 0.46803275, 1.65180234, 1. , -1.02833401,
  166. 0. , 1. , 0. , 0. , 1. ],
  167. [ 0. , 0.39337063, 0.20578441, 0. , 1.53808353,
  168. 0. , 0. , 1. , 0. , 1. ],
  169. [ 0. , 0.49555796, 1.08596924, 1. , 1.14725852,
  170. 0. , 0. , 1. , 0. , 1. ],
  171. [ 0. , -0.42860084, -0.9258818 , 0. , -0.74172901,
  172. 0. , 0. , 0. , 0. , 1. ],
  173. [ 0. , 0.34416932, 0.01717338, 0. , -1.04136151,
  174. 0. , 0. , 1. , 0. , 1. ],
  175. [ 1. , -0.5817098 , -1.42884455, 1. , 0.50891101,
  176. 0. , 0. , 0. , 0. , 1. ],
  177. [ 1. , -1.40161689, -1.4917149 , 0. , 0.09203101,
  178. 1. , 0. , 0. , 0. , 1. ],
  179. [ 0. , 0.34210493, -0.48578938, 0. , 2.09826604,
  180. 0. , 0. , 1. , 0. , 1. ],
  181. [ 0. , -0.34946587, 0.26865475, 0. , 2.09826604,
  182. 1. , 0. , 0. , 0. , 1. ],
  183. [ 0. , 0.93527313, 0.3315251 , 1. , -1.09347151,
  184. 0. , 0. , 1. , 0. , 1. ],
  185. [ 0. , 0.49074105, -0.48578938, 0. , -0.87200401,
  186. 1. , 0. , 0. , 0. , 1. ],
  187. [ 0. , -0.70454104, -0.98875214, 1. , 0.31349851,
  188. 0. , 0. , 0. , 0. , 1. ],
  189. [ 0. , 1.95542609, 1.58893199, 0. , -0.5463165 ,
  190. 0. , 0. , 0. , 0. , 1. ],
  191. [ 0. , 0.56161845, -0.36004869, 1. , 1.59019353,
  192. 1. , 0. , 0. , 0. , 1. ],
  193. [ 0. , 0.93871378, -0.10856731, 1. , -0.97622401,
  194. 0. , 0. , 1. , 0. , 1. ],
  195. [ 0. , -0.10208308, 0.3315251 , 0. , -0.83292151,
  196. 0. , 1. , 0. , 0. , 1. ],
  197. [ 0. , -0.56140996, -1.36597421, 0. , 0.88670852,
  198. 0. , 0. , 0. , 0. , 1. ],
  199. [ 0. , 0.34416932, -0.61153007, 0. , 0.11808601,
  200. 0. , 1. , 0. , 0. , 1. ]])
  201.  
  202. array([ 3, 11, 3, 4, 6, 11, 9, 2, 13, 4, 1, 10, 13, 8, 5, 8, 1,
  203. 11, 1, 10, 6, 3, 8, 3, 8, 2, 20, 9, 13, 9, 3, 4, 8, 2,
  204. 1, 3, 5, 6, 3, 1, 3, 9, 2, 14, 4, 9, 4, 13, 10, 2, 15,
  205. 1, 2, 8, 4, 12, 14, 3, 13, 3, 11, 7, 10, 10, 6, 13, 5, 5,
  206. 10, 9, 2, 4, 5, 3, 19, 5, 4, 2, 7, 5, 6, 1, 9, 1, 1,
  207. 1, 12, 5, 11, 3, 5, 12, 2, 3, 3, 4, 3, 5, 2, 4])
  208.  
  209. class TotalReservations(object):
  210. """ Class to carry out machine learning tasks """
  211.  
  212.  
  213.  
  214. def __init__(self,train_X_std,train_Y,test_X_std,test_Y,estimator,param_grid):
  215. """ Constructor to initialze the data
  216.  
  217. """
  218.  
  219. self.train_X=train_X_std
  220. self.train_Y=train_Y
  221. self.test_X=test_X_std
  222. self.test_Y=test_Y
  223. # The hyper parameter grid for this estimator
  224. self.param_grid=param_grid
  225. # The actual ML estimator from sklearn
  226. self.estimator=estimator
  227.  
  228.  
  229.  
  230. def grid_search(self):
  231.  
  232. """This function does Cross Validation using Grid Search
  233.  
  234. """
  235.  
  236. from sklearn.model_selection import GridSearchCV
  237. self.g_cv = GridSearchCV(estimator=self.estimator,param_grid=self.param_grid,cv=5)
  238. self.g_cv.fit(self.train_X,self.train_Y)
  239.  
  240.  
  241.  
  242. def train_performance(self):
  243. """ Method to get the training performance of the estimator across all parameters
  244.  
  245. """
  246.  
  247. self.mean_train_score=self.g_cv.cv_results_['mean_train_score']
  248. self.mean_val_score=self.g_cv.cv_results_['mean_test_score']
  249.  
  250. # Printing the Dummy Regressor score
  251. self.dummy_regressor(self.train_X,self.train_Y,self.test_X,self.test_Y)
  252.  
  253. print("nThe mean train scores are {}n".format(self.mean_train_score))
  254.  
  255. print("The mean validation scores are {}n".format(self.mean_val_score))
  256.  
  257. print("The score on held out data is: {score}n Hyper-Parameters for Best Score : {param}n"
  258. .format(score=self.g_cv.best_score_,param=self.g_cv.best_params_))
  259.  
  260. # For Ridge Regression
  261. from sklearn.linear_model import Ridge
  262. ridge_lr=Ridge(random_state=42)
  263.  
  264. #***************************************************************************************
  265.  
  266.  
  267. # Creating Hyperparameter values Grid for Random Forests
  268. # Actual to be used
  269.  
  270.  
  271. # Creating Hyperparameters values Grid for Ridge Regression
  272. grid_ridge={'alpha':[0.0001,0.001,0.01,0.1,1.0]}
  273.  
  274. td_ridge.grid_search()
  275.  
  276. # Training Performance of SGD Regressor
  277. td_ridge.train_performance()
  278.  
  279.  
  280. The mean train scores are [0.21945918 0.21945918 0.21945917 0.2194588 0.21942437]
  281.  
  282. The mean validation scores are [0.18215611 0.18215637 0.18215894 0.18218431 0.18240627]
  283.  
  284. The score on held out data is: 0.18240626691460574
  285. Hyper-Parameters for Best Score : {'alpha': 1.0}
  286.  
  287. The R2 Score of ridge_regressor on test data is: 0.17520249693363288
  288.  
  289. The mse of ridge_regressor on test data is: 17.791933297637534
  290. The mean absolute error of ridge_regressor on test data is: 3.381908224949849
Add Comment
Please, Sign In to add comment