Comments (1)
Yes, you can! But keep in mind most optimization problems in ML models are defined to be solved efficiently (and are in fact single objective). However, you can of course treat them as a black-box problem as well. The example below illustrates this for Ridge Regression.
import numpy as np
from sklearn import linear_model
from pymoo.algorithms.soo.nonconvex.de import DE
from pymoo.core.problem import ElementwiseProblem
from pymoo.operators.sampling.lhs import LHS
from pymoo.optimize import minimize
A = np.array([[0, 0], [0, 0], [1, 1]])
b = np.array([0, .1, 1])
alpha = 0.5
reg = linear_model.Ridge(alpha=alpha)
reg.fit(A, b)
print(reg.intercept_, reg.coef_)
class RidgeRegression(ElementwiseProblem):
def __init__(self):
super().__init__(n_var=3, n_obj=1, xl=-10, xu=+10)
def _evaluate(self, x, out, *args, **kwargs):
coef_ = x[:2]
intercept_ = x[2]
y_hat = A @ coef_ + intercept_
out['coef'] = coef_
out['intercept'] = intercept_
out['F'] = ((b - y_hat) ** 2).sum() + alpha * (coef_ ** 2).sum()
problem = RidgeRegression()
algorithm = DE(
pop_size=100,
sampling=LHS(),
variant="DE/rand/1/bin",
CR=0.3,
dither="vector",
jitter=False
)
res = minimize(problem,
algorithm,
seed=1,
verbose=False)
sol = res.opt[0]
print(sol.get('intercept'), sol.get('coef'))
A whole other topic is to optimize the hyperparameters of ML models. Please search for hyper parameter optimization to get more information about this.
PS: Please open a discussion and not an issue as this is nothing that needs to be added as a feature or fixed.
from pymoo.
Related Issues (20)
- Hello, can hyperparameter optimization be done for multi-objective problems? HOT 1
- 超参数优化HyperparameterProblem HOT 1
- Optimisation parameters for integer types HOT 1
- Restarting from Checkpoint, multiple runs, always reverts back to first checkpoint.
- The repair is not passed to the mating argument of the MixedVariableGA class HOT 5
- ValueError: negative dimensions are not allowed HOT 1
- Conda package HOT 4
- Concurrency safety parallelisation HOT 2
- Concerns Regarding Initialization of Binary Variables and Support for Custom Initial Population in PyMoo's NSGA2 HOT 1
- using Pymoo for find optimal index of compounds HOT 1
- about MixedVariableProblem,How to generate a matrix of specified shape HOT 1
- Relaunch a simulation if it didn't run HOT 1
- Question: what is the second array returned by pymoo.problems.get_problem('osy') HOT 1
- Invalid progress was set by the TerminationCriterion. HOT 1
- [Feature Request] The proper method for storing optimization result persistently. HOT 6
- How to repair inputs(X) after problem evaluation? HOT 2
- AttributeError: module 'matplotlib.cm' has no attribute 'get_cmap' when using Matplotlib 3.9.0
- Handling crashes in PSO HOT 1
- Parallelization improvement HOT 3
- Bug: Random seed incorrectly set for CMAES optimizer HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pymoo.