Skip to main content

A python package for ensembling machine learning predictions using hill climbing optimization

Project description

Hill Climbing

Hill climbing is a mathematical optimization algorithm that belongs to the family of local search techniques. It is commonly used to iteratively improve a solution based on a cost or objective function. This package provides a simple implementation of the hill climbing algorithm and is useful for efficiently blending predictions from multiple machine learning models. The goal is to achieve an ensemble score that is better than that of any single model in the ensemble.

How it works

Hill climbing starts with an initial solution, which is the predictions of one of the base models. It then iteratively explores neighboring solutions by adjusting the weights used to blend predictions from other models. If a new combination results in an improved value of the objective function, it becomes the current solution. This process repeats until no further improvement is possible, i.e. when a local optimum has been reached.

Installation

pip install hill-climbing

Example usage

from hill_climbing import Climber
from sklearn.metrics import root_mean_squared_error


# Running hill climbing
climber = Climber(
    objective="minimize",
    eval_metric=root_mean_squared_error
)
climber.fit(X, y)

print(f"Best score: {climber.best_score}")
print(f"Best predictions: {climber.best_oof_preds}")

# Predicting on unseen data
test_preds = climber.predict(X_test)

Example usage with cross-validation:

from hill_climbing import ClimberCV
from sklearn.metrics import root_mean_squared_error
from sklearn.model_selection import KFold


# Running hill climbing with CV
climber_cv = ClimberCV(
    objective="minimize",
    eval_metric=root_mean_squared_error,
    cv=KFold(n_splits=5, shuffle=True, random_state=42)
)
climber_cv.fit(X, y)

print(f"Best score: {climber_cv.best_score}")
print(f"Best predictions: {climber_cv.best_oof_preds}")

# Predicting on unseen data
test_preds = climber_cv.predict(X_test)

Parameters

Parameter Type Default Description
objective str - Either "maximize" or "minimize" the evaluation metric
eval_metric callable - The evaluation metric function to optimize
allow_negative_weights bool False Whether to allow negative weights. Note that allowing negative weights increases computation time, and in some cases may lead to overfitting
precision float 0.01 Controls the step size when trying new weights. Lower values will lead to higher computation times
starting_model str "best" Starting model selection strategy ("best", "random", or one of the column names in X)
score_decimal_places int 3 Number of decimal places for score display
random_state int 42 Random seed for reproducibility
verbose bool True Whether to output information during hill climbing
n_jobs int -1 Number of parallel jobs (-1 means use all available cores)
cv BaseCrossValidator - Cross-validation splitter from scikit-learn. This parameter is only available in ClimberCV

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hill_climbing-0.1.1.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hill_climbing-0.1.1-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file hill_climbing-0.1.1.tar.gz.

File metadata

  • Download URL: hill_climbing-0.1.1.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for hill_climbing-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7e7810b047ab9b2a1e28713465d16d04632a8f8d2d5cc0d69c468c9df34baca9
MD5 5369649d458b464c31344b71c03c387c
BLAKE2b-256 d6af51954d8f5351f4be60913e8368c20ff912a3e1984a47b74a26afa7059a20

See more details on using hashes here.

Provenance

The following attestation bundles were made for hill_climbing-0.1.1.tar.gz:

Publisher: publish.yml on ravaghi/hill-climbing

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hill_climbing-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: hill_climbing-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for hill_climbing-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 13546b38ecc1f75722156c5444cc6a6eb1a473b5d2fc41dbb087ca8db550431d
MD5 1f99d3f9f42d02af19b6e114b771cc39
BLAKE2b-256 344edf0aadb129788c9e8c1e506fa3b4ed1ad42a935414994012588b7ace2439

See more details on using hashes here.

Provenance

The following attestation bundles were made for hill_climbing-0.1.1-py3-none-any.whl:

Publisher: publish.yml on ravaghi/hill-climbing

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page