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,256 @@
|
|
|
1
|
+
from customer_retention.core.components.enums import Severity
|
|
2
|
+
from customer_retention.core.utils import compute_effect_size
|
|
3
|
+
|
|
4
|
+
from .column_profiler import CategoricalProfiler, ColumnProfiler, NumericProfiler, ProfilerFactory
|
|
5
|
+
from .distribution_analysis import (
|
|
6
|
+
DistributionAnalysis,
|
|
7
|
+
DistributionAnalyzer,
|
|
8
|
+
DistributionTransformationType,
|
|
9
|
+
TransformationRecommendation,
|
|
10
|
+
)
|
|
11
|
+
from .drift_detector import BaselineDriftChecker
|
|
12
|
+
from .drift_detector import DriftResult as BaselineDriftResult
|
|
13
|
+
from .profile_result import (
|
|
14
|
+
BinaryMetrics,
|
|
15
|
+
CategoricalMetrics,
|
|
16
|
+
ColumnProfile,
|
|
17
|
+
DatetimeMetrics,
|
|
18
|
+
GranularityResult,
|
|
19
|
+
IdentifierMetrics,
|
|
20
|
+
NumericMetrics,
|
|
21
|
+
ProfileResult,
|
|
22
|
+
TargetMetrics,
|
|
23
|
+
TextMetrics,
|
|
24
|
+
TypeConfidence,
|
|
25
|
+
TypeInference,
|
|
26
|
+
UniversalMetrics,
|
|
27
|
+
)
|
|
28
|
+
from .quality_checks import QualityCheck, QualityCheckRegistry, QualityCheckResult
|
|
29
|
+
from .report_generator import ReportGenerator
|
|
30
|
+
from .scd_analyzer import SCDAnalyzer, SCDResult
|
|
31
|
+
from .type_detector import TypeDetector
|
|
32
|
+
|
|
33
|
+
# Backward compatibility alias
|
|
34
|
+
TransformationType = DistributionTransformationType
|
|
35
|
+
from .categorical_distribution import (
|
|
36
|
+
CategoricalDistributionAnalysis,
|
|
37
|
+
CategoricalDistributionAnalyzer,
|
|
38
|
+
EncodingRecommendation,
|
|
39
|
+
EncodingType,
|
|
40
|
+
)
|
|
41
|
+
from .categorical_target_analyzer import (
|
|
42
|
+
CategoricalAnalysisResult,
|
|
43
|
+
CategoricalFeatureInsight,
|
|
44
|
+
CategoricalTargetAnalyzer,
|
|
45
|
+
CategoricalTargetResult,
|
|
46
|
+
analyze_categorical_features,
|
|
47
|
+
filter_categorical_columns,
|
|
48
|
+
)
|
|
49
|
+
from .feature_capacity import (
|
|
50
|
+
EffectiveFeaturesResult,
|
|
51
|
+
FeatureCapacityAnalyzer,
|
|
52
|
+
FeatureCapacityResult,
|
|
53
|
+
ModelComplexityGuidance,
|
|
54
|
+
SegmentCapacityResult,
|
|
55
|
+
)
|
|
56
|
+
from .pattern_analysis_config import (
|
|
57
|
+
AggregationFeatureConfig,
|
|
58
|
+
FindingsValidationResult,
|
|
59
|
+
PatternAnalysisConfig,
|
|
60
|
+
PatternAnalysisResult,
|
|
61
|
+
SparklineData,
|
|
62
|
+
SparklineDataBuilder,
|
|
63
|
+
create_momentum_ratio_features,
|
|
64
|
+
create_recency_bucket_feature,
|
|
65
|
+
deduplicate_events,
|
|
66
|
+
get_analysis_frequency,
|
|
67
|
+
get_duplicate_event_count,
|
|
68
|
+
get_sparkline_frequency,
|
|
69
|
+
validate_temporal_findings,
|
|
70
|
+
)
|
|
71
|
+
from .relationship_detector import DatasetRelationship, JoinSuggestion, RelationshipDetector, RelationshipType
|
|
72
|
+
from .relationship_recommender import (
|
|
73
|
+
RecommendationCategory,
|
|
74
|
+
RelationshipAnalysisSummary,
|
|
75
|
+
RelationshipRecommendation,
|
|
76
|
+
RelationshipRecommender,
|
|
77
|
+
)
|
|
78
|
+
from .segment_analyzer import (
|
|
79
|
+
ClusterVisualizationResult,
|
|
80
|
+
DimensionReductionMethod,
|
|
81
|
+
FullSegmentationResult,
|
|
82
|
+
SegmentAnalyzer,
|
|
83
|
+
SegmentationDecisionMetrics,
|
|
84
|
+
SegmentationMethod,
|
|
85
|
+
SegmentationResult,
|
|
86
|
+
SegmentProfile,
|
|
87
|
+
)
|
|
88
|
+
from .segment_aware_outlier import SegmentAwareOutlierAnalyzer, SegmentAwareOutlierResult
|
|
89
|
+
from .target_level_analyzer import (
|
|
90
|
+
AggregationMethod,
|
|
91
|
+
TargetColumnDetector,
|
|
92
|
+
TargetDistribution,
|
|
93
|
+
TargetLevel,
|
|
94
|
+
TargetLevelAnalyzer,
|
|
95
|
+
TargetLevelResult,
|
|
96
|
+
)
|
|
97
|
+
from .temporal_analyzer import (
|
|
98
|
+
SeasonalityResult,
|
|
99
|
+
TemporalAnalysis,
|
|
100
|
+
TemporalAnalyzer,
|
|
101
|
+
TemporalGranularity,
|
|
102
|
+
TemporalRecommendation,
|
|
103
|
+
TemporalRecommendationType,
|
|
104
|
+
)
|
|
105
|
+
from .temporal_coverage import (
|
|
106
|
+
DriftImplication,
|
|
107
|
+
EntityWindowCoverage,
|
|
108
|
+
FeatureAvailability,
|
|
109
|
+
FeatureAvailabilityResult,
|
|
110
|
+
TemporalCoverageResult,
|
|
111
|
+
TemporalGap,
|
|
112
|
+
analyze_feature_availability,
|
|
113
|
+
analyze_temporal_coverage,
|
|
114
|
+
derive_drift_implications,
|
|
115
|
+
)
|
|
116
|
+
from .temporal_feature_analyzer import (
|
|
117
|
+
CohortMomentumResult,
|
|
118
|
+
CohortVelocityResult,
|
|
119
|
+
FeatureRecommendation,
|
|
120
|
+
FeatureType,
|
|
121
|
+
LagCorrelationResult,
|
|
122
|
+
MomentumResult,
|
|
123
|
+
PredictivePowerResult,
|
|
124
|
+
TemporalFeatureAnalyzer,
|
|
125
|
+
VelocityRecommendation,
|
|
126
|
+
VelocityResult,
|
|
127
|
+
)
|
|
128
|
+
from .temporal_feature_engineer import (
|
|
129
|
+
FeatureGroup,
|
|
130
|
+
FeatureGroupResult,
|
|
131
|
+
ReferenceMode,
|
|
132
|
+
TemporalAggregationConfig,
|
|
133
|
+
TemporalFeatureEngineer,
|
|
134
|
+
TemporalFeatureResult,
|
|
135
|
+
)
|
|
136
|
+
from .temporal_pattern_analyzer import (
|
|
137
|
+
AnomalyDiagnostics,
|
|
138
|
+
CohortDistribution,
|
|
139
|
+
CohortRecommendation,
|
|
140
|
+
GroupStats,
|
|
141
|
+
RecencyBucketStats,
|
|
142
|
+
RecencyComparisonResult,
|
|
143
|
+
RecencyInsight,
|
|
144
|
+
RecencyResult,
|
|
145
|
+
SeasonalityPeriod,
|
|
146
|
+
TemporalPatternAnalysis,
|
|
147
|
+
TemporalPatternAnalyzer,
|
|
148
|
+
TrendDirection,
|
|
149
|
+
TrendRecommendation,
|
|
150
|
+
TrendResult,
|
|
151
|
+
analyze_cohort_distribution,
|
|
152
|
+
classify_distribution_pattern,
|
|
153
|
+
compare_recency_by_target,
|
|
154
|
+
compute_group_stats,
|
|
155
|
+
compute_recency_buckets,
|
|
156
|
+
detect_inflection_bucket,
|
|
157
|
+
generate_cohort_recommendations,
|
|
158
|
+
generate_recency_insights,
|
|
159
|
+
generate_trend_recommendations,
|
|
160
|
+
)
|
|
161
|
+
from .temporal_quality_checks import (
|
|
162
|
+
DuplicateEventCheck,
|
|
163
|
+
EventOrderCheck,
|
|
164
|
+
FutureDateCheck,
|
|
165
|
+
TemporalGapCheck,
|
|
166
|
+
TemporalQualityCheck,
|
|
167
|
+
TemporalQualityReporter,
|
|
168
|
+
TemporalQualityResult,
|
|
169
|
+
TemporalQualityScore,
|
|
170
|
+
)
|
|
171
|
+
from .temporal_target_analyzer import TemporalTargetAnalyzer, TemporalTargetResult
|
|
172
|
+
from .text_embedder import EMBEDDING_MODELS, TextEmbedder, get_model_info, list_available_models
|
|
173
|
+
from .text_processor import TextColumnProcessor, TextColumnResult, TextProcessingConfig
|
|
174
|
+
from .text_reducer import ReductionResult, TextDimensionalityReducer
|
|
175
|
+
from .time_series_profiler import (
|
|
176
|
+
ActivitySegmentResult,
|
|
177
|
+
DistributionStats,
|
|
178
|
+
EntityLifecycle,
|
|
179
|
+
LifecycleQuadrantResult,
|
|
180
|
+
TimeSeriesProfile,
|
|
181
|
+
TimeSeriesProfiler,
|
|
182
|
+
classify_activity_segments,
|
|
183
|
+
classify_lifecycle_quadrants,
|
|
184
|
+
)
|
|
185
|
+
from .time_window_aggregator import AggregationPlan, AggregationType, TimeWindow, TimeWindowAggregator
|
|
186
|
+
from .window_recommendation import (
|
|
187
|
+
TemporalHeterogeneityResult,
|
|
188
|
+
WindowRecommendationCollector,
|
|
189
|
+
WindowUnionResult,
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
__all__ = [
|
|
193
|
+
"Severity",
|
|
194
|
+
"ProfileResult", "ColumnProfile", "TypeInference", "TypeConfidence",
|
|
195
|
+
"UniversalMetrics", "NumericMetrics", "CategoricalMetrics",
|
|
196
|
+
"DatetimeMetrics", "BinaryMetrics", "IdentifierMetrics", "TargetMetrics", "TextMetrics",
|
|
197
|
+
"GranularityResult",
|
|
198
|
+
"TypeDetector",
|
|
199
|
+
"ColumnProfiler", "ProfilerFactory", "NumericProfiler", "CategoricalProfiler",
|
|
200
|
+
"QualityCheck", "QualityCheckResult", "QualityCheckRegistry",
|
|
201
|
+
"BaselineDriftChecker", "BaselineDriftResult",
|
|
202
|
+
"ReportGenerator",
|
|
203
|
+
"SCDAnalyzer", "SCDResult",
|
|
204
|
+
"DistributionAnalyzer", "DistributionAnalysis",
|
|
205
|
+
"TransformationRecommendation", "DistributionTransformationType", "TransformationType",
|
|
206
|
+
"CategoricalDistributionAnalyzer", "CategoricalDistributionAnalysis",
|
|
207
|
+
"EncodingRecommendation", "EncodingType",
|
|
208
|
+
"TemporalAnalyzer", "TemporalAnalysis", "TemporalGranularity", "SeasonalityResult",
|
|
209
|
+
"TemporalRecommendation", "TemporalRecommendationType",
|
|
210
|
+
"SegmentAnalyzer", "SegmentationResult", "SegmentProfile", "SegmentationMethod",
|
|
211
|
+
"DimensionReductionMethod", "ClusterVisualizationResult",
|
|
212
|
+
"SegmentationDecisionMetrics", "FullSegmentationResult",
|
|
213
|
+
"SegmentAwareOutlierAnalyzer", "SegmentAwareOutlierResult",
|
|
214
|
+
"CategoricalTargetAnalyzer", "CategoricalTargetResult",
|
|
215
|
+
"CategoricalAnalysisResult", "CategoricalFeatureInsight",
|
|
216
|
+
"analyze_categorical_features", "filter_categorical_columns",
|
|
217
|
+
"TemporalTargetAnalyzer", "TemporalTargetResult",
|
|
218
|
+
"TargetLevelAnalyzer", "TargetLevelResult", "TargetLevel", "AggregationMethod",
|
|
219
|
+
"TargetDistribution", "TargetColumnDetector",
|
|
220
|
+
"PatternAnalysisConfig", "PatternAnalysisResult",
|
|
221
|
+
"SparklineData", "SparklineDataBuilder",
|
|
222
|
+
"get_analysis_frequency", "get_sparkline_frequency",
|
|
223
|
+
"AggregationFeatureConfig", "FindingsValidationResult", "validate_temporal_findings",
|
|
224
|
+
"get_duplicate_event_count", "deduplicate_events",
|
|
225
|
+
"create_recency_bucket_feature", "create_momentum_ratio_features",
|
|
226
|
+
"TimeSeriesProfiler", "TimeSeriesProfile", "DistributionStats", "EntityLifecycle",
|
|
227
|
+
"LifecycleQuadrantResult", "classify_lifecycle_quadrants",
|
|
228
|
+
"ActivitySegmentResult", "classify_activity_segments",
|
|
229
|
+
"TemporalQualityCheck", "TemporalQualityReporter", "TemporalQualityResult", "TemporalQualityScore",
|
|
230
|
+
"DuplicateEventCheck", "TemporalGapCheck", "FutureDateCheck", "EventOrderCheck",
|
|
231
|
+
"TemporalPatternAnalyzer", "TemporalPatternAnalysis",
|
|
232
|
+
"TrendResult", "TrendDirection", "TrendRecommendation", "SeasonalityPeriod", "RecencyResult",
|
|
233
|
+
"RecencyComparisonResult", "RecencyBucketStats", "RecencyInsight", "AnomalyDiagnostics",
|
|
234
|
+
"GroupStats", "CohortDistribution", "CohortRecommendation",
|
|
235
|
+
"generate_trend_recommendations", "generate_cohort_recommendations", "generate_recency_insights",
|
|
236
|
+
"analyze_cohort_distribution", "compare_recency_by_target",
|
|
237
|
+
"compute_effect_size", "compute_group_stats", "compute_recency_buckets",
|
|
238
|
+
"detect_inflection_bucket", "classify_distribution_pattern",
|
|
239
|
+
"RelationshipDetector", "DatasetRelationship", "RelationshipType", "JoinSuggestion",
|
|
240
|
+
"TimeWindowAggregator", "AggregationPlan", "TimeWindow", "AggregationType",
|
|
241
|
+
"TemporalFeatureAnalyzer", "VelocityResult", "MomentumResult", "CohortVelocityResult",
|
|
242
|
+
"CohortMomentumResult", "VelocityRecommendation", "LagCorrelationResult", "PredictivePowerResult", "FeatureRecommendation", "FeatureType",
|
|
243
|
+
"RelationshipRecommender", "RelationshipRecommendation",
|
|
244
|
+
"RecommendationCategory", "RelationshipAnalysisSummary",
|
|
245
|
+
"FeatureCapacityAnalyzer", "FeatureCapacityResult",
|
|
246
|
+
"SegmentCapacityResult", "EffectiveFeaturesResult", "ModelComplexityGuidance",
|
|
247
|
+
"TemporalFeatureEngineer", "TemporalAggregationConfig",
|
|
248
|
+
"ReferenceMode", "FeatureGroup", "FeatureGroupResult", "TemporalFeatureResult",
|
|
249
|
+
"TextEmbedder", "EMBEDDING_MODELS", "get_model_info", "list_available_models",
|
|
250
|
+
"TextDimensionalityReducer", "ReductionResult",
|
|
251
|
+
"TextColumnProcessor", "TextProcessingConfig", "TextColumnResult",
|
|
252
|
+
"WindowRecommendationCollector", "WindowUnionResult", "TemporalHeterogeneityResult",
|
|
253
|
+
"analyze_temporal_coverage", "TemporalCoverageResult", "TemporalGap", "EntityWindowCoverage",
|
|
254
|
+
"derive_drift_implications", "DriftImplication",
|
|
255
|
+
"analyze_feature_availability", "FeatureAvailability", "FeatureAvailabilityResult",
|
|
256
|
+
]
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
from dataclasses import dataclass, field
|
|
2
|
+
from enum import Enum
|
|
3
|
+
from typing import Any, Dict, List, Optional
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
|
|
7
|
+
from customer_retention.core.compat import Series, pd
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class EncodingType(Enum):
|
|
11
|
+
ONE_HOT = "one_hot"
|
|
12
|
+
TARGET = "target"
|
|
13
|
+
FREQUENCY = "frequency"
|
|
14
|
+
ORDINAL = "ordinal"
|
|
15
|
+
CYCLICAL = "cyclical"
|
|
16
|
+
BINARY = "binary"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@dataclass
|
|
20
|
+
class CategoricalDistributionAnalysis:
|
|
21
|
+
column_name: str
|
|
22
|
+
category_count: int
|
|
23
|
+
total_count: int
|
|
24
|
+
imbalance_ratio: float
|
|
25
|
+
entropy: float
|
|
26
|
+
normalized_entropy: float
|
|
27
|
+
top1_concentration: float
|
|
28
|
+
top3_concentration: float
|
|
29
|
+
rare_category_count: int
|
|
30
|
+
rare_category_names: List[str]
|
|
31
|
+
value_counts: Dict[str, int]
|
|
32
|
+
|
|
33
|
+
IMBALANCE_THRESHOLD = 10.0
|
|
34
|
+
LOW_DIVERSITY_THRESHOLD = 0.5
|
|
35
|
+
HIGH_CONCENTRATION_THRESHOLD = 90.0
|
|
36
|
+
|
|
37
|
+
@property
|
|
38
|
+
def is_imbalanced(self) -> bool:
|
|
39
|
+
return self.imbalance_ratio > self.IMBALANCE_THRESHOLD
|
|
40
|
+
|
|
41
|
+
@property
|
|
42
|
+
def has_low_diversity(self) -> bool:
|
|
43
|
+
return self.normalized_entropy < self.LOW_DIVERSITY_THRESHOLD
|
|
44
|
+
|
|
45
|
+
@property
|
|
46
|
+
def has_rare_categories(self) -> bool:
|
|
47
|
+
return self.rare_category_count > 0
|
|
48
|
+
|
|
49
|
+
@property
|
|
50
|
+
def is_highly_concentrated(self) -> bool:
|
|
51
|
+
return self.top3_concentration > self.HIGH_CONCENTRATION_THRESHOLD
|
|
52
|
+
|
|
53
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
54
|
+
return {
|
|
55
|
+
"column": self.column_name,
|
|
56
|
+
"categories": self.category_count,
|
|
57
|
+
"imbalance_ratio": round(self.imbalance_ratio, 2),
|
|
58
|
+
"entropy": round(self.entropy, 3),
|
|
59
|
+
"normalized_entropy": round(self.normalized_entropy, 3),
|
|
60
|
+
"top1_concentration": round(self.top1_concentration, 1),
|
|
61
|
+
"top3_concentration": round(self.top3_concentration, 1),
|
|
62
|
+
"rare_categories": self.rare_category_count,
|
|
63
|
+
"is_imbalanced": self.is_imbalanced,
|
|
64
|
+
"has_low_diversity": self.has_low_diversity,
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
@dataclass
|
|
69
|
+
class EncodingRecommendation:
|
|
70
|
+
column_name: str
|
|
71
|
+
encoding_type: EncodingType
|
|
72
|
+
reason: str
|
|
73
|
+
priority: str
|
|
74
|
+
preprocessing_steps: List[str] = field(default_factory=list)
|
|
75
|
+
warnings: List[str] = field(default_factory=list)
|
|
76
|
+
|
|
77
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
78
|
+
return {
|
|
79
|
+
"column": self.column_name,
|
|
80
|
+
"encoding": self.encoding_type.value,
|
|
81
|
+
"reason": self.reason,
|
|
82
|
+
"priority": self.priority,
|
|
83
|
+
"preprocessing_steps": self.preprocessing_steps,
|
|
84
|
+
"warnings": self.warnings,
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class CategoricalDistributionAnalyzer:
|
|
89
|
+
LOW_CARDINALITY_THRESHOLD = 5
|
|
90
|
+
MEDIUM_CARDINALITY_THRESHOLD = 20
|
|
91
|
+
RARE_CATEGORY_THRESHOLD = 0.01
|
|
92
|
+
|
|
93
|
+
def analyze(self, series: Series, column_name: str) -> CategoricalDistributionAnalysis:
|
|
94
|
+
clean_series = series.dropna()
|
|
95
|
+
total_count = len(clean_series)
|
|
96
|
+
|
|
97
|
+
if total_count == 0:
|
|
98
|
+
return self._empty_analysis(column_name)
|
|
99
|
+
|
|
100
|
+
value_counts = clean_series.value_counts()
|
|
101
|
+
category_count = len(value_counts)
|
|
102
|
+
|
|
103
|
+
if category_count == 0:
|
|
104
|
+
return self._empty_analysis(column_name)
|
|
105
|
+
|
|
106
|
+
imbalance_ratio = float(value_counts.iloc[0] / value_counts.iloc[-1]) if value_counts.iloc[-1] > 0 else float('inf')
|
|
107
|
+
entropy, normalized_entropy = self._calculate_entropy(value_counts, total_count, category_count)
|
|
108
|
+
top1_concentration = float(value_counts.iloc[0] / total_count * 100)
|
|
109
|
+
top3_concentration = float(value_counts.head(3).sum() / total_count * 100)
|
|
110
|
+
rare_threshold = total_count * self.RARE_CATEGORY_THRESHOLD
|
|
111
|
+
rare_mask = value_counts < rare_threshold
|
|
112
|
+
rare_category_count = int(rare_mask.sum())
|
|
113
|
+
rare_category_names = value_counts[rare_mask].index.tolist()
|
|
114
|
+
|
|
115
|
+
return CategoricalDistributionAnalysis(
|
|
116
|
+
column_name=column_name,
|
|
117
|
+
category_count=category_count,
|
|
118
|
+
total_count=total_count,
|
|
119
|
+
imbalance_ratio=imbalance_ratio,
|
|
120
|
+
entropy=entropy,
|
|
121
|
+
normalized_entropy=normalized_entropy,
|
|
122
|
+
top1_concentration=top1_concentration,
|
|
123
|
+
top3_concentration=top3_concentration,
|
|
124
|
+
rare_category_count=rare_category_count,
|
|
125
|
+
rare_category_names=rare_category_names[:10],
|
|
126
|
+
value_counts=value_counts.head(20).to_dict(),
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
def _empty_analysis(self, column_name: str) -> CategoricalDistributionAnalysis:
|
|
130
|
+
return CategoricalDistributionAnalysis(
|
|
131
|
+
column_name=column_name, category_count=0, total_count=0,
|
|
132
|
+
imbalance_ratio=0.0, entropy=0.0, normalized_entropy=0.0,
|
|
133
|
+
top1_concentration=0.0, top3_concentration=0.0,
|
|
134
|
+
rare_category_count=0, rare_category_names=[], value_counts={},
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
def _calculate_entropy(self, value_counts: Series, total: int, n_categories: int) -> tuple:
|
|
138
|
+
probabilities = value_counts / total
|
|
139
|
+
entropy = float(-np.sum(probabilities * np.log2(probabilities + 1e-10)))
|
|
140
|
+
max_entropy = np.log2(n_categories) if n_categories > 1 else 1.0
|
|
141
|
+
normalized = entropy / max_entropy if max_entropy > 0 else 0.0
|
|
142
|
+
return entropy, normalized
|
|
143
|
+
|
|
144
|
+
def recommend_encoding(
|
|
145
|
+
self, analysis: CategoricalDistributionAnalysis, is_cyclical: bool = False, is_ordinal: bool = False
|
|
146
|
+
) -> EncodingRecommendation:
|
|
147
|
+
preprocessing = []
|
|
148
|
+
warnings = []
|
|
149
|
+
|
|
150
|
+
if is_cyclical:
|
|
151
|
+
return EncodingRecommendation(
|
|
152
|
+
column_name=analysis.column_name,
|
|
153
|
+
encoding_type=EncodingType.CYCLICAL,
|
|
154
|
+
reason="Cyclical data benefits from sin/cos encoding to preserve circular relationships",
|
|
155
|
+
priority="medium",
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
if is_ordinal:
|
|
159
|
+
return EncodingRecommendation(
|
|
160
|
+
column_name=analysis.column_name,
|
|
161
|
+
encoding_type=EncodingType.ORDINAL,
|
|
162
|
+
reason="Ordinal data should preserve category order",
|
|
163
|
+
priority="medium",
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
if analysis.category_count == 2:
|
|
167
|
+
return EncodingRecommendation(
|
|
168
|
+
column_name=analysis.column_name,
|
|
169
|
+
encoding_type=EncodingType.BINARY,
|
|
170
|
+
reason="Binary categorical - simple 0/1 encoding",
|
|
171
|
+
priority="low",
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
if analysis.has_rare_categories:
|
|
175
|
+
preprocessing.append(f"Group {analysis.rare_category_count} rare categories into 'Other'")
|
|
176
|
+
|
|
177
|
+
if analysis.is_imbalanced:
|
|
178
|
+
warnings.append("Use stratified sampling to preserve rare category representation")
|
|
179
|
+
|
|
180
|
+
if analysis.category_count <= self.LOW_CARDINALITY_THRESHOLD:
|
|
181
|
+
return EncodingRecommendation(
|
|
182
|
+
column_name=analysis.column_name,
|
|
183
|
+
encoding_type=EncodingType.ONE_HOT,
|
|
184
|
+
reason=f"Low cardinality ({analysis.category_count} categories) - safe feature expansion",
|
|
185
|
+
priority="low",
|
|
186
|
+
preprocessing_steps=preprocessing,
|
|
187
|
+
warnings=warnings,
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
if analysis.category_count <= self.MEDIUM_CARDINALITY_THRESHOLD:
|
|
191
|
+
if analysis.has_rare_categories:
|
|
192
|
+
encoding = EncodingType.TARGET
|
|
193
|
+
reason = f"Medium cardinality ({analysis.category_count}) with rare categories - target encoding preferred"
|
|
194
|
+
priority = "medium"
|
|
195
|
+
else:
|
|
196
|
+
encoding = EncodingType.ONE_HOT
|
|
197
|
+
reason = f"Medium cardinality ({analysis.category_count}) without rare categories"
|
|
198
|
+
priority = "low"
|
|
199
|
+
return EncodingRecommendation(
|
|
200
|
+
column_name=analysis.column_name,
|
|
201
|
+
encoding_type=encoding,
|
|
202
|
+
reason=reason,
|
|
203
|
+
priority=priority,
|
|
204
|
+
preprocessing_steps=preprocessing,
|
|
205
|
+
warnings=warnings,
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
warnings.append("High cardinality may require regularization with target encoding")
|
|
209
|
+
return EncodingRecommendation(
|
|
210
|
+
column_name=analysis.column_name,
|
|
211
|
+
encoding_type=EncodingType.TARGET,
|
|
212
|
+
reason=f"High cardinality ({analysis.category_count} categories) - target or frequency encoding",
|
|
213
|
+
priority="high",
|
|
214
|
+
preprocessing_steps=preprocessing,
|
|
215
|
+
warnings=warnings,
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
def analyze_dataframe(
|
|
219
|
+
self, df: pd.DataFrame, categorical_columns: Optional[List[str]] = None
|
|
220
|
+
) -> Dict[str, CategoricalDistributionAnalysis]:
|
|
221
|
+
if categorical_columns is None:
|
|
222
|
+
categorical_columns = df.select_dtypes(include=["object", "category"]).columns.tolist()
|
|
223
|
+
|
|
224
|
+
return {col: self.analyze(df[col], col) for col in categorical_columns if col in df.columns}
|
|
225
|
+
|
|
226
|
+
def get_all_recommendations(
|
|
227
|
+
self, df: pd.DataFrame, categorical_columns: Optional[List[str]] = None,
|
|
228
|
+
cyclical_columns: Optional[List[str]] = None, ordinal_columns: Optional[List[str]] = None
|
|
229
|
+
) -> List[EncodingRecommendation]:
|
|
230
|
+
cyclical_columns = cyclical_columns or []
|
|
231
|
+
ordinal_columns = ordinal_columns or []
|
|
232
|
+
analyses = self.analyze_dataframe(df, categorical_columns)
|
|
233
|
+
|
|
234
|
+
recommendations = []
|
|
235
|
+
for col_name, analysis in analyses.items():
|
|
236
|
+
is_cyclical = col_name in cyclical_columns
|
|
237
|
+
is_ordinal = col_name in ordinal_columns
|
|
238
|
+
rec = self.recommend_encoding(analysis, is_cyclical=is_cyclical, is_ordinal=is_ordinal)
|
|
239
|
+
recommendations.append(rec)
|
|
240
|
+
|
|
241
|
+
priority_order = {"high": 0, "medium": 1, "low": 2}
|
|
242
|
+
recommendations.sort(key=lambda r: priority_order.get(r.priority, 3))
|
|
243
|
+
return recommendations
|
|
244
|
+
|
|
245
|
+
def generate_summary(
|
|
246
|
+
self, df: pd.DataFrame, categorical_columns: Optional[List[str]] = None
|
|
247
|
+
) -> Dict[str, Any]:
|
|
248
|
+
analyses = self.analyze_dataframe(df, categorical_columns)
|
|
249
|
+
recommendations = self.get_all_recommendations(df, categorical_columns)
|
|
250
|
+
|
|
251
|
+
imbalanced = [n for n, a in analyses.items() if a.is_imbalanced]
|
|
252
|
+
low_diversity = [n for n, a in analyses.items() if a.has_low_diversity]
|
|
253
|
+
with_rare = [n for n, a in analyses.items() if a.has_rare_categories]
|
|
254
|
+
|
|
255
|
+
return {
|
|
256
|
+
"summary": {
|
|
257
|
+
"total_columns": len(analyses),
|
|
258
|
+
"imbalanced_count": len(imbalanced),
|
|
259
|
+
"low_diversity_count": len(low_diversity),
|
|
260
|
+
"with_rare_categories_count": len(with_rare),
|
|
261
|
+
},
|
|
262
|
+
"categories": {
|
|
263
|
+
"imbalanced": imbalanced,
|
|
264
|
+
"low_diversity": low_diversity,
|
|
265
|
+
"with_rare_categories": with_rare,
|
|
266
|
+
},
|
|
267
|
+
"analyses": {k: v.to_dict() for k, v in analyses.items()},
|
|
268
|
+
"recommendations": [r.to_dict() for r in recommendations],
|
|
269
|
+
}
|