Giter VIP home page Giter VIP logo

Comments (1)

jameslamb avatar jameslamb commented on June 4, 2024

Thanks for using LightGBM.

I've reformatted your post a bit to make the difference between code, output from code, and your own words a bit clearer. If you're new to GitHub and/or writing markdown, please see https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#quoting-code to learn about how I did that.


I don't immediately see what's wrong with your model file but in general... don't manually merge files like this. There are just too many ways for it to go wrong (mixed line endings, accidental inclusion of special characters, failure to update all parameters correctly, etc.).

If it's acceptable to not be training both models at the same time, do this:

  1. train the first model
  2. save it to a text file with .save_model()
  3. move that file over to the other machine
  4. train another model on that machine, with new data, passing the path to the first model file to init_model

That will cause LightGBM to begin boosting from the end of the first model, using your new dataset. It's not exactly the same as the process you described (where you train two models from scratch and then combine them), but it's a good way to incorporate learnings from new data into an already-training model.

Like this pattern:

init_gbm = lgb.train(params, lgb_train, num_boost_round=20)
model_name = "model.txt"
init_gbm.save_model(model_name)
evals_result = {}
gbm = lgb.train(
params,
lgb_train,
num_boost_round=30,
valid_sets=lgb_eval,
# test custom eval metrics
feval=(lambda p, d: ("custom_mae", mean_absolute_error(p, d.get_label()), False)),
callbacks=[lgb.record_evaluation(evals_result)],
init_model="model.txt",
)

There are some more details on how to do this at https://stackoverflow.com/questions/73664093/lightgbm-train-vs-update-vs-refit/73669068#73669068


There is an API in LightGBM's C API, LGBM_BoosterMerge(), that I believe can be used to take 2 models and combine them together without training, but it's not currently exposed in the Python package.

LightGBM/src/c_api.cpp

Lines 2008 to 2009 in 28536a0

int LGBM_BoosterMerge(BoosterHandle handle,
BoosterHandle other_handle) {

We could consider adding that in the Python package.

from lightgbm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.