MCPcopy Create free account
hub / github.com/chaoshangcs/GTS / historical_average_predict

Function historical_average_predict

scripts/eval_baseline_methods.py:12–36  ·  view source on GitHub ↗

Calculates the historical average of sensor reading. :param df: :param period: default 1 week. :param test_ratio: :param null_val: default 0. :return:

(df, period=12 * 24 * 7, test_ratio=0.2, null_val=0.)

Source from the content-addressed store, hash-verified

10
11
12def historical_average_predict(df, period=12 * 24 * 7, test_ratio=0.2, null_val=0.):
13 """
14 Calculates the historical average of sensor reading.
15 :param df:
16 :param period: default 1 week.
17 :param test_ratio:
18 :param null_val: default 0.
19 :return:
20 """
21 n_sample, n_sensor = df.shape
22 n_test = int(round(n_sample * test_ratio))
23 n_train = n_sample - n_test
24 y_test = df[-n_test:]
25 y_predict = pd.DataFrame.copy(y_test)
26
27 for i in range(n_train, min(n_sample, n_train + period)):
28 inds = [j for j in range(i % period, n_train, period)]
29 historical = df.iloc[inds, :]
30 y_predict.iloc[i - n_train, :] = historical[historical != null_val].mean()
31 # Copy each period.
32 for i in range(n_train + period, n_sample, period):
33 size = min(period, n_sample - i)
34 start = i - n_train
35 y_predict.iloc[start:start + size, :] = y_predict.iloc[start - period: start + size - period, :].values
36 return y_predict, y_test
37
38
39def static_predict(df, n_forward, test_ratio=0.2):

Callers 1

eval_historical_averageFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected