Created
January 13, 2016 00:21
-
-
Save rajarsheem/756bab91d4e7ce074ba5 to your computer and use it in GitHub Desktop.
Predict Web Traffic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Problem link : https://www.hackerrank.com/challenges/time-series-prediction | |
from sklearn import linear_model as lm | |
import sys | |
import pandas as pd | |
import numpy as np | |
import statsmodels.api as sm | |
def sampling(data,prev): | |
n = len(data) | |
i = np.random.randint(prev, n - 1) | |
x = np.arange(i - prev, i) | |
return [data[t] for t in x], data[i] | |
n = int(input()) | |
traffic = [] | |
for i in range(n): | |
traffic.append(int(input())) | |
offset = 7 | |
last = 130 | |
X = [] | |
for t in range(n - last, n): | |
z = [t] | |
z.extend([1 if w == t % offset else 0 for w in range(offset)]) | |
X.append(z) | |
Y = traffic[-last:] | |
r = sm.OLS(Y, X).fit() | |
X = [] | |
for t in range(30): | |
z = [n + t] | |
z.extend([1 if w == (n + t) % offset else 0 for w in range(offset)]) | |
X.append(z) | |
ans = r.predict(X) | |
for x in ans: | |
print(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment