Commit 69114525 authored by wxchan's avatar wxchan
Browse files

solve conflicts; add README for python examples

parents eba6d200 6c1a74ab
...@@ -17,7 +17,7 @@ For more details, please refer to [Features](https://github.com/Microsoft/LightG ...@@ -17,7 +17,7 @@ For more details, please refer to [Features](https://github.com/Microsoft/LightG
News News
---- ----
12/02/2012 : Release [python-package](https://github.com/Microsoft/LightGBM/tree/master/python-package) beta version, welcome to have a try and provide issues and feedback. 12/02/2016 : Release [python-package](https://github.com/Microsoft/LightGBM/tree/master/python-package) beta version, welcome to have a try and provide issues and feedback.
Get Started Get Started
------------ ------------
......
Python Package Example
=====================
Here is an example for LightGBM to use python package.
***You should install lightgbm (both c++ and python verion) first.***
For the installation, check the wiki [here](https://github.com/Microsoft/LightGBM/wiki/Installation-Guide).
You also need scikit-learn and pandas to run the examples, but they are not required for the package itself. You can install them with pip:
```
pip install -U scikit-learn
pip install -U pandas
```
Now you can run examples in this folder, for example:
```
python simple_example.py
```
...@@ -62,4 +62,3 @@ model_json = gbm.dump_model() ...@@ -62,4 +62,3 @@ model_json = gbm.dump_model()
with open('model.json', 'w+') as f: with open('model.json', 'w+') as f:
json.dump(model_json, f, indent=4) json.dump(model_json, f, indent=4)
...@@ -21,3 +21,4 @@ __version__ = 0.1 ...@@ -21,3 +21,4 @@ __version__ = 0.1
__all__ = ['Dataset', 'Booster', __all__ = ['Dataset', 'Booster',
'train', 'cv', 'train', 'cv',
'LGBMModel', 'LGBMRegressor', 'LGBMClassifier', 'LGBMRanker'] 'LGBMModel', 'LGBMRegressor', 'LGBMClassifier', 'LGBMRanker']
...@@ -245,13 +245,14 @@ class CVBooster(object): ...@@ -245,13 +245,14 @@ class CVBooster(object):
return self.booster.eval_valid(feval) return self.booster.eval_valid(feval)
try: try:
try: from sklearn.model_selection import StratifiedKFold
from sklearn.model_selection import StratifiedKFold
except ImportError:
from sklearn.cross_validation import StratifiedKFold
SKLEARN_StratifiedKFold = True SKLEARN_StratifiedKFold = True
except ImportError: except ImportError:
SKLEARN_StratifiedKFold = False try:
from sklearn.cross_validation import StratifiedKFold
SKLEARN_StratifiedKFold = True
except ImportError:
SKLEARN_StratifiedKFold = False
def _make_n_folds(full_data, nfold, param, seed, fpreproc=None, stratified=False): def _make_n_folds(full_data, nfold, param, seed, fpreproc=None, stratified=False):
""" """
......
...@@ -416,17 +416,7 @@ std::string GBDT::DumpModel() const { ...@@ -416,17 +416,7 @@ std::string GBDT::DumpModel() const {
ss << models_[i]->ToJSON(); ss << models_[i]->ToJSON();
ss << "}"; ss << "}";
} }
ss << "]," << std::endl; ss << "]" << std::endl;
std::vector<std::pair<size_t, std::string>> pairs = FeatureImportance();
ss << "\"feature_importances\":{" << std::endl;
for (size_t i = 0; i < pairs.size(); ++i) {
if (i > 0) {
ss << ",";
}
ss << "\"" << pairs[i].second << "\":" << pairs[i].first;
}
ss << "}" << std::endl;
ss << "}" << std::endl; ss << "}" << std::endl;
......
...@@ -3,8 +3,8 @@ import numpy as np ...@@ -3,8 +3,8 @@ import numpy as np
from sklearn import datasets, metrics, model_selection from sklearn import datasets, metrics, model_selection
import lightgbm as lgb import lightgbm as lgb
X, Y = datasets.make_classification(n_samples=100000, n_features=100, random_state=42) X, Y = datasets.make_classification(n_samples=100000, n_features=100)
x_train, x_test, y_train, y_test = model_selection.train_test_split(X, Y, test_size=0.1, random_state=42) x_train, x_test, y_train, y_test = model_selection.train_test_split(X, Y, test_size=0.1)
train_data = lgb.Dataset(x_train, max_bin=255, label=y_train) train_data = lgb.Dataset(x_train, max_bin=255, label=y_train)
valid_data = train_data.create_valid(x_test, label=y_test) valid_data = train_data.create_valid(x_test, label=y_test)
......
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