diff --git a/README.md b/README.md index 45e724fab..b4d6ce3a5 100644 --- a/README.md +++ b/README.md @@ -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 ------------ diff --git a/examples/python-guide/README.md b/examples/python-guide/README.md new file mode 100644 index 000000000..fd9fd4359 --- /dev/null +++ b/examples/python-guide/README.md @@ -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 +``` diff --git a/examples/python-guide/simple_example.py b/examples/python-guide/simple_example.py index d41304f44..a1442eafc 100644 --- a/examples/python-guide/simple_example.py +++ b/examples/python-guide/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) - diff --git a/python-package/lightgbm/__init__.py b/python-package/lightgbm/__init__.py index 6774b2bde..68a8eb8cc 100644 --- a/python-package/lightgbm/__init__.py +++ b/python-package/lightgbm/__init__.py @@ -21,3 +21,4 @@ __version__ = 0.1 __all__ = ['Dataset', 'Booster', 'train', 'cv', 'LGBMModel', 'LGBMRegressor', 'LGBMClassifier', 'LGBMRanker'] + diff --git a/python-package/lightgbm/engine.py b/python-package/lightgbm/engine.py index 0cf2d5f44..0de35e99d 100644 --- a/python-package/lightgbm/engine.py +++ b/python-package/lightgbm/engine.py @@ -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): """ diff --git a/src/boosting/gbdt.cpp b/src/boosting/gbdt.cpp index 7c5e9e68f..e6ec6ec27 100644 --- a/src/boosting/gbdt.cpp +++ b/src/boosting/gbdt.cpp @@ -416,17 +416,7 @@ std::string GBDT::DumpModel() const { ss << models_[i]->ToJSON(); ss << "}"; } - ss << "]," << std::endl; - - std::vector> 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; diff --git a/tests/python_package_test/test_basic.py b/tests/python_package_test/test_basic.py index 055d0b321..7dce36872 100644 --- a/tests/python_package_test/test_basic.py +++ b/tests/python_package_test/test_basic.py @@ -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)