Guest User

Untitled

a guest
Apr 25th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. #scaling data
  2. scaler_x = preprocessing.MinMaxScaler(feature_range =(-1, 1))
  3. x = np.array(x).reshape ((len(x),11 ))
  4. x = scaler_x.fit_transform(x)
  5. scaler_y = preprocessing.MinMaxScaler(feature_range =(-1, 1))
  6. y = np.array(y).reshape ((len(y), 1))
  7. y = scaler_y.fit_transform(y)
  8.  
  9. # Split train and test data
  10. x_train=x[0: train_end ,]
  11. x_test=x[train_end +1: ,]
  12. y_train=y[0: train_end]
  13. y_test=y[train_end +1:]
  14. x_train=x_train.reshape(x_train.shape +(1,))
  15. x_test=x_test.reshape(x_test.shape + (1,))
  16. # Train and save the Model named fit1 in a json and h5 files
  17. [....]
  18. # serialize model to JSON
  19. model_json = fit1.to_json()
  20. with open("model.json", "w") as json_file:
  21. json_file.write(model_json)
  22. # serialize weights to HDF5
  23. fit1.save_weights("model.h5")
  24. print(">>>> Model saved to model.h5 in the disk")
  25.  
  26. from DailyDemand import scaler_y
  27. from DailyDemand import scaler_x
  28. [...]
  29. # load json and create model
  30. json_file = open('model.json', 'r')
  31. loaded_model_json = json_file.read()
  32. json_file.close()
  33. loaded_model = model_from_json(loaded_model_json)
  34. # load weights into new model
  35. loaded_model.load_weights("model.h5")
  36. print("Loaded model from disk")
  37.  
  38. ########################################
  39. # make prediction with the loaded model
  40.  
  41. FeaturesTest = [267,61200,695,677,70600,116700,130200,768,659,741,419300]
  42. xaa = np.array(FeaturesTest).reshape ((1,11 )).astype(float)
  43. print(xaa)
  44. xaa = scaler_x.fit_transform(xaa)
  45. xaa = xaa.reshape(xaa.shape +(1,))
  46. print("print FeaturesTest scalled: ")
  47. print(xaa) # incorrect scalled value, always returns -1 ones
  48.  
  49. xaa = [[[-1.]
  50. [-1.]
  51. [-1.]
  52. [-1.]
  53. [-1.]
  54. [-1.]
  55. [-1.]
  56. [-1.]
  57. [-1.]
  58. [-1.]
  59. [-1.]]]
  60.  
  61. tomorrowDemand = loaded_model.predict(xaa)
  62. print("tomorrowDemand scalled: ", tomorrowDemand)
  63. prediction = scaler_y.inverse_transform(np.array(tomorrowDemand).reshape ((len(tomorrowDemand), 1))).astype(int)
  64. print ("la demande reelle est 95900 et la prediction est: ", prediction)
  65.  
  66. xaa = scaler_x.fit_transform(xaa)
  67.  
  68. xaa = scaler_x.transform(xaa)
Add Comment
Please, Sign In to add comment