Giter Club home page Giter Club logo

asymmetric_loss's Introduction

Hello Internet! I am Vincent, a Software Engineer based in Switzerland. I have been focusing on Data Engineering and Machine Learning Operations (MLOps) over the past few years: data pipelines, CI/CD frameworks, workflow management, APIs..

So far, I have worked in several domains, namely public health, financial services and consumer electronics. I conducted a wide variety of projects involving tools like containers (e.g. Docker, Kubernetes), cloud providers (AWS, GCP), distributed computing (e.g. Spark), databases (e.g. Snowflake) and Machine Learning (e.g PyTorch, XGBoost, pandas, scikit-learn...). I use Linux shells, Git/GitHub, Python and SQL on a daily basis.

I created this GitHub account to archive projects and code that might be useful to other people, including future me. All the content is under MIT license. Feel free to use anything you may find interesting. You can find more digestible versions of most of these repositories on my blog, blog.vlgdata.io. I am also on LinkedIn.

Thanks for reading!

Links

asymmetric_loss's People

Contributors

datatrigger avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

asymmetric_loss's Issues

Model predicts negative values

I am using XGBoost for a sequence to sequence prediction task where the objective is to predict the next m hours of prices given n hours of historical prices.

When I use the LINEX loss with XGBoost for this time series forecasting problem, 100 % of the model's predicted values are negative, despite very few of the observations in the dataset being negative.

I suspect this is because the model learns that producing negative predictions leads to the lowest loss. That is, taking the exponent of negative values gives small values, and the exponent part of the gradient and hessian computations dominates the results of the computations. Below, we can see that underpredicting by 2 produces values that are much smaller than over-predicting by 2.

underpred = 8
overpred = 12
y = 10
a = 1.5 

gradient_underpred = (2/a) * ( np.exp(a * (underpred-y)) - 1 ) # -1.2669505755095147
gradient_overpred = (2/a) * ( np.exp(a * (overpred-y)) - 1 ) # 25.447382564250223

hessian_underpred = 2 * np.exp(a * (underpred-y)) # 0.09957413673572789
hessian_overpred = 2 * np.exp(a * (overpred-y)) # 40.171073846375336

This is, of course, how LINEX is intended to work, but it seems does its job so well that predictions made with an XGBoost with the LINEX objective become useless.

The negative predictions might also be caused by something else that I haven't discovered.

Any suggestions for what my cause the problem and how to mitigate it?

Below is the full code except for the LINEX code as I copy-pasted your code.

Note that the data are np.arrays.

Shapes of data:
xgb_training_data_x: (37117, 72), i.e. 37117 instances of sequences that are 72 values long
xgb_training_data_y: (37117, 58), i.e. 37117 instances of sequences that are 58 values long
xgb_test_data_x: (4469, 72), i.e. 4469 instances of sequences that are 72 values long

a = 0.001
mode = "underestimate"

model_linex = xgb.XGBRegressor(
    learning_rate =0.2,
    n_estimators=10,#150,
    max_depth=4,#8,
    min_child_weight=1,
    gamma=0.0,
    subsample=0.8,
    colsample_bytree=0.8,
    scale_pos_weight=1,
    seed=42,
    objective=linex.get_linex_function(a=a, mode=mode)
    )

model = xgb.XGBRegressor(
    learning_rate =0.2,
    n_estimators=10,#150,
    max_depth=4,#8,
    min_child_weight=1,
    gamma=0.0,
    subsample=0.8,
    colsample_bytree=0.8,
    scale_pos_weight=1,
    seed=42
    )

# The fit() procedure produces a warning:
# "UserWarning: Use subset (sliced data) of np.ndarray is not recommended" 
# But the warning is expected behavior: 
# https://github.com/dmlc/xgboost/issues/6908 
# https://stackoverflow.com/questions/67225016/warning-occuring-in-xgboost
# It seems the data becomes sliced because of the MultiOutputRegressor wrapper

xgb_trained_linex = MultiOutputRegressor(model_linex).fit(xgb_training_data_x, xgb_training_data_y)

xgb_prediction_linex = xgb_trained_linex.predict(xgb_test_data_x)

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.