Skip to content

Instantly share code, notes, and snippets.

@rajarsheem
Created January 13, 2016 00:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save rajarsheem/756bab91d4e7ce074ba5 to your computer and use it in GitHub Desktop.
Save rajarsheem/756bab91d4e7ce074ba5 to your computer and use it in GitHub Desktop.
Predict Web Traffic
# 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