Commit 55de8ea6 authored by Yuyu Zhang's avatar Yuyu Zhang Committed by Guolin Ke
Browse files

Update Python-intro.md (#573)

Some format fix
parent a8adaa92
...@@ -104,7 +104,7 @@ Setting Parameters ...@@ -104,7 +104,7 @@ Setting Parameters
LightGBM can use either a list of pairs or a dictionary to set [parameters](./Parameters.md). For instance: LightGBM can use either a list of pairs or a dictionary to set [parameters](./Parameters.md). For instance:
* Booster parameters * Booster parameters
```python ```python
param = {'num_leaves':31, 'num_trees':100, 'objective':'binary' } param = {'num_leaves':31, 'num_trees':100, 'objective':'binary'}
param['metric'] = 'auc' param['metric'] = 'auc'
``` ```
* You can also specify multiple eval metrics: * You can also specify multiple eval metrics:
...@@ -119,7 +119,7 @@ Training ...@@ -119,7 +119,7 @@ Training
Training a model requires a parameter list and data set. Training a model requires a parameter list and data set.
```python ```python
num_round = 10 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. After training, the model can be saved.
```python ```python
...@@ -132,7 +132,7 @@ json_model = bst.dump_model() ...@@ -132,7 +132,7 @@ json_model = bst.dump_model()
``` ```
A saved model can be loaded as follows: A saved model can be loaded as follows:
```python ```python
bst = lgb.Booster(model_file="model.txt") #init model bst = lgb.Booster(model_file='model.txt') #init model
``` ```
CV CV
...@@ -149,7 +149,7 @@ If you have a validation set, you can use early stopping to find the optimal num ...@@ -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. Early stopping requires at least one set in `valid_sets`. If there's more than one, it will use all of them.
```python ```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) bst.save_model('model.txt', num_iteration=bst.best_iteration)
``` ```
...@@ -170,5 +170,5 @@ ypred = bst.predict(data) ...@@ -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`: If early stopping is enabled during training, you can get predictions from the best iteration with `bst.best_iteration`:
```python ```python
ypred = bst.predict(data,num_iteration=bst.best_iteration) ypred = bst.predict(data, num_iteration=bst.best_iteration)
``` ```
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment