Skip to main content

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

Metadata

Release files for kfc-procedure 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kfc-procedure 0.1.1
File Size Uploaded
kfc_procedure-0.1.1.tar.gz 88.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kfc-procedure 0.1.1
File Interpreter ABI Platform
kfc_procedure-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 226.1 kB

Release files / kfc_procedure-0.1.1.tar.gz

Download URL kfc_procedure-0.1.1.tar.gz
Size 88.1 kB
Tags Source
SHA-256 checksum
How to use checksums
6668dc89348ff89644fa2969c9fa689f09c605f34814ba23784efd782c6cfda3
BLAKE2b-256 checksum
How to use checksums
7c881bc1c66eab2d061670077ff1226d0624f6c9aca0a9eaf668f8def61e5fb4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Release files / kfc_procedure-0.1.1-py3-none-any.whl

Download URL kfc_procedure-0.1.1-py3-none-any.whl
Size 137.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cbe90f8769576373150ac14fde97751b6de6b5ca472bd2cc7ba93ed969639e74
BLAKE2b-256 checksum
How to use checksums
7529dffd91c7b5e27f23431131a95e4c8dc558667efd9e151642c4b887db1594
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page