Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
model_mvp
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
decision-science
model_mvp
Commits
45721de0
Commit
45721de0
authored
Apr 22, 2019
by
王家华
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
debug
parent
b5a3f366
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
293 additions
and
214 deletions
+293
-214
__init__.cpython-37.pyc
models/__pycache__/__init__.cpython-37.pyc
+0
-0
xgboost.cpython-37.pyc
models/__pycache__/xgboost.cpython-37.pyc
+0
-0
lightgbm.py
models/lightgbm.py
+51
-1
__init__.cpython-37.pyc
mvp/__pycache__/__init__.cpython-37.pyc
+0
-0
dhb.cpython-37.pyc
mvp/__pycache__/dhb.cpython-37.pyc
+0
-0
xgbreport.cpython-37.pyc
mvp/__pycache__/xgbreport.cpython-37.pyc
+0
-0
dhb.py
mvp/dhb.py
+240
-210
lgbreport.py
mvp/lgbreport.py
+2
-3
No files found.
models/__pycache__/__init__.cpython-37.pyc
0 → 100644
View file @
45721de0
File added
models/__pycache__/xgboost.cpython-37.pyc
0 → 100644
View file @
45721de0
File added
models/lightgbm.py
View file @
45721de0
import
lightgbm
as
lgb
from
sklearn.metrics
import
roc_auc_score
from
sklearn.model_selection
import
GridSearchCV
from
sklearn.metrics
import
confusion_matrix
,
mean_squared_error
import
numpy
import
pandas
...
...
@@ -21,8 +22,9 @@ params = {
'verbose'
:
1
# <0 显示致命的, =0 显示错误 (警告), >0 显示信息
}
'''
'''
instructions : training lightgbm model with specified params
Parameters :
...
...
@@ -33,5 +35,53 @@ Parameters :
'''
def
lgb_train
(
params
,
training_set
,
features
,
target
):
lgb_train
=
lgb
.
Dataset
(
training_set
[
features
],
training_set
[
target
])
#lgb.train(params,)
return
1
'''
instructions : build a lgb classifier
Params :
'''
def
buildClf
(
params
):
return
lgb
.
LGBMClassifier
(
params
)
'''
'''
def
automodelfit
(
clf
,
param_grid
,
dftrain
,
features
,
resp
,
kfold
=
10
,
scoring
=
'roc_auc'
):
# kflod=StratifiedKFold(n_splits=kfold,shuffle=True,random_state=7)
grid_search
=
GridSearchCV
(
clf
,
param_grid
,
scoring
=
scoring
,
n_jobs
=
2
,
cv
=
kfold
,
verbose
=
2
,
iid
=
True
,
refit
=
True
)
#== 模型训练
grid_search
.
fit
(
dftrain
[
features
],
dftrain
[
resp
])
#== 获取最优参数
return
grid_search
def
modelfit
(
clf
,
dftrain
,
features
,
resp
,
useTrainCV
=
True
,
kfold
=
10
,
eval_metric
=
'auc'
,
early_stopping_rounds
=
20
):
'''
模型训练
:type useTrainCV: object
:param clf:XGBClassifier
:param dftrain:训练集
:param features: 特征
:param resp:label
:param useTrainCV:if True call cv function,目的是调节参数 n_estimators
:param cv_folds: N 折交叉验证
:param early_stopping_rounds:添加数loss变化不大这个状态持续的轮数,达到这个数就退出训练过程
:param eval_metric 同 目标函数 objective 有关,取值https://xgboost.readthedocs.io/en/latest/python/python_api.html#
:return:
'''
if
useTrainCV
:
# kflod = StratifiedKFold(n_splits=kfold, shuffle=True, random_state=7)
xgb_param
=
clf
.
get_xgb_params
()
xgtrain
=
lgb
.
DMatrix
(
dftrain
[
features
]
.
values
,
label
=
dftrain
[
resp
]
.
values
)
cvresult
=
lgb
.
cv
(
xgb_param
,
xgtrain
,
num_boost_round
=
clf
.
get_params
()[
'n_estimators'
],
nfold
=
kfold
,
metrics
=
eval_metric
,
early_stopping_rounds
=
early_stopping_rounds
,
verbose_eval
=
True
)
clf
.
set_params
(
n_estimators
=
cvresult
.
shape
[
0
])
clf
.
fit
(
dftrain
[
features
],
dftrain
[
resp
],
eval_metric
=
eval_metric
)
return
clf
mvp/__pycache__/__init__.cpython-37.pyc
0 → 100644
View file @
45721de0
File added
mvp/__pycache__/dhb.cpython-37.pyc
0 → 100644
View file @
45721de0
File added
mvp/__pycache__/xgbreport.cpython-37.pyc
0 → 100644
View file @
45721de0
File added
mvp/dhb.py
View file @
45721de0
This diff is collapsed.
Click to expand it.
mvp/lgbreport.py
View file @
45721de0
...
...
@@ -6,7 +6,6 @@ from data.analyis import datacal
from
models
import
xgboost
from
matplotlib
import
pyplot
as
plt
from
data.graph
import
drawplot
import
dhb
from
mvp
import
dhb
from
data.datasource
import
mysqldb
,
mongodb
dhb
=
dhb
()
df_dhb
=
dhb
.
dhb_features_extract
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment