Skip to content

Commit 27c876a

Browse files
Add LLM support, add more examples, update docs, add ensembling
1 parent ac87347 commit 27c876a

File tree

73 files changed

+7752
-82548
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+7752
-82548
lines changed

README.md

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ Here you can see our test coverage in more detail:
4040
* [v3.0 Breaking Changes](#v30-breaking-changes)
4141
* [v2.0 Improvements](#v20-improvements)
4242
* [Convenience features](#convenience-features)
43-
* [Kaggle competition results and example notebooks](#kaggle-competition-results-and-example-notebooks)
43+
* [Example scripts](#example-scripts)
44+
* [Kaggle competition results](#kaggle-competition-results)
4445
* [About the code](#about-the-code)
4546
* [Code quality](#code-quality)
4647
* [Documentation](#documentation)
@@ -73,17 +74,32 @@ uncertainty quantification.
7374
### Basic usage
7475

7576
```sh
76-
from bluecast.blueprints.cast import BlueCast
77-
78-
automl = BlueCast(
79-
class_problem="binary",
80-
)
77+
from bluecast.blueprints.unified import BlueCastAuto
78+
from bluecast.ensemble.ensemble_config import EnsembleConfig
8179

80+
# Binary classification - single model
81+
automl = BlueCastAuto(class_problem="binary")
8282
automl.fit(df_train, target_col="target")
8383
y_probs, y_classes = automl.predict(df_val)
8484

85-
# predict_proba is also available (also for BlueCastCV)
86-
y_probs = automl.predict_proba(df_val)
85+
# Regression with cross-validation and stacking ensemble
86+
automl = BlueCastAuto(
87+
class_problem="regression",
88+
use_cross_validation=True,
89+
ensemble_config=EnsembleConfig(ensemble_strategy="stacking"),
90+
)
91+
automl.fit(df_train, target_col="target")
92+
y_preds = automl.predict(df_val)
93+
```
94+
95+
The original per-class imports still work for users who prefer them:
96+
97+
```sh
98+
from bluecast.blueprints.cast import BlueCast
99+
100+
automl = BlueCast(class_problem="binary")
101+
automl.fit(df_train, target_col="target")
102+
y_probs, y_classes = automl.predict(df_val)
87103
```
88104

89105
### Recent Major Improvements
@@ -164,7 +180,25 @@ y_probs, y_classes = automl.predict(df_val)
164180
It is important to note that df_train contains the target column while
165181
df_eval does not. The target column is passed separately as y_eval.
166182

167-
### Kaggle competition results and example notebooks
183+
### Example scripts
184+
185+
The [examples/](examples/) directory contains self-contained scripts
186+
using synthetic data that demonstrate BlueCast's full feature set:
187+
188+
| Script | Topics |
189+
| ------ | ------ |
190+
| [00_full_showcase.py](examples/00_full_showcase.py) | **End-to-end walkthrough of all features** |
191+
| [01_quick_start.py](examples/01_quick_start.py) | Binary, multiclass, regression, `fit_eval` |
192+
| [02_cross_validation_and_ensembles.py](examples/02_cross_validation_and_ensembles.py) | `BlueCastCV`, mean blending, stacking, hill climbing |
193+
| [03_conformal_prediction.py](examples/03_conformal_prediction.py) | Uncertainty quantification, group-conditional intervals |
194+
| [04_linear_models.py](examples/04_linear_models.py) | Logistic/Ridge/Lasso regression, configurable preprocessing |
195+
| [05_unified_interface.py](examples/05_unified_interface.py) | `BlueCastAuto` single entry point for all problem types |
196+
| [06_advanced_customization.py](examples/06_advanced_customization.py) | Custom preprocessing, XGBoost, drift monitoring, experiment tracking, save/load |
197+
| [07_fairness.py](examples/07_fairness.py) | Fairness auditing, demographic parity, equalized odds, conformal fairness |
198+
| [08_eda.py](examples/08_eda.py) | Univariate/bivariate plots, PCA, t-SNE, correlations, data quality, leakage detection |
199+
| [09_bluecast_ai.py](examples/09_bluecast_ai.py) | Multi-agent LLM-powered AutoML (requires API key) |
200+
201+
### Kaggle competition results
168202

169203
Even though BlueCast has been designed to be a lightweight
170204
automl framework, it still offers the possibilities to
@@ -182,7 +216,7 @@ feature- and performance-wise.
182216
and adding conformal prediction ([notebook](https://www.kaggle.com/code/thomasmeiner/bluecast-has-conformal-prediction))
183217
* 26th place in the Kaggle 24h "AutoMl" GrandPrix July 2024 blitz competition ([notebook](https://www.kaggle.com/code/thomasmeiner/automl-grand-prix-bluecast-26th-place-solution))
184218

185-
Please note that some notebooks ran older versions of BlueCast and
219+
Please note that some Kaggle notebooks ran older versions of BlueCast and
186220
might not be compatible with the most recent version anymore.
187221

188222
## About the code

bluecast/__init__.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""BlueCast - a lightweight AutoML framework."""
2+
3+
from bluecast.blueprints.cast import BlueCast
4+
from bluecast.blueprints.cast_cv import BlueCastCV
5+
from bluecast.blueprints.cast_cv_regression import BlueCastCVRegression
6+
from bluecast.blueprints.cast_regression import BlueCastRegression
7+
from bluecast.blueprints.unified import BlueCastAuto
8+
from bluecast.config.training_config import TrainingConfig
9+
from bluecast.ensemble.ensemble_config import EnsembleConfig
10+
from bluecast.evaluation.fairness import FairnessAuditor
11+
from bluecast.experimentation.tracking import ExperimentTracker
12+
13+
__all__ = [
14+
"BlueCast",
15+
"BlueCastCV",
16+
"BlueCastRegression",
17+
"BlueCastCVRegression",
18+
"BlueCastAuto",
19+
"TrainingConfig",
20+
"EnsembleConfig",
21+
"ExperimentTracker",
22+
"FairnessAuditor",
23+
]

bluecast/ai/__init__.py

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
"""
2+
BlueCastAI: Multi-agent LLM-powered AutoML.
3+
4+
Optional module -- install dependencies with:
5+
pip install bluecast[ai] # all providers
6+
pip install bluecast[ai-gemini] # Google Gemini only
7+
pip install bluecast[ai-openai] # OpenAI only
8+
pip install bluecast[ai-anthropic] # Anthropic Claude only
9+
10+
Usage::
11+
12+
from bluecast.ai import BlueCastAI
13+
14+
ai = BlueCastAI(api_key="...", provider="gemini")
15+
result = ai.run(df_train, target_col="target",
16+
prompt="Build a precise binary classifier")
17+
result.predict(df_test)
18+
result.save_code("pipeline.py")
19+
"""
20+
21+
import logging
22+
from typing import List, Literal, Optional
23+
24+
import pandas as pd
25+
26+
from bluecast.ai.config import AIConfig
27+
from bluecast.ai.result import BlueCastAIResult
28+
29+
logger = logging.getLogger(__name__)
30+
31+
32+
def _create_provider(config: AIConfig):
33+
"""Factory to create the right LLM provider based on config."""
34+
model = config.get_model_name()
35+
36+
if config.provider == "gemini":
37+
from bluecast.ai.providers.gemini import GeminiProvider
38+
return GeminiProvider(api_key=config.api_key, model=model, temperature=config.temperature)
39+
elif config.provider == "openai":
40+
from bluecast.ai.providers.openai_provider import OpenAIProvider
41+
return OpenAIProvider(api_key=config.api_key, model=model, temperature=config.temperature)
42+
elif config.provider == "anthropic":
43+
from bluecast.ai.providers.anthropic_provider import AnthropicProvider
44+
return AnthropicProvider(api_key=config.api_key, model=model, temperature=config.temperature)
45+
else:
46+
raise ValueError(f"Unknown provider: {config.provider}. Use 'gemini', 'openai', or 'anthropic'.")
47+
48+
49+
class BlueCastAI:
50+
"""Multi-agent LLM-powered AutoML for BlueCast.
51+
52+
Provide an API key, a dataset, and a natural language prompt.
53+
BlueCastAI will analyze the data, engineer features, build a pipeline,
54+
evaluate it, and iteratively improve it -- all guided by LLM agents.
55+
56+
:param api_key: API key for the LLM provider.
57+
:param provider: LLM provider: 'gemini', 'openai', or 'anthropic'.
58+
:param model: Provider-specific model name (e.g. 'gpt-4o', 'claude-sonnet-4-20250514').
59+
Uses a sensible default per provider if not specified.
60+
:param enable_web_search: Whether agents can search the web for techniques.
61+
:param verbose: Whether to print progress to stdout.
62+
:param temperature: LLM temperature (0.0 = deterministic, 1.0 = creative).
63+
:param checkpoint_dir: Directory for saving checkpoints. If a run crashes,
64+
the next call to .run() with the same checkpoint_dir resumes from where
65+
it left off. Set to None to disable checkpointing.
66+
67+
Usage::
68+
69+
from bluecast.ai import BlueCastAI
70+
71+
ai = BlueCastAI(api_key="your-key", provider="gemini")
72+
result = ai.run(
73+
df_train,
74+
target_col="target",
75+
prompt="Build a high-precision binary classifier with hill climbing ensemble",
76+
mode="precise",
77+
)
78+
79+
# Use the trained pipeline
80+
predictions = result.predict(df_test)
81+
82+
# Export reproducible code
83+
result.save_code("my_pipeline.py")
84+
85+
# View what happened
86+
result.show_report()
87+
"""
88+
89+
def __init__(
90+
self,
91+
api_key: str,
92+
provider: Literal["gemini", "openai", "anthropic"] = "gemini",
93+
model: Optional[str] = None,
94+
enable_web_search: bool = False,
95+
verbose: bool = True,
96+
temperature: float = 0.2,
97+
checkpoint_dir: Optional[str] = None,
98+
):
99+
self.config = AIConfig(
100+
api_key=api_key,
101+
provider=provider,
102+
model=model,
103+
enable_web_search=enable_web_search,
104+
verbose=verbose,
105+
temperature=temperature,
106+
checkpoint_dir=checkpoint_dir,
107+
)
108+
self._llm = _create_provider(self.config)
109+
110+
def run(
111+
self,
112+
df: pd.DataFrame,
113+
target_col: str,
114+
prompt: str = "Build a good model",
115+
context_files: Optional[List[str]] = None,
116+
mode: Literal["fast", "balanced", "precise"] = "balanced",
117+
max_iterations: int = 0,
118+
) -> BlueCastAIResult:
119+
"""Run the multi-agent pipeline on the dataset.
120+
121+
:param df: Training DataFrame including the target column.
122+
:param target_col: Name of the target column.
123+
:param prompt: Natural language instructions for what to build.
124+
Examples:
125+
- "Build a fast baseline model"
126+
- "Build a precise binary classifier with stacking ensemble"
127+
- "Maximize ROC AUC using hill climbing and feature engineering"
128+
:param context_files: Optional list of file paths containing domain knowledge.
129+
:param mode: Speed vs thoroughness trade-off:
130+
'fast' = skip FE, 1 iteration (~2 min),
131+
'balanced' = targeted FE, 3 iterations (~10 min),
132+
'precise' = full FE, ensemble, 5+ iterations (~30 min).
133+
:param max_iterations: Override the number of build-evaluate-improve cycles.
134+
If 0, uses the mode default.
135+
:returns: BlueCastAIResult with trained pipeline, code, metrics, and logs.
136+
"""
137+
self.config.mode = mode
138+
self.config.context_files = context_files or []
139+
if max_iterations > 0:
140+
self.config.max_iterations = max_iterations
141+
142+
from bluecast.ai.orchestrator import Orchestrator
143+
144+
orchestrator = Orchestrator(
145+
llm=self._llm,
146+
config=self.config,
147+
df=df,
148+
target_col=target_col,
149+
prompt=prompt,
150+
)
151+
return orchestrator.run()

bluecast/ai/agents/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""BlueCastAI agent implementations."""

0 commit comments

Comments
 (0)