1
$\begingroup$

I'm trying to do time series forecasting with linear regression like it's done in this video: Radial basis forecasting starting from 5:50.

I understand the basic idea of basis, but I don't think I understood the usage of it in time series data correctly. I have a Pandas dataframe with daily timestamps and target variables. I tried writing radial basis function

def radial_basis(x, month):
    alpha = 0.5
    coef = -1/(2*alpha)
    return np.exp(coef*(x-month)**2)

and calculating basis for every month (x is row number). This didn't work.

Any tips on how I should try to do this?

$\endgroup$
0
$\begingroup$

I was able to solve this by myself. First you need to create a column that contains day of year values from the timestamps. Then apply radial_basis function for that column with month parameter being the middle day of every month. For example in January it's 15, February 45 etc.

With this method you can generate a spike for every month.

data_all['Day'] = data_all.Timestamp.dt.dayofyear

def radial_basis(x, month):
    alpha = 8
    coef = -1/(2*alpha)
    return np.exp(coef*(x-month)**2)

for i in range(12):
    col = 'RB' + str(i+1)
    data_all[col] = data_all.Day.apply(radial_basis, month=(15+30*i))

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.