gugarosa / opytimizer

🐦 Opytimizer is a Python library consisting of meta-heuristic optimization algorithms.
https://opytimizer.readthedocs.io
Apache License 2.0
604 stars 41 forks source link

[NEW] Define objective function for regression problem #27

Closed hanamthang closed 2 years ago

hanamthang commented 2 years ago

Hi there,

I attempted to define an objective function (using CatBoost model for data) to solve a minimum problem in a regression task, however failed to create new objective function. So, do your package offer the solution for regression and can we define such an objective function in this case?

My desired objective function something like this to minimize the MSE:

from catboost import CatBoostRegressor as cbr
cbr_model = cbr()

def objective_function(cbr_model,X_train3, y_train3, X_test3, y_test3):      
    cbr_model.fit(X_train3,y_train3)  
    mse=mean_squared_error(y_test3,cbr_model.predict(X_test3))
    return mse

Many thanks, Thang

gugarosa commented 2 years ago

Hello Thang! I hope everything is going well with you.

You can take a look at the following integrations to have a glimpse on how to define your objective function: https://github.com/gugarosa/opytimizer/tree/master/examples/integrations

Roughly speaking, the objective function only takes into one argument (let's say x), which is the numpy array holding the decision variables that are being optimized. Everything else needs to be inside the objective function or be declared as a wrapper, such as the following: https://github.com/gugarosa/dbn_tuning/blob/main/utils/target.py

Best regards, Gustavo.

hanamthang commented 2 years ago

I got it. Many thanks, Thang