MLBazaar / MLBazaar/MLBlocks

Enabling passing of primitives/pipelines to hyperparameters

Open
#126 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
124
Forks
33
PR merge metrics
No merged PRs in 30d

Description

Description

I was trying to construct a primitive for sklearn.model_selection.RandomizedSearchCV when I found that the hyperparameter for estimator is itself can be a primitive.

What I Did

To go around the current implementation, I tried to create a pipeline for the estimator (using LogisticRegression) and passed that as the value for the hyperparameter estimator i input_params as follows:
init_params = {
"sklearn.model_selection.RandomizedSearchCV": {
'estimator': logistic_regression_pipeline,
'scoring': "accuracy",
'n_iter': 5
}
}

In python <3.7 it fails in deepcopy of hyperparameters (fix suggested here: https://stackoverflow.com/questions/6279305/typeerror-cannot-deepcopy-this-pattern-object)

In python 3.7+ it fails where sklearn throws the exception that the estimator object needs to be an object of type sklearn estimator and not MLPipeline

There needs to be a way to pass such primitives as input params

Note It works if I pass the logisticRegression object directly to the init_params as:
'estimator': LogisticRegression(random_state=0)

but looses the capability of:

  1. saving the pipeline to disk
  2. constructing the complete pipeline using only MLBlocks

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the RandomizedSearchCV case using init_params with a LogisticRegression pipeline as the estimator, checking the deepcopy failure on Python before 3.7 and the sklearn estimator exception on Python 3.7+. Done should allow primitive or pipeline values as hyperparameters while preserving pipeline-to-disk saving and complete construction using only MLBlocks.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, scikit-learn
Domain
machine-learning
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.