def formFeatureTargetVectors(data, depth=1, horizon=1): # Pre-process the data and form feature and target vectors tsp = ts.TimeSeriesProcessor(data, depth, horizon) featureVectors, targetVectors = tsp.getProcessedData() featureVectors = featureVectors.reshape(featureVectors.shape[0], depth, 1) return featureVectors, targetVectors
# Normalize the raw data minMax = pp.MinMaxScaler((0,1)) rawData[:, valueIndex] = minMax.fit_transform(rawData[:, valueIndex]) # Read until the horizon actualData = rawData[rawData.shape[0]-horizon:, valueIndex] rawData = rawData[:rawData.shape[0]-horizon, :] # Available data - to store known and unknown availableData = np.zeros((rawData.shape[0]+horizon,4)) availableData[:rawData.shape[0], 0:3] = rawData[:, 0:3] availableData[:rawData.shape[0], 3] = rawData[:, valueIndex] #Pre-Process the data to form feature and target vectors tsp = ts.TimeSeriesProcessor(rawData[:, valueIndex], depth, 1) processedData = tsp.getProcessedData() #Append bias processedData = np.hstack((np.ones((processedData.shape[0], 1)),processedData)) #Training data trainingInputData = processedData[:,:1+depth] trainingOutputData = processedData[:,1+depth:] #Validation data validationInputData = trainingInputData validationOutputData = trainingOutputData #Tune the reservoir
from performance import ErrorMetrics as rmse from datetime import datetime import numpy as np import os from datetime import date, timedelta from timeseries import TimeSeries as ts # Read data from the file rawData = np.loadtxt("facebookFansHistory_bmw_raw.txt", delimiter=',') data = rawData[:rawData.shape[0], rawData.shape[1] - 1].reshape( (rawData.shape[0], 1)) depth = 1 horizon = 1 tsp = ts.TimeSeriesProcessor(rawData, depth, horizon, 4) processedData = tsp.getProcessedData() inputData = np.hstack((np.ones((processedData.shape[0], 1)), processedData[:processedData.shape[0], :depth])) outputData = processedData[:processedData.shape[0], depth:depth + horizon] # Train inputWeightRandom = np.load("Outputs/inputWeight.npy") reservoirWeightRandom = np.load("Outputs/reservoirWeight.npy") res = reservoir.Reservoir(size=600, spectralRadius=1.25, inputScaling=0.50, reservoirScaling=0.50, leakingRate=0.20, initialTransient=0,