Skip to main content

Clusterwise predictive modeling library

Project description

KFC-Model: A Python Implementation of the KFC Procedure

KFC-Model is a modular Python library for clusterwise predictive modeling using the KFC procedure (K-step, F-step, C-step). It combines multiple clustering divergences, local models, and aggregation strategies for regression and classification tasks.

Features

  • KFC meta-estimator for clusterwise learning
  • Modular KStep, FStep, and CStep components
  • Support for Bregman K-Means divergences
  • Local model factories for regression and classification
  • Aggregation strategies including mean, stacking, and GradientCOBRA
  • Easy extension with custom components

Installation

Requirements:

  • Python 3.11+
  • numpy
  • pandas
  • scikit-learn
  • xgboost
  • matplotlib

Create and activate a virtual environment:

python3 -m venv .venv
source .venv/bin/activate

Install dependencies:

python3 -m pip install -r requirements.txt

Install the package locally:

python3 -m pip install -e .

Quick Start

import numpy as np
from kfc_procedure.kfc import KFCRegressor, KFCClassifier

# Example data
X = np.random.randn(200, 5)
y_reg = X[:, 0] * 2 + np.random.randn(200) * 0.1
y_clf = (y_reg > 0).astype(int)

# Regression example
model = KFCRegressor(
    divergences=["euclidean", "kl"],
    local_model="linear",
    aggregation="mean",
    random_state=42,
)
model.fit(X, y_reg)
y_pred = model.predict(X)

# Classification example
clf = KFCClassifier(
    divergences=["euclidean"],
    local_model="logistic",
    aggregation="majority_vote",
    random_state=42,
)
clf.fit(X, y_clf)
y_pred_clf = clf.predict(X)
proba = clf.predict_proba(X)

Core Components

  • KStep: fits clustering models using one or more Bregman divergences
  • FStep: trains local models for each cluster and divergence
  • CStep: aggregates local predictions into final outputs
  • KFCRegressor / KFCClassifier: full meta-estimators exposing fit, predict, and predict_proba

Configuration

divergences

The divergences parameter accepts:

  • a list of divergence names, e.g. ['euclidean', 'kl']
  • a list of config dictionaries, e.g. [{ 'name': 'euclidean', 'n_clusters': 4 }]

Available divergences: 'euclidean', 'kl', 'gkl', 'is', 'logistic'

local_model

The local_model parameter accepts:

  • a model name string, e.g. 'linear', 'ridge'

Supported regression models include: linear, ridge, lasso, decision_tree, random_forest. Supported classification models include: logistic, decision_tree, random_forest.

aggregation

The aggregation parameter accepts:

  • an aggregation strategy name string, e.g. 'mean', 'stacking'

Supported aggregators:

  • Regression: mean, weighted_mean, stacking
  • Classification: majority_vote, stacking, combine_classifier

Project Structure

  • src/kfc_procedure/: main package code
  • src/kfc_procedure/core/: factories, clustering, ML wrappers, and aggregation strategies
  • src/kfc_procedure/steps/: KFC step implementations
  • src/kfc_procedure/utils/: resolution and validation helpers

Contributing

Contributions, bug reports, and improvements are welcome. Use pytest for testing and follow the existing package layout for new components.

License

MIT License

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

kfc_procedure-0.1.1.tar.gz (88.1 kB view details)

Uploaded Source

Built Distribution

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

kfc_procedure-0.1.1-py3-none-any.whl (137.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: kfc_procedure-0.1.1.tar.gz
  • Upload date:
  • Size: 88.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for kfc_procedure-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6668dc89348ff89644fa2969c9fa689f09c605f34814ba23784efd782c6cfda3
MD5 081266a9b29d41fe0b89995931f1b30e
BLAKE2b-256 7c881bc1c66eab2d061670077ff1226d0624f6c9aca0a9eaf668f8def61e5fb4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kfc_procedure-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 137.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for kfc_procedure-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cbe90f8769576373150ac14fde97751b6de6b5ca472bd2cc7ba93ed969639e74
MD5 bdd56f0665d0fb48ff081b59f5d6198c
BLAKE2b-256 7529dffd91c7b5e27f23431131a95e4c8dc558667efd9e151642c4b887db1594

See more details on using hashes here.

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