Beispiel #1
0
    def __init__(self, a, d, p):
        self.aParamList = a
        self.dParamList = d
        self.pParamList = p

        #Output plot
        self.plot = outPlot.OutputTimeSeriesPlot("Gammafunctions.html",
                                                 "Gamma function",
                                                 "with different parameters",
                                                 "f(x)", "")
# Read the data
df = pd.read_csv('BMW_comments_interaction.csv',
                 index_col=0,
                 parse_dates=True,
                 names=['value'])

# Convert the dataframe into series
series = pd.Series(data=np.array(df.as_matrix()).flatten(), index=df.index)
resampled_series = series.resample(rule='H', how=_sum)

xAxis = []
yAxis = []
for index, value in resampled_series.iteritems():
    year = int(index.year)
    month = int(index.month) - 1
    day = int(index.day)
    hour = int(index.hour)
    nextDayStr = "Date.UTC(" + str(year) + "," + str(
        int(month)) + "," + str(day) + "," + str(hour) + ")"
    xAxis.append(nextDayStr)
    yAxis.append(str(value))

# Plotting of the actual and prediction output
outputFolderName = "Outputs/Outputs-Comments-Hourly" + str(datetime.now())
os.mkdir(outputFolderName)
outplot = plotting.OutputTimeSeriesPlot(outputFolderName + "/OwnPosts.html",
                                        "Facebook Comments-BMW", "",
                                        "Number of Comments")
outplot.setSeries('Own Posts', np.array(xAxis), np.array(yAxis))
outplot.createOutput()
    month = nextDate.strftime("%m")
    day = nextDate.strftime("%d")
    nextDayStr = "Date.UTC(" + year+","+ str((int(month)-1)) + "," + day +")"
    xAxis.append(nextDayStr)

    #Form the feature vectors
    feature = [1.0]
    for interval in featureIntervalList:
        feature.append(series[nextDate + interval])

    feature = np.array(feature).reshape((1,len(featureIntervalList)+1))

    predictedValue = res2.predict(feature)[0,0]
    predicted.append(predictedValue)

    #Add it to the series
    series[nextDate] = predictedValue


predicted2 = minMax.inverse_transform(np.array(predicted))

# Plotting of the actual and prediction output
outputFolderName = "Outputs/Outputs" + str(datetime.now()) + "_depth_" + str(depth) + "_horizon_" + str(horizon)
os.mkdir(outputFolderName)
outplot = outTimePlot.OutputTimeSeriesPlot(outputFolderName + "/Prediction.html", "Facebook Own posts-BMW", "", "Number of posts")
outplot.setSeries('Actual Output', np.array(xAxis), actualData)
outplot.setSeries('Predicted Output 1', np.array(xAxis), predicted1)
outplot.setSeries('Predicted Output 2', np.array(xAxis), predicted2)
outplot.createOutput()

    predictedDict[str(depth)] = deScaled

    #Calculate the error
    errorFunction = rmse.MeanSquareError()
    error = errorFunction.compute(actualData.reshape(1, horizon),
                                  deScaled.reshape(1, horizon))
    regressionError.append(error)

    xAxisError.append("Depth_" + str(depth))

# Plotting of the actual and prediction output
outputFolderName = "Outputs/Output" + str(
    datetime.now()) + "_depth_comparison_" + "_horizon_" + str(horizon)
os.mkdir(outputFolderName)
outplot = outTimePlot.OutputTimeSeriesPlot(
    outputFolderName + "/Prediction.html", "Comparison of prediction outputs",
    "with varying depths", "Likes Count")
outplot.setSeries('Actual Output', np.array(xAxis), actualData)
for depth in depthList:
    seriesName = 'Predicted_Output_depth' + str(depth)
    predicted = predictedDict[str(depth)]
    outplot.setSeries(seriesName, np.array(xAxis), predicted)
outplot.createOutput()

#Plotting of regression
errPlot = errorPlot.ErrorPlot(outputFolderName + "/Regression_Error.html",
                              "Comparison of regression error",
                              "with varying depths", "ESN Configuration",
                              "Total Error")
#X-axis
errPlot.setXAxis(np.array(xAxisError))
Beispiel #5
0
# Read the data
df = pd.read_csv('facebookPosts_ferrari_time_photo_interaction.csv',
                 index_col=0,
                 parse_dates=True,
                 names=['value'])

# Convert the dataframe into series
series = pd.Series(data=np.array(df.as_matrix()).flatten(), index=df.index)
resampled_series = series.resample(rule='H', how=_sum)

xAxis = []
yAxis = []
for index, value in resampled_series.iteritems():
    year = int(index.year)
    month = int(index.month) - 1
    day = int(index.day)
    hour = int(index.hour)
    nextDayStr = "Date.UTC(" + str(year) + "," + str(
        int(month)) + "," + str(day) + "," + str(hour) + ")"
    xAxis.append(nextDayStr)
    yAxis.append(str(value))

# Plotting of the actual and prediction output
outputFolderName = "Outputs/Outputs-OwnPosts-Hourly" + str(datetime.now())
os.mkdir(outputFolderName)
outplot = plotting.OutputTimeSeriesPlot(
    outputFolderName + "/OwnPosts.html",
    "Facebook Own Posts Interaction-Ferrari", "", "Interaction")
outplot.setSeries('Own Posts', np.array(xAxis), np.array(yAxis))
outplot.createOutput()
numberOfOUtliers = 0
for index, value in actualSeries.iteritems():
    year = index.strftime("%Y")
    month = index.strftime("%m")
    day = index.strftime("%d")
    hour = index.strftime("%H")
    nextDayStr = "Date.UTC(" + str(year) + "," + str(int(month) -
                                                     1) + "," + str(day) + ")"
    xAxis.append(nextDayStr)

    if (outlierSeries[index] == 1):
        color.append("red")
        radius.append(10)
        numberOfOUtliers += 1
    else:
        color.append("blue")
        radius.append(4)

# Step 4 - Plot the actual data
fileName = "/Outlier_Detection_Using_STD.html"
actualDataPlot = plot.OutputTimeSeriesPlot(
    outputFolderName + fileName, "Facebook Fans Change",
    "Outlier Detection using standard deviation approach", "Fans Change")

actualDataPlot.setSeriesWithColorAndRadius("Fans Change", np.array(xAxis),
                                           actualSeries.values.flatten(),
                                           np.array(color), np.array(radius))
actualDataPlot.createOutput()

print("Number of outliers: " + str(numberOfOUtliers))
Beispiel #7
0
    #Compose the query
    query = [1.0]
    for d in range(1, depth + 1):
        query.append(availableData[nextDayIndex - d, 3])

    nextDayPredicted = res.predict(np.array(query).reshape((1, depth + 1)))
    predictedOutput.append(nextDayPredicted[0, 0])

    #Update the available data
    availableData[nextDayIndex, 3] = nextDayPredicted[0, 0]
    availableData[nextDayIndex, 0] = int(year)
    availableData[nextDayIndex, 1] = int(month)
    availableData[nextDayIndex, 2] = int(day)

    lastDay = nextDay
    lastDayIndex = nextDayIndex

predicted = minMax.inverse_transform(np.array(predictedOutput))

# Plotting of the actual and prediction output
outputFolderName = "Outputs" + str(
    datetime.now()) + "_depth_" + str(depth) + "_horizon_" + str(horizon)
os.mkdir(outputFolderName)
outplot = outTimePlot.OutputTimeSeriesPlot(
    outputFolderName + "/Prediction.html", "Likes count for facebook page-BMW",
    "", "Likes Count")
outplot.setSeries('Actual Output', np.array(xAxis), actualData)
outplot.setSeries('Predicted Output', np.array(xAxis), predicted)
outplot.createOutput()