solve conflicts; add README for python examples

This commit is contained in:
wxchan 2016-12-02 15:02:44 +08:00
Родитель eba6d200a8 6c1a74ab76
Коммит 6911452588
7 изменённых файлов: 29 добавлений и 20 удалений

Просмотреть файл

@ -17,7 +17,7 @@ For more details, please refer to [Features](https://github.com/Microsoft/LightG
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
------------

Просмотреть файл

@ -0,0 +1,18 @@
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()
with open('model.json', 'w+') as f:
json.dump(model_json, f, indent=4)

Просмотреть файл

@ -21,3 +21,4 @@ __version__ = 0.1
__all__ = ['Dataset', 'Booster',
'train', 'cv',
'LGBMModel', 'LGBMRegressor', 'LGBMClassifier', 'LGBMRanker']

Просмотреть файл

@ -245,13 +245,14 @@ class CVBooster(object):
return self.booster.eval_valid(feval)
try:
try:
from sklearn.model_selection import StratifiedKFold
except ImportError:
from sklearn.cross_validation import StratifiedKFold
from sklearn.model_selection import StratifiedKFold
SKLEARN_StratifiedKFold = True
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):
"""

Просмотреть файл

@ -416,17 +416,7 @@ std::string GBDT::DumpModel() const {
ss << models_[i]->ToJSON();
ss << "}";
}
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
from sklearn import datasets, metrics, model_selection
import lightgbm as lgb
X, Y = datasets.make_classification(n_samples=100000, n_features=100, random_state=42)
x_train, x_test, y_train, y_test = model_selection.train_test_split(X, Y, test_size=0.1, 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)
train_data = lgb.Dataset(x_train, max_bin=255, label=y_train)
valid_data = train_data.create_valid(x_test, label=y_test)