We want to predict the time series of sunspots. Monthly data can be found at https://www.sidc.be/SILSO/datafiles. We want to predict future sunspot numbers using neural networks.
Y_train
with the values to be fitted and X_train
with the corresponding inputs. A reasonable number of inputs is 60 (the 60 values previous to Y) but you can experiment with different numbers. You can use the following code:
linp = 60
trainL = len(x)//4 *3
X_train = np.zeros((trainL-linp-1,linp))
Y_train = np.zeros((trainL-linp-1,1))
for i in range(trainL-linp-1):
X_train[i] = x[i:i+linp]
Y_train[i] = x[i+linp]
Create the arrays for testing on the remaining 1/4 of the data in the same way.
sklearn.neural_network.MLPRegressor
. Set early_stopping to False and validation_fraction to 0. You can try different numbers of layers, different layer sizes, and activation functions and compare their results - experiment with these parameters!partial_fit(X_train,Y_train)
function of your MLPRegressor and then calculate the mean squared error of your traing set and your validation set using the predict(X)
function of your MLPRegressor. In the end, plot the time evolution of the mean squared error of both traing and validation set in one figure (it might be helpful to set a log scale). In this way you can see, if the number of iterations you did was adequate, to few or to many, dependent on whehter or not after the last prediction the error on the validation set reached its minimum.sklearn.inspection.permutation_importance
on both the training set and the test set. Plot the result. Was the model trained well?fit(X_train,Y_train)
function with validation_fraction=0.1
und early_stopping=True
. Print the error on the training set and the test set.sklearn.inspection.permutation_importance
on both the training set and the test set. Plot the result.