Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tianlh
LightGBM-DCU
Commits
55de8ea6
Commit
55de8ea6
authored
May 31, 2017
by
Yuyu Zhang
Committed by
Guolin Ke
Jun 01, 2017
Browse files
Update Python-intro.md (#573)
Some format fix
parent
a8adaa92
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
5 deletions
+5
-5
docs/Python-intro.md
docs/Python-intro.md
+5
-5
No files found.
docs/Python-intro.md
View file @
55de8ea6
...
...
@@ -104,7 +104,7 @@ Setting Parameters
LightGBM can use either a list of pairs or a dictionary to set
[
parameters
](
./Parameters.md
)
. For instance:
*
Booster parameters
```
python
param
=
{
'num_leaves'
:
31
,
'num_trees'
:
100
,
'objective'
:
'binary'
}
param
=
{
'num_leaves'
:
31
,
'num_trees'
:
100
,
'objective'
:
'binary'
}
param
[
'metric'
]
=
'auc'
```
*
You can also specify multiple eval metrics:
...
...
@@ -119,7 +119,7 @@ Training
Training a model requires a parameter list and data set.
```
python
num_round
=
10
bst
=
lgb
.
train
(
param
,
train_data
,
num_round
,
valid_sets
=
[
test_data
]
)
bst
=
lgb
.
train
(
param
,
train_data
,
num_round
,
valid_sets
=
[
test_data
])
```
After training, the model can be saved.
```
python
...
...
@@ -132,7 +132,7 @@ json_model = bst.dump_model()
```
A saved model can be loaded as follows:
```
python
bst
=
lgb
.
Booster
(
model_file
=
"
model.txt
"
)
#init model
bst
=
lgb
.
Booster
(
model_file
=
'
model.txt
'
)
#init model
```
CV
...
...
@@ -149,7 +149,7 @@ If you have a validation set, you can use early stopping to find the optimal num
Early stopping requires at least one set in
`valid_sets`
. If there's more than one, it will use all of them.
```
python
bst
=
train
(
param
,
train_data
,
num_round
,
valid_sets
=
valid_sets
,
early_stopping_rounds
=
10
)
bst
=
lgb
.
train
(
param
,
train_data
,
num_round
,
valid_sets
=
valid_sets
,
early_stopping_rounds
=
10
)
bst
.
save_model
(
'model.txt'
,
num_iteration
=
bst
.
best_iteration
)
```
...
...
@@ -170,5 +170,5 @@ ypred = bst.predict(data)
If early stopping is enabled during training, you can get predictions from the best iteration with
`bst.best_iteration`
:
```
python
ypred
=
bst
.
predict
(
data
,
num_iteration
=
bst
.
best_iteration
)
ypred
=
bst
.
predict
(
data
,
num_iteration
=
bst
.
best_iteration
)
```
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