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
b8eae307
Commit
b8eae307
authored
Apr 12, 2019
by
linfang.wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
加入MySQL 连接
parent
313190e7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
17 deletions
+3
-17
xgboost.py
model/xgboost.py
+3
-17
No files found.
model/xgboost.py
View file @
b8eae307
...
@@ -32,14 +32,6 @@ def split_train_val(df, trainsplit = 'random', trainsplitRatio = 0.8, sort_col=N
...
@@ -32,14 +32,6 @@ def split_train_val(df, trainsplit = 'random', trainsplitRatio = 0.8, sort_col=N
val
=
None
val
=
None
return
train
,
val
return
train
,
val
# log 损失函数
def
logregobj
(
preds
,
dtrain
):
labels
=
dtrain
.
get_label
()
preds
=
1.0
/
(
1.0
+
np
.
exp
(
-
preds
))
grad
=
preds
-
labels
hess
=
preds
*
(
1.0
-
preds
)
return
grad
,
hess
def
buildClf
(
max_depth
=
2
,
learning_rate
=
0.1
,
n_estimators
=
5000
,
gamma
=
0
,
def
buildClf
(
max_depth
=
2
,
learning_rate
=
0.1
,
n_estimators
=
5000
,
gamma
=
0
,
min_child_weight
=
1
,
max_delta_step
=
0
,
subsample
=
0.8
,
colsample_bytree
=
0.8
,
reg_alpha
=
0
,
reg_lambda
=
1
,
min_child_weight
=
1
,
max_delta_step
=
0
,
subsample
=
0.8
,
colsample_bytree
=
0.8
,
reg_alpha
=
0
,
reg_lambda
=
1
,
...
@@ -105,12 +97,12 @@ def automodelfit(clf,param_grid,dftrain,features,resp, kfold=10,scoring='roc_auc
...
@@ -105,12 +97,12 @@ def automodelfit(clf,param_grid,dftrain,features,resp, kfold=10,scoring='roc_auc
return
grid_search
return
grid_search
def
modelfit
(
clf
,
dftrain
,
features
,
resp
,
dfval
=
None
,
useTrainCV
=
True
,
cv_folds
=
10
,
eval_metric
=
'auc'
,
early_stopping_rounds
=
20
):
def
modelfit
(
clf
,
dftrain
,
features
,
resp
,
useTrainCV
=
True
,
cv_folds
=
10
,
eval_metric
=
'auc'
,
early_stopping_rounds
=
20
):
'''
'''
模型训练
模型训练
:type useTrainCV: object
:param clf:XGBClassifier
:param clf:XGBClassifier
:param dftrain:训练集
:param dftrain:训练集
:param dfval 验证集用于模型训练,early_stopping_rounds
:param features: 特征
:param features: 特征
:param resp:label
:param resp:label
:param useTrainCV:if True call cv function,目的是调节参数 n_estimators
:param useTrainCV:if True call cv function,目的是调节参数 n_estimators
...
@@ -126,13 +118,7 @@ def modelfit(clf, dftrain, features, resp, dfval=None,useTrainCV = True, cv_fold
...
@@ -126,13 +118,7 @@ def modelfit(clf, dftrain, features, resp, dfval=None,useTrainCV = True, cv_fold
metrics
=
eval_metric
,
early_stopping_rounds
=
early_stopping_rounds
,
verbose_eval
=
True
)
metrics
=
eval_metric
,
early_stopping_rounds
=
early_stopping_rounds
,
verbose_eval
=
True
)
clf
.
set_params
(
n_estimators
=
cvresult
.
shape
[
0
])
clf
.
set_params
(
n_estimators
=
cvresult
.
shape
[
0
])
# Fit the algorithm on the data and save the model
clf
.
fit
(
dftrain
[
features
],
dftrain
[
resp
],
eval_metric
=
eval_metric
)
if
not
dfval
==
None
:
#== 如果有验证集的话,则无需进行cv运算 基于验证集auc early_stopping_rounds
clf
.
fit
(
dftrain
[
features
],
dftrain
[
resp
],
eval_set
=
[(
dftrain
[
features
],
dftrain
[
resp
]),
(
dfval
[
features
],
dfval
[
resp
])],
eval_metric
=
eval_metric
,
early_stopping_rounds
=
early_stopping_rounds
)
else
:
clf
.
fit
(
dftrain
[
features
],
dftrain
[
resp
],
eval_metric
=
eval_metric
)
return
clf
return
clf
...
...
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