Exemple #1
0
                    spectralRadius=0.85,
                    inputScaling=0.0019,
                    reservoirScaling=0.07,
                    leakingRate=0.17,
                    initialTransient=0,
                    inputWeightRandom=inputWeightMatrix,
                    reservoirWeightRandom=reservoirWeight)
res.trainReservoir()

# Warm up
predictedTrainingOutputData = res.predict(featureVectors[-50:])

# Predict the future
predictedTestingOutputData = util.predictFutureDays(res, trainingSeries, depth, horizon)

error = metrics.RootMeanSquareError().compute(testingSeries.values.flatten().reshape(horizon,1), predictedTestingOutputData.values.flatten().reshape(horizon,1))
print("Regression error:"+str(error))

# Step 8 - De-scale the series
actualSeries = util.descaleSeries(testingSeries)
predictedSeries = util.descaleSeries(predictedTestingOutputData)

# Step 9 - Plot the results
details = profileName + "_horizon_" + str(horizon) + "_depth_" + str(depth) + "_network_size_" + str(size)
util.plotSeries("Outputs/Outputs_" + str(datetime.now()) + details,
                [actualSeries, predictedSeries], ["Actual Output", "Predicted Output"], "Facebook Own Posts Interaction Rate - "+profileName, "Interaction Rate")




# Train using linear regression
#model = SVR()
model = Pipeline([('poly', PolynomialFeatures(degree=3)),
                  ('linear', LinearRegression(fit_intercept=False))])
model.fit(featureVectors, targetVectors[:, 0])
predictedTrainingOutputData = model.predict(featureVectors)

# Descale
predictedTrainingOutputData = util.scalingFunction.inverse_transform(
    predictedTrainingOutputData)
targetVectors = util.scalingFunction.inverse_transform(targetVectors)

#targetVectors =actualSeries.values.reshape(actualSeries.values.shape[0],1)[depth:]

error = metrics.RootMeanSquareError().compute(
    targetVectors,
    predictedTrainingOutputData.reshape(predictedTrainingOutputData.shape[0],
                                        1))
print("Regression error:" + str(error))

#Plotting of the prediction output and error
outputFolderName = "Outputs/Outputs" + datetime.now().strftime(
    "%Y_%m_%d_%H_%M_%S")
os.mkdir(outputFolderName)
outplot = outputPlot.OutputPlot(outputFolderName + "/Prediction.html",
                                "Facebook Fans Change - Linear Regression",
                                "Taylor Swift", "Time", "Output")
outplot.setXSeries(np.arange(1, n + 1))
outplot.setYSeries('Actual Output', targetVectors[:, 0])
outplot.setYSeries('Predicted Output', predictedTrainingOutputData)
outplot.createOutput()
print("Done!")