SHARE
TWEET

Untitled

a guest Jun 18th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from sklearn.preprocessing import MinMaxScaler
  2. from sklearn.model_selection import TimeSeriesSplit
  3. from sklearn.model_selection import GridSearchCV
  4. from matplotlib import pyplot
  5. from sklearn.neural_network import MLPRegressor
  6. from sklearn.metrics import mean_squared_error
  7. import pandas as pd
  8.  
  9. dataset = pd.read_csv('champagne.csv', header=None)
  10.  
  11. scaler = MinMaxScaler()
  12. scaled_dataset = scaler.fit_transform(dataset)
  13.  
  14. mlpr = MLPRegressor(max_iter=7000)
  15.  
  16. param_list = {"hidden_layer_sizes": [1,50], "activation": ["identity", "logistic", "tanh", "relu"], "solver": ["lbfgs", "sgd", "adam"], "alpha": [0.00005,0.0005]}
  17. gridCV = GridSearchCV(estimator=mlpr, param_grid=param_list)
  18.  
  19. splits = TimeSeriesSplit(n_splits=3)
  20.  
  21. pyplot.figure(1)
  22. index = 1
  23.  
  24. for train_index, test_index in splits.split(scaled_dataset):
  25.  
  26.     training_set = scaled_dataset[train_index]
  27.     testing_set = scaled_dataset[test_index]
  28.  
  29.     train_index_array = train_index.reshape(-1,1)
  30.     test_index_array = test_index.reshape(-1,1)
  31.  
  32.     gridCV.fit(train_index_array, training_set)
  33.     predicted = gridCV.predict(test_index_array)
  34.     parameters = mlpr.get_params()
  35.  
  36.     test_mse = mean_squared_error(testing_set, predicted)
  37.  
  38.     pyplot.subplot(310 + index)
  39.     pyplot.plot(predicted)
  40.     pyplot.plot([None for i in training_set] + [x for x in testing_set])
  41.     index += 1
  42.  
  43.     train_index.flatten()
  44.     test_index.flatten()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top