churnkit 0.75.0a1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- churnkit-0.75.0a1.data/data/share/churnkit/exploration_notebooks/00_start_here.ipynb +647 -0
- churnkit-0.75.0a1.data/data/share/churnkit/exploration_notebooks/01_data_discovery.ipynb +1165 -0
- churnkit-0.75.0a1.data/data/share/churnkit/exploration_notebooks/01a_a_temporal_text_deep_dive.ipynb +961 -0
- churnkit-0.75.0a1.data/data/share/churnkit/exploration_notebooks/01a_temporal_deep_dive.ipynb +1690 -0
- churnkit-0.75.0a1.data/data/share/churnkit/exploration_notebooks/01b_temporal_quality.ipynb +679 -0
- churnkit-0.75.0a1.data/data/share/churnkit/exploration_notebooks/01c_temporal_patterns.ipynb +3305 -0
- churnkit-0.75.0a1.data/data/share/churnkit/exploration_notebooks/01d_event_aggregation.ipynb +1463 -0
- churnkit-0.75.0a1.data/data/share/churnkit/exploration_notebooks/02_column_deep_dive.ipynb +1430 -0
- churnkit-0.75.0a1.data/data/share/churnkit/exploration_notebooks/02a_text_columns_deep_dive.ipynb +854 -0
- churnkit-0.75.0a1.data/data/share/churnkit/exploration_notebooks/03_quality_assessment.ipynb +1639 -0
- churnkit-0.75.0a1.data/data/share/churnkit/exploration_notebooks/04_relationship_analysis.ipynb +1890 -0
- churnkit-0.75.0a1.data/data/share/churnkit/exploration_notebooks/05_multi_dataset.ipynb +1457 -0
- churnkit-0.75.0a1.data/data/share/churnkit/exploration_notebooks/06_feature_opportunities.ipynb +1624 -0
- churnkit-0.75.0a1.data/data/share/churnkit/exploration_notebooks/07_modeling_readiness.ipynb +780 -0
- churnkit-0.75.0a1.data/data/share/churnkit/exploration_notebooks/08_baseline_experiments.ipynb +979 -0
- churnkit-0.75.0a1.data/data/share/churnkit/exploration_notebooks/09_business_alignment.ipynb +572 -0
- churnkit-0.75.0a1.data/data/share/churnkit/exploration_notebooks/10_spec_generation.ipynb +1179 -0
- churnkit-0.75.0a1.data/data/share/churnkit/exploration_notebooks/11_scoring_validation.ipynb +1418 -0
- churnkit-0.75.0a1.data/data/share/churnkit/exploration_notebooks/12_view_documentation.ipynb +151 -0
- churnkit-0.75.0a1.dist-info/METADATA +229 -0
- churnkit-0.75.0a1.dist-info/RECORD +302 -0
- churnkit-0.75.0a1.dist-info/WHEEL +4 -0
- churnkit-0.75.0a1.dist-info/entry_points.txt +2 -0
- churnkit-0.75.0a1.dist-info/licenses/LICENSE +202 -0
- customer_retention/__init__.py +37 -0
- customer_retention/analysis/__init__.py +0 -0
- customer_retention/analysis/auto_explorer/__init__.py +62 -0
- customer_retention/analysis/auto_explorer/exploration_manager.py +470 -0
- customer_retention/analysis/auto_explorer/explorer.py +258 -0
- customer_retention/analysis/auto_explorer/findings.py +291 -0
- customer_retention/analysis/auto_explorer/layered_recommendations.py +485 -0
- customer_retention/analysis/auto_explorer/recommendation_builder.py +148 -0
- customer_retention/analysis/auto_explorer/recommendations.py +418 -0
- customer_retention/analysis/business/__init__.py +26 -0
- customer_retention/analysis/business/ab_test_designer.py +144 -0
- customer_retention/analysis/business/fairness_analyzer.py +166 -0
- customer_retention/analysis/business/intervention_matcher.py +121 -0
- customer_retention/analysis/business/report_generator.py +222 -0
- customer_retention/analysis/business/risk_profile.py +199 -0
- customer_retention/analysis/business/roi_analyzer.py +139 -0
- customer_retention/analysis/diagnostics/__init__.py +20 -0
- customer_retention/analysis/diagnostics/calibration_analyzer.py +133 -0
- customer_retention/analysis/diagnostics/cv_analyzer.py +144 -0
- customer_retention/analysis/diagnostics/error_analyzer.py +107 -0
- customer_retention/analysis/diagnostics/leakage_detector.py +394 -0
- customer_retention/analysis/diagnostics/noise_tester.py +140 -0
- customer_retention/analysis/diagnostics/overfitting_analyzer.py +190 -0
- customer_retention/analysis/diagnostics/segment_analyzer.py +122 -0
- customer_retention/analysis/discovery/__init__.py +8 -0
- customer_retention/analysis/discovery/config_generator.py +49 -0
- customer_retention/analysis/discovery/discovery_flow.py +19 -0
- customer_retention/analysis/discovery/type_inferencer.py +147 -0
- customer_retention/analysis/interpretability/__init__.py +13 -0
- customer_retention/analysis/interpretability/cohort_analyzer.py +185 -0
- customer_retention/analysis/interpretability/counterfactual.py +175 -0
- customer_retention/analysis/interpretability/individual_explainer.py +141 -0
- customer_retention/analysis/interpretability/pdp_generator.py +103 -0
- customer_retention/analysis/interpretability/shap_explainer.py +106 -0
- customer_retention/analysis/jupyter_save_hook.py +28 -0
- customer_retention/analysis/notebook_html_exporter.py +136 -0
- customer_retention/analysis/notebook_progress.py +60 -0
- customer_retention/analysis/plotly_preprocessor.py +154 -0
- customer_retention/analysis/recommendations/__init__.py +54 -0
- customer_retention/analysis/recommendations/base.py +158 -0
- customer_retention/analysis/recommendations/cleaning/__init__.py +11 -0
- customer_retention/analysis/recommendations/cleaning/consistency.py +107 -0
- customer_retention/analysis/recommendations/cleaning/deduplicate.py +94 -0
- customer_retention/analysis/recommendations/cleaning/impute.py +67 -0
- customer_retention/analysis/recommendations/cleaning/outlier.py +71 -0
- customer_retention/analysis/recommendations/datetime/__init__.py +3 -0
- customer_retention/analysis/recommendations/datetime/extract.py +149 -0
- customer_retention/analysis/recommendations/encoding/__init__.py +3 -0
- customer_retention/analysis/recommendations/encoding/categorical.py +114 -0
- customer_retention/analysis/recommendations/pipeline.py +74 -0
- customer_retention/analysis/recommendations/registry.py +76 -0
- customer_retention/analysis/recommendations/selection/__init__.py +3 -0
- customer_retention/analysis/recommendations/selection/drop_column.py +56 -0
- customer_retention/analysis/recommendations/transform/__init__.py +4 -0
- customer_retention/analysis/recommendations/transform/power.py +94 -0
- customer_retention/analysis/recommendations/transform/scale.py +112 -0
- customer_retention/analysis/visualization/__init__.py +15 -0
- customer_retention/analysis/visualization/chart_builder.py +2619 -0
- customer_retention/analysis/visualization/console.py +122 -0
- customer_retention/analysis/visualization/display.py +171 -0
- customer_retention/analysis/visualization/number_formatter.py +36 -0
- customer_retention/artifacts/__init__.py +3 -0
- customer_retention/artifacts/fit_artifact_registry.py +146 -0
- customer_retention/cli.py +93 -0
- customer_retention/core/__init__.py +0 -0
- customer_retention/core/compat/__init__.py +193 -0
- customer_retention/core/compat/detection.py +99 -0
- customer_retention/core/compat/ops.py +48 -0
- customer_retention/core/compat/pandas_backend.py +57 -0
- customer_retention/core/compat/spark_backend.py +75 -0
- customer_retention/core/components/__init__.py +11 -0
- customer_retention/core/components/base.py +79 -0
- customer_retention/core/components/components/__init__.py +13 -0
- customer_retention/core/components/components/deployer.py +26 -0
- customer_retention/core/components/components/explainer.py +26 -0
- customer_retention/core/components/components/feature_eng.py +33 -0
- customer_retention/core/components/components/ingester.py +34 -0
- customer_retention/core/components/components/profiler.py +34 -0
- customer_retention/core/components/components/trainer.py +38 -0
- customer_retention/core/components/components/transformer.py +36 -0
- customer_retention/core/components/components/validator.py +37 -0
- customer_retention/core/components/enums.py +33 -0
- customer_retention/core/components/orchestrator.py +94 -0
- customer_retention/core/components/registry.py +59 -0
- customer_retention/core/config/__init__.py +39 -0
- customer_retention/core/config/column_config.py +95 -0
- customer_retention/core/config/experiments.py +71 -0
- customer_retention/core/config/pipeline_config.py +117 -0
- customer_retention/core/config/source_config.py +83 -0
- customer_retention/core/utils/__init__.py +28 -0
- customer_retention/core/utils/leakage.py +85 -0
- customer_retention/core/utils/severity.py +53 -0
- customer_retention/core/utils/statistics.py +90 -0
- customer_retention/generators/__init__.py +0 -0
- customer_retention/generators/notebook_generator/__init__.py +167 -0
- customer_retention/generators/notebook_generator/base.py +55 -0
- customer_retention/generators/notebook_generator/cell_builder.py +49 -0
- customer_retention/generators/notebook_generator/config.py +47 -0
- customer_retention/generators/notebook_generator/databricks_generator.py +48 -0
- customer_retention/generators/notebook_generator/local_generator.py +48 -0
- customer_retention/generators/notebook_generator/project_init.py +174 -0
- customer_retention/generators/notebook_generator/runner.py +150 -0
- customer_retention/generators/notebook_generator/script_generator.py +110 -0
- customer_retention/generators/notebook_generator/stages/__init__.py +19 -0
- customer_retention/generators/notebook_generator/stages/base_stage.py +86 -0
- customer_retention/generators/notebook_generator/stages/s01_ingestion.py +100 -0
- customer_retention/generators/notebook_generator/stages/s02_profiling.py +95 -0
- customer_retention/generators/notebook_generator/stages/s03_cleaning.py +180 -0
- customer_retention/generators/notebook_generator/stages/s04_transformation.py +165 -0
- customer_retention/generators/notebook_generator/stages/s05_feature_engineering.py +115 -0
- customer_retention/generators/notebook_generator/stages/s06_feature_selection.py +97 -0
- customer_retention/generators/notebook_generator/stages/s07_model_training.py +176 -0
- customer_retention/generators/notebook_generator/stages/s08_deployment.py +81 -0
- customer_retention/generators/notebook_generator/stages/s09_monitoring.py +112 -0
- customer_retention/generators/notebook_generator/stages/s10_batch_inference.py +642 -0
- customer_retention/generators/notebook_generator/stages/s11_feature_store.py +348 -0
- customer_retention/generators/orchestration/__init__.py +23 -0
- customer_retention/generators/orchestration/code_generator.py +196 -0
- customer_retention/generators/orchestration/context.py +147 -0
- customer_retention/generators/orchestration/data_materializer.py +188 -0
- customer_retention/generators/orchestration/databricks_exporter.py +411 -0
- customer_retention/generators/orchestration/doc_generator.py +311 -0
- customer_retention/generators/pipeline_generator/__init__.py +26 -0
- customer_retention/generators/pipeline_generator/findings_parser.py +727 -0
- customer_retention/generators/pipeline_generator/generator.py +142 -0
- customer_retention/generators/pipeline_generator/models.py +166 -0
- customer_retention/generators/pipeline_generator/renderer.py +2125 -0
- customer_retention/generators/spec_generator/__init__.py +37 -0
- customer_retention/generators/spec_generator/databricks_generator.py +433 -0
- customer_retention/generators/spec_generator/generic_generator.py +373 -0
- customer_retention/generators/spec_generator/mlflow_pipeline_generator.py +685 -0
- customer_retention/generators/spec_generator/pipeline_spec.py +298 -0
- customer_retention/integrations/__init__.py +0 -0
- customer_retention/integrations/adapters/__init__.py +13 -0
- customer_retention/integrations/adapters/base.py +10 -0
- customer_retention/integrations/adapters/factory.py +25 -0
- customer_retention/integrations/adapters/feature_store/__init__.py +6 -0
- customer_retention/integrations/adapters/feature_store/base.py +57 -0
- customer_retention/integrations/adapters/feature_store/databricks.py +94 -0
- customer_retention/integrations/adapters/feature_store/feast_adapter.py +97 -0
- customer_retention/integrations/adapters/feature_store/local.py +75 -0
- customer_retention/integrations/adapters/mlflow/__init__.py +6 -0
- customer_retention/integrations/adapters/mlflow/base.py +32 -0
- customer_retention/integrations/adapters/mlflow/databricks.py +54 -0
- customer_retention/integrations/adapters/mlflow/experiment_tracker.py +161 -0
- customer_retention/integrations/adapters/mlflow/local.py +50 -0
- customer_retention/integrations/adapters/storage/__init__.py +5 -0
- customer_retention/integrations/adapters/storage/base.py +33 -0
- customer_retention/integrations/adapters/storage/databricks.py +76 -0
- customer_retention/integrations/adapters/storage/local.py +59 -0
- customer_retention/integrations/feature_store/__init__.py +47 -0
- customer_retention/integrations/feature_store/definitions.py +215 -0
- customer_retention/integrations/feature_store/manager.py +744 -0
- customer_retention/integrations/feature_store/registry.py +412 -0
- customer_retention/integrations/iteration/__init__.py +28 -0
- customer_retention/integrations/iteration/context.py +212 -0
- customer_retention/integrations/iteration/feedback_collector.py +184 -0
- customer_retention/integrations/iteration/orchestrator.py +168 -0
- customer_retention/integrations/iteration/recommendation_tracker.py +341 -0
- customer_retention/integrations/iteration/signals.py +212 -0
- customer_retention/integrations/llm_context/__init__.py +4 -0
- customer_retention/integrations/llm_context/context_builder.py +201 -0
- customer_retention/integrations/llm_context/prompts.py +100 -0
- customer_retention/integrations/streaming/__init__.py +103 -0
- customer_retention/integrations/streaming/batch_integration.py +149 -0
- customer_retention/integrations/streaming/early_warning_model.py +227 -0
- customer_retention/integrations/streaming/event_schema.py +214 -0
- customer_retention/integrations/streaming/online_store_writer.py +249 -0
- customer_retention/integrations/streaming/realtime_scorer.py +261 -0
- customer_retention/integrations/streaming/trigger_engine.py +293 -0
- customer_retention/integrations/streaming/window_aggregator.py +393 -0
- customer_retention/stages/__init__.py +0 -0
- customer_retention/stages/cleaning/__init__.py +9 -0
- customer_retention/stages/cleaning/base.py +28 -0
- customer_retention/stages/cleaning/missing_handler.py +160 -0
- customer_retention/stages/cleaning/outlier_handler.py +204 -0
- customer_retention/stages/deployment/__init__.py +28 -0
- customer_retention/stages/deployment/batch_scorer.py +106 -0
- customer_retention/stages/deployment/champion_challenger.py +299 -0
- customer_retention/stages/deployment/model_registry.py +182 -0
- customer_retention/stages/deployment/retraining_trigger.py +245 -0
- customer_retention/stages/features/__init__.py +73 -0
- customer_retention/stages/features/behavioral_features.py +266 -0
- customer_retention/stages/features/customer_segmentation.py +505 -0
- customer_retention/stages/features/feature_definitions.py +265 -0
- customer_retention/stages/features/feature_engineer.py +551 -0
- customer_retention/stages/features/feature_manifest.py +340 -0
- customer_retention/stages/features/feature_selector.py +239 -0
- customer_retention/stages/features/interaction_features.py +160 -0
- customer_retention/stages/features/temporal_features.py +243 -0
- customer_retention/stages/ingestion/__init__.py +9 -0
- customer_retention/stages/ingestion/load_result.py +32 -0
- customer_retention/stages/ingestion/loaders.py +195 -0
- customer_retention/stages/ingestion/source_registry.py +130 -0
- customer_retention/stages/modeling/__init__.py +31 -0
- customer_retention/stages/modeling/baseline_trainer.py +139 -0
- customer_retention/stages/modeling/cross_validator.py +125 -0
- customer_retention/stages/modeling/data_splitter.py +205 -0
- customer_retention/stages/modeling/feature_scaler.py +99 -0
- customer_retention/stages/modeling/hyperparameter_tuner.py +107 -0
- customer_retention/stages/modeling/imbalance_handler.py +282 -0
- customer_retention/stages/modeling/mlflow_logger.py +95 -0
- customer_retention/stages/modeling/model_comparator.py +149 -0
- customer_retention/stages/modeling/model_evaluator.py +138 -0
- customer_retention/stages/modeling/threshold_optimizer.py +131 -0
- customer_retention/stages/monitoring/__init__.py +37 -0
- customer_retention/stages/monitoring/alert_manager.py +328 -0
- customer_retention/stages/monitoring/drift_detector.py +201 -0
- customer_retention/stages/monitoring/performance_monitor.py +242 -0
- customer_retention/stages/preprocessing/__init__.py +5 -0
- customer_retention/stages/preprocessing/transformer_manager.py +284 -0
- customer_retention/stages/profiling/__init__.py +256 -0
- customer_retention/stages/profiling/categorical_distribution.py +269 -0
- customer_retention/stages/profiling/categorical_target_analyzer.py +274 -0
- customer_retention/stages/profiling/column_profiler.py +527 -0
- customer_retention/stages/profiling/distribution_analysis.py +483 -0
- customer_retention/stages/profiling/drift_detector.py +310 -0
- customer_retention/stages/profiling/feature_capacity.py +507 -0
- customer_retention/stages/profiling/pattern_analysis_config.py +513 -0
- customer_retention/stages/profiling/profile_result.py +212 -0
- customer_retention/stages/profiling/quality_checks.py +1632 -0
- customer_retention/stages/profiling/relationship_detector.py +256 -0
- customer_retention/stages/profiling/relationship_recommender.py +454 -0
- customer_retention/stages/profiling/report_generator.py +520 -0
- customer_retention/stages/profiling/scd_analyzer.py +151 -0
- customer_retention/stages/profiling/segment_analyzer.py +632 -0
- customer_retention/stages/profiling/segment_aware_outlier.py +265 -0
- customer_retention/stages/profiling/target_level_analyzer.py +217 -0
- customer_retention/stages/profiling/temporal_analyzer.py +388 -0
- customer_retention/stages/profiling/temporal_coverage.py +488 -0
- customer_retention/stages/profiling/temporal_feature_analyzer.py +692 -0
- customer_retention/stages/profiling/temporal_feature_engineer.py +703 -0
- customer_retention/stages/profiling/temporal_pattern_analyzer.py +636 -0
- customer_retention/stages/profiling/temporal_quality_checks.py +278 -0
- customer_retention/stages/profiling/temporal_target_analyzer.py +241 -0
- customer_retention/stages/profiling/text_embedder.py +87 -0
- customer_retention/stages/profiling/text_processor.py +115 -0
- customer_retention/stages/profiling/text_reducer.py +60 -0
- customer_retention/stages/profiling/time_series_profiler.py +303 -0
- customer_retention/stages/profiling/time_window_aggregator.py +376 -0
- customer_retention/stages/profiling/type_detector.py +382 -0
- customer_retention/stages/profiling/window_recommendation.py +288 -0
- customer_retention/stages/temporal/__init__.py +166 -0
- customer_retention/stages/temporal/access_guard.py +180 -0
- customer_retention/stages/temporal/cutoff_analyzer.py +235 -0
- customer_retention/stages/temporal/data_preparer.py +178 -0
- customer_retention/stages/temporal/point_in_time_join.py +134 -0
- customer_retention/stages/temporal/point_in_time_registry.py +148 -0
- customer_retention/stages/temporal/scenario_detector.py +163 -0
- customer_retention/stages/temporal/snapshot_manager.py +259 -0
- customer_retention/stages/temporal/synthetic_coordinator.py +66 -0
- customer_retention/stages/temporal/timestamp_discovery.py +531 -0
- customer_retention/stages/temporal/timestamp_manager.py +255 -0
- customer_retention/stages/transformation/__init__.py +13 -0
- customer_retention/stages/transformation/binary_handler.py +85 -0
- customer_retention/stages/transformation/categorical_encoder.py +245 -0
- customer_retention/stages/transformation/datetime_transformer.py +97 -0
- customer_retention/stages/transformation/numeric_transformer.py +181 -0
- customer_retention/stages/transformation/pipeline.py +257 -0
- customer_retention/stages/validation/__init__.py +60 -0
- customer_retention/stages/validation/adversarial_scoring_validator.py +205 -0
- customer_retention/stages/validation/business_sense_gate.py +173 -0
- customer_retention/stages/validation/data_quality_gate.py +235 -0
- customer_retention/stages/validation/data_validators.py +511 -0
- customer_retention/stages/validation/feature_quality_gate.py +183 -0
- customer_retention/stages/validation/gates.py +117 -0
- customer_retention/stages/validation/leakage_gate.py +352 -0
- customer_retention/stages/validation/model_validity_gate.py +213 -0
- customer_retention/stages/validation/pipeline_validation_runner.py +264 -0
- customer_retention/stages/validation/quality_scorer.py +544 -0
- customer_retention/stages/validation/rule_generator.py +57 -0
- customer_retention/stages/validation/scoring_pipeline_validator.py +446 -0
- customer_retention/stages/validation/timeseries_detector.py +769 -0
- customer_retention/transforms/__init__.py +47 -0
- customer_retention/transforms/artifact_store.py +50 -0
- customer_retention/transforms/executor.py +157 -0
- customer_retention/transforms/fitted.py +92 -0
- customer_retention/transforms/ops.py +148 -0
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
from typing import TYPE_CHECKING, List, Optional
|
|
2
|
+
|
|
3
|
+
from customer_retention.analysis.auto_explorer.layered_recommendations import (
|
|
4
|
+
LayeredRecommendation,
|
|
5
|
+
RecommendationRegistry,
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
if TYPE_CHECKING:
|
|
9
|
+
from customer_retention.analysis.auto_explorer.findings import ExplorationFindings
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class PipelineDocGenerator:
|
|
13
|
+
def __init__(self, registry: RecommendationRegistry, findings: Optional["ExplorationFindings"] = None):
|
|
14
|
+
self.registry = registry
|
|
15
|
+
self.findings = findings
|
|
16
|
+
|
|
17
|
+
def generate(self) -> str:
|
|
18
|
+
sections = [
|
|
19
|
+
self._generate_header(),
|
|
20
|
+
self._generate_assistant_prompt(),
|
|
21
|
+
self._generate_data_overview(),
|
|
22
|
+
self._generate_column_schema(),
|
|
23
|
+
self._generate_sources_spec(),
|
|
24
|
+
self._generate_bronze_spec(),
|
|
25
|
+
self._generate_silver_spec(),
|
|
26
|
+
self._generate_gold_spec(),
|
|
27
|
+
self._generate_notebook_structure(),
|
|
28
|
+
self._generate_delta_structure(),
|
|
29
|
+
]
|
|
30
|
+
return "\n\n".join(s for s in sections if s)
|
|
31
|
+
|
|
32
|
+
def _generate_header(self) -> str:
|
|
33
|
+
return "# Pipeline Specification\n\nGenerated pipeline specification for LLM context."
|
|
34
|
+
|
|
35
|
+
def _generate_assistant_prompt(self) -> str:
|
|
36
|
+
lines = [
|
|
37
|
+
"## Assistant Instructions",
|
|
38
|
+
"",
|
|
39
|
+
"Generate a standalone PySpark data pipeline following the medallion architecture.",
|
|
40
|
+
"The code should:",
|
|
41
|
+
"- Use native PySpark DataFrame operations (no external framework dependencies)",
|
|
42
|
+
"- Read from landing zone and write to Delta tables",
|
|
43
|
+
"- Implement Bronze (cleaning), Silver (aggregations), and Gold (feature engineering) layers",
|
|
44
|
+
"- Use `pyspark.sql.functions` for transformations",
|
|
45
|
+
"- Use `pyspark.ml.feature` for encoding and scaling",
|
|
46
|
+
]
|
|
47
|
+
return "\n".join(lines)
|
|
48
|
+
|
|
49
|
+
def _generate_data_overview(self) -> str:
|
|
50
|
+
lines = ["## Data Overview", ""]
|
|
51
|
+
if self.findings:
|
|
52
|
+
lines.append(f"- **Source**: {self.findings.source_path}")
|
|
53
|
+
lines.append(f"- **Format**: {self.findings.source_format}")
|
|
54
|
+
lines.append(f"- **Rows**: {self.findings.row_count:,}")
|
|
55
|
+
lines.append(f"- **Columns**: {self.findings.column_count}")
|
|
56
|
+
if self.findings.target_column:
|
|
57
|
+
lines.append(f"- **Target**: `{self.findings.target_column}` (variable to predict)")
|
|
58
|
+
if self.findings.identifier_columns:
|
|
59
|
+
lines.append(f"- **Identifiers**: {', '.join(f'`{c}`' for c in self.findings.identifier_columns)}")
|
|
60
|
+
else:
|
|
61
|
+
lines.append("No data overview available.")
|
|
62
|
+
return "\n".join(lines)
|
|
63
|
+
|
|
64
|
+
def _generate_column_schema(self) -> str:
|
|
65
|
+
lines = ["## Column Schema", ""]
|
|
66
|
+
if not self.findings or not self.findings.columns:
|
|
67
|
+
lines.append("No column schema available.")
|
|
68
|
+
return "\n".join(lines)
|
|
69
|
+
|
|
70
|
+
lines.append("| Column | Type | Null % | Statistics |")
|
|
71
|
+
lines.append("|--------|------|--------|------------|")
|
|
72
|
+
|
|
73
|
+
for name, col in self.findings.columns.items():
|
|
74
|
+
col_type = col.inferred_type.name if col.inferred_type else "UNKNOWN"
|
|
75
|
+
null_pct = col.universal_metrics.get("null_percentage", 0) if col.universal_metrics else 0
|
|
76
|
+
stats = self._format_column_stats(col)
|
|
77
|
+
lines.append(f"| `{name}` | {col_type} | {null_pct:.1f}% | {stats} |")
|
|
78
|
+
|
|
79
|
+
return "\n".join(lines)
|
|
80
|
+
|
|
81
|
+
def _format_column_stats(self, col) -> str:
|
|
82
|
+
parts = []
|
|
83
|
+
if col.universal_metrics:
|
|
84
|
+
if "distinct_count" in col.universal_metrics:
|
|
85
|
+
parts.append(f"distinct={col.universal_metrics['distinct_count']}")
|
|
86
|
+
if "null_count" in col.universal_metrics:
|
|
87
|
+
parts.append(f"nulls={col.universal_metrics['null_count']}")
|
|
88
|
+
if col.type_metrics:
|
|
89
|
+
if "mean" in col.type_metrics:
|
|
90
|
+
parts.append(f"mean={col.type_metrics['mean']}")
|
|
91
|
+
if "std" in col.type_metrics:
|
|
92
|
+
parts.append(f"std={col.type_metrics['std']}")
|
|
93
|
+
if "skewness" in col.type_metrics:
|
|
94
|
+
parts.append(f"skew={col.type_metrics['skewness']}")
|
|
95
|
+
return ", ".join(parts) if parts else "-"
|
|
96
|
+
|
|
97
|
+
def _generate_sources_spec(self) -> str:
|
|
98
|
+
if not self.registry.sources:
|
|
99
|
+
return ""
|
|
100
|
+
|
|
101
|
+
lines = [
|
|
102
|
+
"## Data Sources",
|
|
103
|
+
"",
|
|
104
|
+
"Multiple source files to process. Bronze notebooks can run in parallel.",
|
|
105
|
+
"",
|
|
106
|
+
"| Source | File Path | Recommendations |",
|
|
107
|
+
"|--------|-----------|-----------------|",
|
|
108
|
+
]
|
|
109
|
+
|
|
110
|
+
for name, bronze in self.registry.sources.items():
|
|
111
|
+
rec_count = len(bronze.all_recommendations)
|
|
112
|
+
lines.append(f"| `{name}` | {bronze.source_file} | {rec_count} |")
|
|
113
|
+
|
|
114
|
+
lines.extend([
|
|
115
|
+
"",
|
|
116
|
+
"### Per-Source Bronze Transformations",
|
|
117
|
+
"",
|
|
118
|
+
])
|
|
119
|
+
|
|
120
|
+
for name, bronze in self.registry.sources.items():
|
|
121
|
+
lines.append(f"#### {name}")
|
|
122
|
+
lines.append(f"- **Source file**: {bronze.source_file}")
|
|
123
|
+
if bronze.null_handling:
|
|
124
|
+
lines.append(f"- **Null handling**: {', '.join(r.target_column for r in bronze.null_handling)}")
|
|
125
|
+
if bronze.outlier_handling:
|
|
126
|
+
lines.append(f"- **Outlier handling**: {', '.join(r.target_column for r in bronze.outlier_handling)}")
|
|
127
|
+
if bronze.type_conversions:
|
|
128
|
+
lines.append(f"- **Type conversions**: {', '.join(r.target_column for r in bronze.type_conversions)}")
|
|
129
|
+
lines.append("")
|
|
130
|
+
|
|
131
|
+
return "\n".join(lines)
|
|
132
|
+
|
|
133
|
+
def _generate_bronze_spec(self) -> str:
|
|
134
|
+
lines = ["## Bronze Layer: Data Cleaning", ""]
|
|
135
|
+
if not self.registry.bronze or not self.registry.bronze.all_recommendations:
|
|
136
|
+
if not self.registry.sources:
|
|
137
|
+
lines.append("No bronze recommendations.")
|
|
138
|
+
else:
|
|
139
|
+
lines.append("See Per-Source Bronze Transformations above.")
|
|
140
|
+
return "\n".join(lines)
|
|
141
|
+
|
|
142
|
+
lines.extend([
|
|
143
|
+
"Implementation: Use `df.na.fill()` for imputation, `df.withColumn()` with `F.when()` for capping.",
|
|
144
|
+
"",
|
|
145
|
+
])
|
|
146
|
+
|
|
147
|
+
if self.registry.bronze.null_handling:
|
|
148
|
+
lines.append("### Null Handling")
|
|
149
|
+
lines.append("Use `df.na.fill()` or compute median/mean then fillna.")
|
|
150
|
+
for rec in self.registry.bronze.null_handling:
|
|
151
|
+
lines.extend(self._format_recommendation(rec))
|
|
152
|
+
|
|
153
|
+
if self.registry.bronze.outlier_handling:
|
|
154
|
+
lines.append("### Outlier Handling")
|
|
155
|
+
lines.append("Use IQR method: compute Q1, Q3, then clip with `F.when()`.")
|
|
156
|
+
for rec in self.registry.bronze.outlier_handling:
|
|
157
|
+
lines.extend(self._format_recommendation(rec))
|
|
158
|
+
|
|
159
|
+
if self.registry.bronze.type_conversions:
|
|
160
|
+
lines.append("### Type Conversions")
|
|
161
|
+
lines.append("Use `df.withColumn(col, F.col(col).cast(type))`.")
|
|
162
|
+
for rec in self.registry.bronze.type_conversions:
|
|
163
|
+
lines.extend(self._format_recommendation(rec))
|
|
164
|
+
|
|
165
|
+
if self.registry.bronze.filtering:
|
|
166
|
+
lines.append("### Filtering")
|
|
167
|
+
lines.append("Use `df.drop(columns)` or `df.filter()`.")
|
|
168
|
+
for rec in self.registry.bronze.filtering:
|
|
169
|
+
lines.extend(self._format_recommendation(rec))
|
|
170
|
+
|
|
171
|
+
return "\n".join(lines)
|
|
172
|
+
|
|
173
|
+
def _generate_silver_spec(self) -> str:
|
|
174
|
+
lines = ["## Silver Layer: Joins & Aggregations", ""]
|
|
175
|
+
if not self.registry.silver or not self.registry.silver.all_recommendations:
|
|
176
|
+
lines.append("No silver recommendations.")
|
|
177
|
+
return "\n".join(lines)
|
|
178
|
+
|
|
179
|
+
lines.append(f"- **Entity Column**: `{self.registry.silver.entity_column}`")
|
|
180
|
+
if self.registry.silver.time_column:
|
|
181
|
+
lines.append(f"- **Time Column**: `{self.registry.silver.time_column}`")
|
|
182
|
+
lines.extend([
|
|
183
|
+
"",
|
|
184
|
+
"Implementation: Use `Window.partitionBy()` for aggregations, `df.join()` for joins.",
|
|
185
|
+
"",
|
|
186
|
+
])
|
|
187
|
+
|
|
188
|
+
if self.registry.silver.joins:
|
|
189
|
+
lines.append("### Joins")
|
|
190
|
+
lines.append("Merge sources using `df.join()`. Execute after all bronze notebooks complete.")
|
|
191
|
+
for rec in self.registry.silver.joins:
|
|
192
|
+
lines.extend(self._format_recommendation(rec))
|
|
193
|
+
|
|
194
|
+
if self.registry.silver.aggregations:
|
|
195
|
+
lines.append("### Aggregations")
|
|
196
|
+
lines.append("Use window functions: `F.sum().over(Window.partitionBy(entity))`.")
|
|
197
|
+
for rec in self.registry.silver.aggregations:
|
|
198
|
+
lines.extend(self._format_recommendation(rec))
|
|
199
|
+
|
|
200
|
+
if self.registry.silver.derived_columns:
|
|
201
|
+
lines.append("### Derived Columns")
|
|
202
|
+
for rec in self.registry.silver.derived_columns:
|
|
203
|
+
lines.extend(self._format_recommendation(rec))
|
|
204
|
+
|
|
205
|
+
return "\n".join(lines)
|
|
206
|
+
|
|
207
|
+
def _generate_gold_spec(self) -> str:
|
|
208
|
+
lines = ["## Gold Layer: Feature Engineering", ""]
|
|
209
|
+
if not self.registry.gold or not self.registry.gold.all_recommendations:
|
|
210
|
+
lines.append("No gold recommendations.")
|
|
211
|
+
return "\n".join(lines)
|
|
212
|
+
|
|
213
|
+
lines.append(f"- **Target Column**: `{self.registry.gold.target_column}`")
|
|
214
|
+
lines.extend([
|
|
215
|
+
"",
|
|
216
|
+
"Implementation: Use `StringIndexer` + `OneHotEncoder` for categoricals, `StandardScaler` for numerics.",
|
|
217
|
+
"",
|
|
218
|
+
])
|
|
219
|
+
|
|
220
|
+
if self.registry.gold.encoding:
|
|
221
|
+
lines.append("### Encoding")
|
|
222
|
+
lines.append("For one_hot: `StringIndexer(inputCol) -> OneHotEncoder(inputCol_idx)`.")
|
|
223
|
+
for rec in self.registry.gold.encoding:
|
|
224
|
+
lines.extend(self._format_recommendation(rec))
|
|
225
|
+
|
|
226
|
+
if self.registry.gold.scaling:
|
|
227
|
+
lines.append("### Scaling")
|
|
228
|
+
lines.append("Use `VectorAssembler` then `StandardScaler` from pyspark.ml.feature.")
|
|
229
|
+
for rec in self.registry.gold.scaling:
|
|
230
|
+
lines.extend(self._format_recommendation(rec))
|
|
231
|
+
|
|
232
|
+
if self.registry.gold.transformations:
|
|
233
|
+
lines.append("### Transformations")
|
|
234
|
+
lines.append("Use `F.log1p()` for log, `F.sqrt()` for sqrt transformations.")
|
|
235
|
+
for rec in self.registry.gold.transformations:
|
|
236
|
+
lines.extend(self._format_recommendation(rec))
|
|
237
|
+
|
|
238
|
+
if self.registry.gold.feature_selection:
|
|
239
|
+
lines.append("### Feature Selection")
|
|
240
|
+
for rec in self.registry.gold.feature_selection:
|
|
241
|
+
lines.extend(self._format_recommendation(rec))
|
|
242
|
+
|
|
243
|
+
return "\n".join(lines)
|
|
244
|
+
|
|
245
|
+
def _generate_notebook_structure(self) -> str:
|
|
246
|
+
if not self.registry.sources:
|
|
247
|
+
return ""
|
|
248
|
+
|
|
249
|
+
source_names = list(self.registry.sources.keys())
|
|
250
|
+
lines = [
|
|
251
|
+
"## Notebook Structure",
|
|
252
|
+
"",
|
|
253
|
+
"Organize notebooks by layer. Bronze notebooks are independent and can run in parallel.",
|
|
254
|
+
"",
|
|
255
|
+
"```",
|
|
256
|
+
"pipeline/",
|
|
257
|
+
"├── bronze/ # Parallel execution",
|
|
258
|
+
]
|
|
259
|
+
|
|
260
|
+
for name in source_names:
|
|
261
|
+
lines.append(f"│ └── bronze_{name}.py")
|
|
262
|
+
|
|
263
|
+
lines.extend([
|
|
264
|
+
"├── silver/ # After bronze completes",
|
|
265
|
+
"│ └── silver_merge.py # Joins all bronze outputs",
|
|
266
|
+
"└── gold/ # After silver completes",
|
|
267
|
+
" └── gold_features.py # Final ML-ready features",
|
|
268
|
+
"```",
|
|
269
|
+
"",
|
|
270
|
+
"### Execution Order",
|
|
271
|
+
"",
|
|
272
|
+
f"1. **Bronze** (parallel): Run all bronze notebooks independently ({', '.join(source_names)})",
|
|
273
|
+
"2. **Silver** (sequential): After all bronze complete, run silver merge notebook",
|
|
274
|
+
"3. **Gold** (sequential): After silver completes, run gold features notebook",
|
|
275
|
+
])
|
|
276
|
+
return "\n".join(lines)
|
|
277
|
+
|
|
278
|
+
def _generate_delta_structure(self) -> str:
|
|
279
|
+
lines = [
|
|
280
|
+
"## Delta Table Structure",
|
|
281
|
+
"",
|
|
282
|
+
"Write each layer to Delta tables using:",
|
|
283
|
+
"```",
|
|
284
|
+
'df.write.format("delta").mode("overwrite").saveAsTable("catalog.schema.layer_table")',
|
|
285
|
+
"```",
|
|
286
|
+
"",
|
|
287
|
+
"Suggested table names:",
|
|
288
|
+
]
|
|
289
|
+
|
|
290
|
+
if self.registry.sources:
|
|
291
|
+
for name in self.registry.sources.keys():
|
|
292
|
+
lines.append(f"- Bronze ({name}): `{{catalog}}.{{schema}}.bronze_{name}`")
|
|
293
|
+
else:
|
|
294
|
+
lines.append("- Bronze: `{catalog}.{schema}.bronze_customers`")
|
|
295
|
+
|
|
296
|
+
lines.extend([
|
|
297
|
+
"- Silver: `{catalog}.{schema}.silver_customers`",
|
|
298
|
+
"- Gold: `{catalog}.{schema}.gold_customers`",
|
|
299
|
+
])
|
|
300
|
+
return "\n".join(lines)
|
|
301
|
+
|
|
302
|
+
def _format_recommendation(self, rec: LayeredRecommendation) -> List[str]:
|
|
303
|
+
lines = [
|
|
304
|
+
f"#### {rec.target_column}",
|
|
305
|
+
f"- **Action**: {rec.action}",
|
|
306
|
+
f"- **Parameters**: {rec.parameters}",
|
|
307
|
+
f"- **Rationale**: {rec.rationale}",
|
|
308
|
+
f"- **Source**: {rec.source_notebook}",
|
|
309
|
+
"",
|
|
310
|
+
]
|
|
311
|
+
return lines
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from .findings_parser import FindingsParser
|
|
2
|
+
from .generator import PipelineGenerator
|
|
3
|
+
from .models import (
|
|
4
|
+
AggregationWindowConfig,
|
|
5
|
+
BronzeEventConfig,
|
|
6
|
+
BronzeLayerConfig,
|
|
7
|
+
GoldLayerConfig,
|
|
8
|
+
LabelTimestampConfig,
|
|
9
|
+
LandingLayerConfig,
|
|
10
|
+
LifecycleConfig,
|
|
11
|
+
PipelineConfig,
|
|
12
|
+
PipelineTransformationType,
|
|
13
|
+
SilverLayerConfig,
|
|
14
|
+
SourceConfig,
|
|
15
|
+
TimestampCoalesceConfig,
|
|
16
|
+
TransformationStep,
|
|
17
|
+
)
|
|
18
|
+
from .renderer import CodeRenderer
|
|
19
|
+
|
|
20
|
+
__all__ = [
|
|
21
|
+
"PipelineTransformationType", "SourceConfig", "TransformationStep",
|
|
22
|
+
"BronzeLayerConfig", "BronzeEventConfig", "SilverLayerConfig", "GoldLayerConfig", "PipelineConfig",
|
|
23
|
+
"PipelineGenerator", "FindingsParser", "CodeRenderer",
|
|
24
|
+
"AggregationWindowConfig", "LifecycleConfig", "LandingLayerConfig",
|
|
25
|
+
"TimestampCoalesceConfig", "LabelTimestampConfig",
|
|
26
|
+
]
|