-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlightgbm_short.py
48 lines (41 loc) · 1.4 KB
/
lightgbm_short.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import pandas as pd
import numpy as np
from statistics import mean
import math
from datetime import datetime
import statistics as st
import datetime
import time
import pickle
import random
import lightgbm as lgb
from sklearn.metrics import mean_squared_error
from sklearn.metrics import make_scorer
from sklearn.model_selection import train_test_split
#Load the file containing variables [X_train, y_train, X_test, y_test]
with open(r"../data-x-li-data/df_merged_train_test_005p.pickle", "rb") as input_file:
X_train, y_train, X_test, y_test = pickle.load(input_file)
#%reset -f
SEED = 333
def mean_absolute_percentage_error(y_true, y_pred):
return np.mean(np.abs((y_true - y_pred) / y_true)) * 100
# Instantiate a lgb.LGBMRegressor
#lgbm0 = lgb.LGBMRegressor(seed=SEED)
lgbm0 = lgb.LGBMRegressor(n_estimators = 14000, max_depth = 8, learning_rate = 0.283, min_data_in_leaf = 20, seed=SEED)
print(lgbm0)
# Fit with SciKit
print(datetime.datetime.now())
lgbm0.fit(X_train, y_train)
print(datetime.datetime.now())
def predict_and_evaluate(x_t, y_t):
# Predict the test set labels 'y_pred0'
y_pred0 = lgbm0.predict(x_t)
# Evaluate the test set RMSE
MAPE_t0 = mean_absolute_percentage_error(y_t, y_pred0)
print(MAPE_t0)
print(datetime.datetime.now())
print(datetime.datetime.now())
print('test MAPE:')
predict_and_evaluate(X_test, y_test)
print('train MAPE:')
predict_and_evaluate(X_train, y_train)