First method: linear regression input : training data (date, total_user, total_event) in list of float output : list of total user prediction in float >>> n = linear_regression_prediction([2,3,4,5], [5,3,4,6], [3,1,2,4], [2,1], [2,2]) >>> bool(abs(n - 5.0) < 1e-6) # Checking pr
(
train_dt: list, train_usr: list, train_mtch: list, test_dt: list, test_mtch: list
)
| 21 | |
| 22 | |
| 23 | def linear_regression_prediction( |
| 24 | train_dt: list, train_usr: list, train_mtch: list, test_dt: list, test_mtch: list |
| 25 | ) -> float: |
| 26 | """ |
| 27 | First method: linear regression |
| 28 | input : training data (date, total_user, total_event) in list of float |
| 29 | output : list of total user prediction in float |
| 30 | >>> n = linear_regression_prediction([2,3,4,5], [5,3,4,6], [3,1,2,4], [2,1], [2,2]) |
| 31 | >>> bool(abs(n - 5.0) < 1e-6) # Checking precision because of floating point errors |
| 32 | True |
| 33 | """ |
| 34 | x = np.array([[1, item, train_mtch[i]] for i, item in enumerate(train_dt)]) |
| 35 | y = np.array(train_usr) |
| 36 | beta = np.dot(np.dot(np.linalg.inv(np.dot(x.transpose(), x)), x.transpose()), y) |
| 37 | return abs(beta[0] + test_dt[0] * beta[1] + test_mtch[0] + beta[2]) |
| 38 | |
| 39 | |
| 40 | def sarimax_predictor(train_user: list, train_match: list, test_match: list) -> float: |