代码拉取完成,页面将自动刷新
# import numpy as np
import pandas as pd
from sklearn.model_selection import StratifiedKFold
# import lightgbm as lgbm
# import _pickle as pickle
import time
from lightgbm.sklearn import LGBMClassifier
from sklearn.model_selection import GridSearchCV
from scipy.sparse import csr_matrix
import warnings
warnings.filterwarnings("ignore")
begin_time = time.time()
def timer(s=0):
global begin_time
if s == 1:
begin_time = time.time()
else:
print(time.time() - begin_time)
X_train = pd.read_pickle("pkl/X_train")
X_train = X_train.sample(n=2000000, random_state=0, axis=0)
print("X_train read")
X_train = csr_matrix(X_train)
print("CSR")
y_train = pd.read_pickle("pkl/y_train")
y_train = y_train.sample(n=2000000, random_state=0, axis=0)
MAX_ROUNDS = 10000
kfold = StratifiedKFold(n_splits=3, shuffle=True, random_state=3)
params = {'boosting_type': 'gbdt',
'objective': 'binary',
'n_jobs': -1,
'learning_rate': 0.1,
'n_estimators': 863,
'max_depth': 7,
'num_leaves': 63,
'max_bin': 127, #2^6,原始特征为整数,很少超过100
'subsample': 0.7,
'bagging_freq': 1,
'colsample_bytree': 0.7,
'verbose=': -1
}
lg = LGBMClassifier(silent=False, **params)
min_child_samples_s = range(10,50,10)
tuned_parameters = dict( min_child_samples = min_child_samples_s)
grid_search2 = GridSearchCV(lg, n_jobs= -1, param_grid=tuned_parameters, cv = kfold, scoring="neg_log_loss", verbose=-1, refit = False)
grid_search2.fit(X_train , y_train)
fo = open("res.txt", "a+")
fo.write("min_child_samples: " + str(grid_search2.best_params_) + "\n")
fo.close()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。