Giter Club home page Giter Club logo

Comments (1)

mancellin avatar mancellin commented on June 13, 2024

I tried to strip out most of the abstraction and got the code below.
As long as we have a single optimizer, I'm not it make sense to factor out more in the AbstractOptimizer class.

Will try to include in the code and run the test suite.

from flaml import AutoML
from datetime import datetime
from palma.utils.utils import get_hash
from palma import logger

import logging
from contextlib import contextmanager

@contextmanager
def disable_logging():
    logging.disable()
    yield
    logging.basicConfig(level=logging.DEBUG)


class AbstractOptimizer:
    def __init__(self, **parameters):
        self.date = datetime.now()
        self.run_id = get_hash(date=self.date)
        self.parameters = parameters


class FlamlOptimizer(AbstractOptimizer):
    def __init__(self, **parameters):
        super().__init__(**parameters)
        self.optimizer = AutoML(**parameters)

    def find_best_model(self, project):
        X = project.X.iloc[project.validation_strategy.train_index]
        y = project.y.iloc[project.validation_strategy.train_index]
        splitter = project.validation_strategy
        split_type = None if splitter is None else splitter.splitter
        groups = None if splitter is None else splitter.groups
        groups = groups if groups is None else groups[splitter.train_index]
        with disable_logging():
            self.optimizer.fit(
                    X_train=pd.DataFrame(X.values, index=range(len(X))),
                    y_train=pd.Series(y.values, index=range(len(X))),
                    split_type=split_type, groups=groups,
                    mlflow_logging=False,
                    task=project.problem
                    )
        best_model = self.optimizer.model.model
        logger.logger.log_artifact(best_model, self.run_id)
        return best_model

optim = FlamlOptimizer(time_budget=2)
model = optim.find_best_model(project)

from palma.

Related Issues (9)

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.