gitlabds 2.0.0__tar.gz → 2.1.0__tar.gz

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.
Files changed (27) hide show
  1. {gitlabds-2.0.0 → gitlabds-2.1.0}/PKG-INFO +146 -57
  2. {gitlabds-2.0.0 → gitlabds-2.1.0}/README.md +145 -56
  3. {gitlabds-2.0.0 → gitlabds-2.1.0}/gitlabds/__init__.py +2 -1
  4. gitlabds-2.1.0/gitlabds/baselines.py +352 -0
  5. {gitlabds-2.0.0 → gitlabds-2.1.0}/gitlabds/model_evaluator.py +8 -8
  6. gitlabds-2.1.0/gitlabds/monitoring_metrics.py +466 -0
  7. {gitlabds-2.0.0 → gitlabds-2.1.0}/gitlabds/trends.py +1 -1
  8. {gitlabds-2.0.0 → gitlabds-2.1.0}/gitlabds.egg-info/PKG-INFO +146 -57
  9. {gitlabds-2.0.0 → gitlabds-2.1.0}/gitlabds.egg-info/SOURCES.txt +2 -1
  10. {gitlabds-2.0.0 → gitlabds-2.1.0}/setup.py +2 -0
  11. gitlabds-2.0.0/gitlabds/model_metrics.py +0 -578
  12. {gitlabds-2.0.0 → gitlabds-2.1.0}/LICENSE +0 -0
  13. {gitlabds-2.0.0 → gitlabds-2.1.0}/gitlabds/config_generator.py +0 -0
  14. {gitlabds-2.0.0 → gitlabds-2.1.0}/gitlabds/dummy.py +0 -0
  15. {gitlabds-2.0.0 → gitlabds-2.1.0}/gitlabds/feature_reduction.py +0 -0
  16. {gitlabds-2.0.0 → gitlabds-2.1.0}/gitlabds/insights.py +0 -0
  17. {gitlabds-2.0.0 → gitlabds-2.1.0}/gitlabds/memory_optimization.py +0 -0
  18. {gitlabds-2.0.0 → gitlabds-2.1.0}/gitlabds/missing.py +0 -0
  19. {gitlabds-2.0.0 → gitlabds-2.1.0}/gitlabds/missing_check.py +0 -0
  20. {gitlabds-2.0.0 → gitlabds-2.1.0}/gitlabds/missing_fill.py +0 -0
  21. {gitlabds-2.0.0 → gitlabds-2.1.0}/gitlabds/outliers.py +0 -0
  22. {gitlabds-2.0.0 → gitlabds-2.1.0}/gitlabds/split_data.py +0 -0
  23. {gitlabds-2.0.0 → gitlabds-2.1.0}/gitlabds.egg-info/dependency_links.txt +0 -0
  24. {gitlabds-2.0.0 → gitlabds-2.1.0}/gitlabds.egg-info/requires.txt +0 -0
  25. {gitlabds-2.0.0 → gitlabds-2.1.0}/gitlabds.egg-info/top_level.txt +0 -0
  26. {gitlabds-2.0.0 → gitlabds-2.1.0}/setup.cfg +0 -0
  27. {gitlabds-2.0.0 → gitlabds-2.1.0}/tests/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: gitlabds
3
- Version: 2.0.0
3
+ Version: 2.1.0
4
4
  Summary: Gitlab Data Science and Modeling Tools
5
5
  Home-page: https://gitlab.com/gitlab-data/gitlabds
6
6
  Author: Kevin Dietz
@@ -593,13 +593,12 @@ config.to_yaml("churn_model_config.yaml")
593
593
 
594
594
  ### Model Evaluation
595
595
 
596
- #### Comprehensive Evaluation
597
596
  <details><summary> ModelEvaluator </summary>
598
597
 
599
598
  #### Description
600
599
  A comprehensive framework for evaluating machine learning models, supporting both classification (binary and multi-class) and regression models. It provides extensive evaluation metrics, visualizations, and feature importance analysis.
601
600
 
602
- `gitlabds.ModelEvaluator(model, x_train, y_train, x_test, y_test, x_oot=None, y_oot=None, classification=True, algo=None, f_score=0.50, decile_n=10, top_features_n=20, show_all_classes=True, show_plots=True, save_plots=True, plot_dir='plots', plot_save_format='png', plot_save_dpi=300)`
601
+ `gitlabds.ModelEvaluator(model, x_train, y_train, x_test, y_test, x_oot=None, y_oot=None, classification=True, algo=None, f1_threshold=0.50, decile_n=10, top_features_n=20, show_all_classes=True, show_plots=True, save_plots=True, plot_dir='plots', plot_save_format='png', plot_save_dpi=300)`
603
602
 
604
603
  #### Parameters:
605
604
  - _**model**_ : The trained model to evaluate. Must have predict for regression and predict_proba method for classification
@@ -611,7 +610,7 @@ A comprehensive framework for evaluating machine learning models, supporting bot
611
610
  - _**y_oot**_ : Optional out-of-time validation labels.
612
611
  - _**classification**_ : Whether this is a classification model. If False, regression metrics will be used.
613
612
  - _**algo**_ : Algorithm type for feature importance calculation. Options: 'xgb', 'rf', 'mars'. For other algorithms, use `None`
614
- - _**f_score**_ : Threshold for binary classification.
613
+ - _**f1_threshold**_ : Threshold for binary classification.
615
614
  - _**decile_n**_ : Number of n-tiles for lift calculation. Defaults to 10 for deciles
616
615
  - _**top_features_n**_ : Number of top features to display in visualizations.
617
616
  - _**show_all_classes**_ : Whether to show metrics for all classes in multi-class classification.
@@ -674,58 +673,8 @@ results.feature_importance.to_csv("feature_importance.csv")
674
673
  ```
675
674
  </details>
676
675
 
677
- #### Metric Functions
678
- <details><summary> Model Metrics </summary>
679
676
 
680
- #### Description
681
- Display a variety of model metrics for linear and logistic predictive models.
682
-
683
- `gitlabds.model_metrics(model, x_train, y_train, x_test, y_test, show_graphs=True, f_score=0.50, classification=True, algo=None, decile_n=10, top_features_n=20):`
684
-
685
- #### Parameters:
686
- - _**model**_ : model file from training
687
- - _**x_train**_ : Training features DataFrame.
688
- - _**y_train**_ : Training labels (Series or DataFrame).
689
- - _**x_test**_ : Test features DataFrame.
690
- - _**y_test**_ : Test labels (Series or DataFrame).
691
- - _**show_graphs**_ : Whether to display plots and graphs.
692
- - _**f_score**_ : Threshold for binary classification.
693
- - _**classification**_ : Whether this is a classification model. If False, regression metrics will be used.
694
- - _**algo**_ : Algorithm type for feature importance calculation. Options: 'xgb', 'rf', 'mars'.
695
- - _**decile_n**_ : Number of n-tiles for lift calculation.
696
- - _**top_features_n**_ : Number of top features to display in feature importance.
697
-
698
- #### Returns
699
- - For classification models: tuple of (metricx, lift, classification_metricx, top_features, decile_breaks)
700
- - For regression models: tuple of (metricx, top_features)
701
-
702
- #### Examples:
703
- ```python
704
- # For a classification model
705
- import gitlabds
706
- metricx, lift, classification_metricx, top_features, decile_breaks = gitlabds.model_metrics(
707
- model=my_classifier,
708
- x_train=x_train,
709
- y_train=y_train,
710
- x_test=x_test,
711
- y_test=y_test,
712
- classification=True,
713
- algo='xgb'
714
- )
715
-
716
- # For a regression model
717
- metricx, top_features = gitlabds.model_metrics(
718
- model=my_regressor,
719
- x_train=x_train,
720
- y_train=y_train,
721
- x_test=x_test,
722
- y_test=y_test,
723
- classification=False
724
- )
725
- ```
726
- </details>
727
-
728
- #### Insight Generation
677
+ ### Insight Generation
729
678
  <details><summary> Marginal Effects </summary>
730
679
 
731
680
  #### Description
@@ -808,9 +757,150 @@ results = gitlabds.prescriptions(
808
757
  ```
809
758
  </details>
810
759
 
760
+ ### Model Monitoring
761
+
762
+ <details><summary> Generate Baseline Features </summary>
763
+
764
+ #### Description
765
+ Generate baseline feature distributions, importance scores, and drift thresholds in a single comprehensive artifact for model monitoring.
766
+
767
+ `gitlabds.generate_baseline_features(training_data, feature_importance_df, importance_method="shapley_values", n_bins=10, psi_warning=0.1, psi_critical=0.2, ks_warning=0.1, ks_critical=0.2, js_warning=0.05, js_critical=0.1, output_path="baseline_features.json"):`
768
+
769
+ #### Parameters:
770
+ - **_training_data_** : Training feature data DataFrame
771
+ - **_feature_importance_df_** : DataFrame with columns: feature, importance
772
+ - **_importance_method_** : Method used to calculate importance (default: "shapley_values")
773
+ - **_n_bins_** : Number of bins for numerical features (default: 10)
774
+ - **_psi_warning, psi_critical_** : PSI thresholds for warning and critical drift detection
775
+ - **_ks_warning, ks_critical_** : KS statistic thresholds for warning and critical drift detection
776
+ - **_js_warning, js_critical_** : JS divergence thresholds for warning and critical drift detection
777
+ - **_output_path_** : Path to save the JSON file
778
+
779
+ #### Returns
780
+ - None (saves baseline artifact to JSON file)
781
+
782
+ #### Examples:
783
+ ```python
784
+ # Generate baseline features with default thresholds
785
+ import gitlabds
786
+ gitlabds.generate_baseline_features(
787
+ training_data=train_df,
788
+ feature_importance_df=importance_df,
789
+ importance_method="shapley_values",
790
+ output_path="model_baseline_features.json"
791
+ )
792
+ ```
793
+
794
+ ```python
795
+ # Generate with custom drift thresholds
796
+ gitlabds.generate_baseline_features(
797
+ training_data=train_df,
798
+ feature_importance_df=importance_df,
799
+ n_bins=15,
800
+ psi_warning=0.15,
801
+ psi_critical=0.25,
802
+ output_path="custom_baseline_features.json"
803
+ )
804
+ ```
805
+ </details>
806
+
807
+ <details><summary> Generate Baseline Calibration </summary>
808
+
809
+ #### Description
810
+ Generate baseline calibration data with train + test curves, prediction statistics, and model configuration for monitoring model calibration drift.
811
+
812
+ `gitlabds.generate_baseline_calibration(train_predictions, train_actuals, test_predictions, test_actuals, model_configuration, n_bins=10, output_path="baseline_calibration.json"):`
813
+
814
+ #### Parameters:
815
+ - **_train_predictions_** : Training set predicted probabilities
816
+ - **_train_actuals_** : Training set actual binary outcomes (0/1)
817
+ - **_test_predictions_** : Test set predicted probabilities
818
+ - **_test_actuals_** : Test set actual binary outcomes (0/1)
819
+ - **_model_configuration_** : Dictionary of model configuration parameters
820
+ - **_n_bins_** : Number of bins for calibration curve (default: 10)
821
+ - **_output_path_** : Path to save the JSON file
822
+
823
+ #### Returns
824
+ - None (saves baseline calibration to JSON file)
825
+
826
+ #### Examples:
827
+ ```python
828
+ # Generate baseline calibration
829
+ import gitlabds
830
+ model_config = {'f1_threshold': 0.15, 'random_state': 42}
831
+
832
+ gitlabds.generate_baseline_calibration(
833
+ train_predictions=y_train_pred,
834
+ train_actuals=y_train,
835
+ test_predictions=y_test_pred,
836
+ test_actuals=y_test,
837
+ model_configuration=model_config,
838
+ output_path="model_baseline_calibration.json"
839
+ )
840
+ ```
841
+ </details>
842
+
843
+ <details><summary> Calculate Monitoring Metrics </summary>
844
+
845
+ #### Description
846
+ Calculate all monitoring metrics including feature drift, prediction drift, and health status for a model scoring run.
847
+
848
+ `gitlabds.calculate_monitoring_metrics(run_id, model_name, sub_model, model_version, scoring_date, feature_df, predictions, baseline_metrics, importance_threshold_pct=0.05):`
849
+
850
+ #### Parameters:
851
+ - **_run_id_** : Unique identifier for this scoring run
852
+ - **_model_name_** : Model name (e.g., "propensity_model")
853
+ - **_sub_model_** : Sub model identifier
854
+ - **_model_version_** : Model version (e.g., "2.1")
855
+ - **_scoring_date_** : Date of scoring
856
+ - **_feature_df_** : Feature data used for scoring
857
+ - **_predictions_** : Model predictions (probabilities 0-1)
858
+ - **_baseline_metrics_** : Dictionary containing baseline_features and baseline_calibration JSON data
859
+ - **_importance_threshold_pct_** : Percentage of total importance required for a feature to be considered "important"
860
+
861
+ #### Returns
862
+ - Dictionary containing DataFrames for each table:
863
+ - 'scoring_summary': model_scoring_summary table
864
+ - 'feature_drift': model_feature_drift table
865
+
866
+ #### Examples:
867
+ ```python
868
+ # Calculate monitoring metrics for a scoring run
869
+ import gitlabds
870
+ from datetime import datetime
871
+
872
+ # Load baseline metrics
873
+ with open('baseline_features.json', 'r') as f:
874
+ baseline_features = json.load(f)
875
+ with open('baseline_calibration.json', 'r') as f:
876
+ baseline_calibration = json.load(f)
877
+
878
+ baseline_metrics = {
879
+ 'baseline_features': baseline_features,
880
+ 'baseline_calibration': baseline_calibration
881
+ }
882
+
883
+ # Calculate metrics
884
+ results = gitlabds.calculate_monitoring_metrics(
885
+ run_id="scoring_run_123",
886
+ model_name="churn_prediction",
887
+ sub_model="high_value_customers",
888
+ model_version="2.1",
889
+ scoring_date=datetime.now(),
890
+ feature_df=current_features,
891
+ predictions=model_predictions,
892
+ baseline_metrics=baseline_metrics,
893
+ importance_threshold_pct=0.05
894
+ )
895
+
896
+ # Access results
897
+ scoring_summary = results['scoring_summary']
898
+ feature_drift = results['feature_drift']
899
+ ```
900
+ </details>
901
+
811
902
  ### SQL and Trend Analysis
812
903
 
813
- #### SQL Generation
814
904
  <details><summary> SQL Trend Query Generator </summary>
815
905
 
816
906
  #### Description
@@ -884,7 +974,6 @@ sql = gitlabds.generate_sql_trend_query(
884
974
  ```
885
975
  </details>
886
976
 
887
- #### Trend Analysis
888
977
  <details><summary> Trend Analysis </summary>
889
978
 
890
979
  #### Description
@@ -573,13 +573,12 @@ config.to_yaml("churn_model_config.yaml")
573
573
 
574
574
  ### Model Evaluation
575
575
 
576
- #### Comprehensive Evaluation
577
576
  <details><summary> ModelEvaluator </summary>
578
577
 
579
578
  #### Description
580
579
  A comprehensive framework for evaluating machine learning models, supporting both classification (binary and multi-class) and regression models. It provides extensive evaluation metrics, visualizations, and feature importance analysis.
581
580
 
582
- `gitlabds.ModelEvaluator(model, x_train, y_train, x_test, y_test, x_oot=None, y_oot=None, classification=True, algo=None, f_score=0.50, decile_n=10, top_features_n=20, show_all_classes=True, show_plots=True, save_plots=True, plot_dir='plots', plot_save_format='png', plot_save_dpi=300)`
581
+ `gitlabds.ModelEvaluator(model, x_train, y_train, x_test, y_test, x_oot=None, y_oot=None, classification=True, algo=None, f1_threshold=0.50, decile_n=10, top_features_n=20, show_all_classes=True, show_plots=True, save_plots=True, plot_dir='plots', plot_save_format='png', plot_save_dpi=300)`
583
582
 
584
583
  #### Parameters:
585
584
  - _**model**_ : The trained model to evaluate. Must have predict for regression and predict_proba method for classification
@@ -591,7 +590,7 @@ A comprehensive framework for evaluating machine learning models, supporting bot
591
590
  - _**y_oot**_ : Optional out-of-time validation labels.
592
591
  - _**classification**_ : Whether this is a classification model. If False, regression metrics will be used.
593
592
  - _**algo**_ : Algorithm type for feature importance calculation. Options: 'xgb', 'rf', 'mars'. For other algorithms, use `None`
594
- - _**f_score**_ : Threshold for binary classification.
593
+ - _**f1_threshold**_ : Threshold for binary classification.
595
594
  - _**decile_n**_ : Number of n-tiles for lift calculation. Defaults to 10 for deciles
596
595
  - _**top_features_n**_ : Number of top features to display in visualizations.
597
596
  - _**show_all_classes**_ : Whether to show metrics for all classes in multi-class classification.
@@ -654,58 +653,8 @@ results.feature_importance.to_csv("feature_importance.csv")
654
653
  ```
655
654
  </details>
656
655
 
657
- #### Metric Functions
658
- <details><summary> Model Metrics </summary>
659
656
 
660
- #### Description
661
- Display a variety of model metrics for linear and logistic predictive models.
662
-
663
- `gitlabds.model_metrics(model, x_train, y_train, x_test, y_test, show_graphs=True, f_score=0.50, classification=True, algo=None, decile_n=10, top_features_n=20):`
664
-
665
- #### Parameters:
666
- - _**model**_ : model file from training
667
- - _**x_train**_ : Training features DataFrame.
668
- - _**y_train**_ : Training labels (Series or DataFrame).
669
- - _**x_test**_ : Test features DataFrame.
670
- - _**y_test**_ : Test labels (Series or DataFrame).
671
- - _**show_graphs**_ : Whether to display plots and graphs.
672
- - _**f_score**_ : Threshold for binary classification.
673
- - _**classification**_ : Whether this is a classification model. If False, regression metrics will be used.
674
- - _**algo**_ : Algorithm type for feature importance calculation. Options: 'xgb', 'rf', 'mars'.
675
- - _**decile_n**_ : Number of n-tiles for lift calculation.
676
- - _**top_features_n**_ : Number of top features to display in feature importance.
677
-
678
- #### Returns
679
- - For classification models: tuple of (metricx, lift, classification_metricx, top_features, decile_breaks)
680
- - For regression models: tuple of (metricx, top_features)
681
-
682
- #### Examples:
683
- ```python
684
- # For a classification model
685
- import gitlabds
686
- metricx, lift, classification_metricx, top_features, decile_breaks = gitlabds.model_metrics(
687
- model=my_classifier,
688
- x_train=x_train,
689
- y_train=y_train,
690
- x_test=x_test,
691
- y_test=y_test,
692
- classification=True,
693
- algo='xgb'
694
- )
695
-
696
- # For a regression model
697
- metricx, top_features = gitlabds.model_metrics(
698
- model=my_regressor,
699
- x_train=x_train,
700
- y_train=y_train,
701
- x_test=x_test,
702
- y_test=y_test,
703
- classification=False
704
- )
705
- ```
706
- </details>
707
-
708
- #### Insight Generation
657
+ ### Insight Generation
709
658
  <details><summary> Marginal Effects </summary>
710
659
 
711
660
  #### Description
@@ -788,9 +737,150 @@ results = gitlabds.prescriptions(
788
737
  ```
789
738
  </details>
790
739
 
740
+ ### Model Monitoring
741
+
742
+ <details><summary> Generate Baseline Features </summary>
743
+
744
+ #### Description
745
+ Generate baseline feature distributions, importance scores, and drift thresholds in a single comprehensive artifact for model monitoring.
746
+
747
+ `gitlabds.generate_baseline_features(training_data, feature_importance_df, importance_method="shapley_values", n_bins=10, psi_warning=0.1, psi_critical=0.2, ks_warning=0.1, ks_critical=0.2, js_warning=0.05, js_critical=0.1, output_path="baseline_features.json"):`
748
+
749
+ #### Parameters:
750
+ - **_training_data_** : Training feature data DataFrame
751
+ - **_feature_importance_df_** : DataFrame with columns: feature, importance
752
+ - **_importance_method_** : Method used to calculate importance (default: "shapley_values")
753
+ - **_n_bins_** : Number of bins for numerical features (default: 10)
754
+ - **_psi_warning, psi_critical_** : PSI thresholds for warning and critical drift detection
755
+ - **_ks_warning, ks_critical_** : KS statistic thresholds for warning and critical drift detection
756
+ - **_js_warning, js_critical_** : JS divergence thresholds for warning and critical drift detection
757
+ - **_output_path_** : Path to save the JSON file
758
+
759
+ #### Returns
760
+ - None (saves baseline artifact to JSON file)
761
+
762
+ #### Examples:
763
+ ```python
764
+ # Generate baseline features with default thresholds
765
+ import gitlabds
766
+ gitlabds.generate_baseline_features(
767
+ training_data=train_df,
768
+ feature_importance_df=importance_df,
769
+ importance_method="shapley_values",
770
+ output_path="model_baseline_features.json"
771
+ )
772
+ ```
773
+
774
+ ```python
775
+ # Generate with custom drift thresholds
776
+ gitlabds.generate_baseline_features(
777
+ training_data=train_df,
778
+ feature_importance_df=importance_df,
779
+ n_bins=15,
780
+ psi_warning=0.15,
781
+ psi_critical=0.25,
782
+ output_path="custom_baseline_features.json"
783
+ )
784
+ ```
785
+ </details>
786
+
787
+ <details><summary> Generate Baseline Calibration </summary>
788
+
789
+ #### Description
790
+ Generate baseline calibration data with train + test curves, prediction statistics, and model configuration for monitoring model calibration drift.
791
+
792
+ `gitlabds.generate_baseline_calibration(train_predictions, train_actuals, test_predictions, test_actuals, model_configuration, n_bins=10, output_path="baseline_calibration.json"):`
793
+
794
+ #### Parameters:
795
+ - **_train_predictions_** : Training set predicted probabilities
796
+ - **_train_actuals_** : Training set actual binary outcomes (0/1)
797
+ - **_test_predictions_** : Test set predicted probabilities
798
+ - **_test_actuals_** : Test set actual binary outcomes (0/1)
799
+ - **_model_configuration_** : Dictionary of model configuration parameters
800
+ - **_n_bins_** : Number of bins for calibration curve (default: 10)
801
+ - **_output_path_** : Path to save the JSON file
802
+
803
+ #### Returns
804
+ - None (saves baseline calibration to JSON file)
805
+
806
+ #### Examples:
807
+ ```python
808
+ # Generate baseline calibration
809
+ import gitlabds
810
+ model_config = {'f1_threshold': 0.15, 'random_state': 42}
811
+
812
+ gitlabds.generate_baseline_calibration(
813
+ train_predictions=y_train_pred,
814
+ train_actuals=y_train,
815
+ test_predictions=y_test_pred,
816
+ test_actuals=y_test,
817
+ model_configuration=model_config,
818
+ output_path="model_baseline_calibration.json"
819
+ )
820
+ ```
821
+ </details>
822
+
823
+ <details><summary> Calculate Monitoring Metrics </summary>
824
+
825
+ #### Description
826
+ Calculate all monitoring metrics including feature drift, prediction drift, and health status for a model scoring run.
827
+
828
+ `gitlabds.calculate_monitoring_metrics(run_id, model_name, sub_model, model_version, scoring_date, feature_df, predictions, baseline_metrics, importance_threshold_pct=0.05):`
829
+
830
+ #### Parameters:
831
+ - **_run_id_** : Unique identifier for this scoring run
832
+ - **_model_name_** : Model name (e.g., "propensity_model")
833
+ - **_sub_model_** : Sub model identifier
834
+ - **_model_version_** : Model version (e.g., "2.1")
835
+ - **_scoring_date_** : Date of scoring
836
+ - **_feature_df_** : Feature data used for scoring
837
+ - **_predictions_** : Model predictions (probabilities 0-1)
838
+ - **_baseline_metrics_** : Dictionary containing baseline_features and baseline_calibration JSON data
839
+ - **_importance_threshold_pct_** : Percentage of total importance required for a feature to be considered "important"
840
+
841
+ #### Returns
842
+ - Dictionary containing DataFrames for each table:
843
+ - 'scoring_summary': model_scoring_summary table
844
+ - 'feature_drift': model_feature_drift table
845
+
846
+ #### Examples:
847
+ ```python
848
+ # Calculate monitoring metrics for a scoring run
849
+ import gitlabds
850
+ from datetime import datetime
851
+
852
+ # Load baseline metrics
853
+ with open('baseline_features.json', 'r') as f:
854
+ baseline_features = json.load(f)
855
+ with open('baseline_calibration.json', 'r') as f:
856
+ baseline_calibration = json.load(f)
857
+
858
+ baseline_metrics = {
859
+ 'baseline_features': baseline_features,
860
+ 'baseline_calibration': baseline_calibration
861
+ }
862
+
863
+ # Calculate metrics
864
+ results = gitlabds.calculate_monitoring_metrics(
865
+ run_id="scoring_run_123",
866
+ model_name="churn_prediction",
867
+ sub_model="high_value_customers",
868
+ model_version="2.1",
869
+ scoring_date=datetime.now(),
870
+ feature_df=current_features,
871
+ predictions=model_predictions,
872
+ baseline_metrics=baseline_metrics,
873
+ importance_threshold_pct=0.05
874
+ )
875
+
876
+ # Access results
877
+ scoring_summary = results['scoring_summary']
878
+ feature_drift = results['feature_drift']
879
+ ```
880
+ </details>
881
+
791
882
  ### SQL and Trend Analysis
792
883
 
793
- #### SQL Generation
794
884
  <details><summary> SQL Trend Query Generator </summary>
795
885
 
796
886
  #### Description
@@ -864,7 +954,6 @@ sql = gitlabds.generate_sql_trend_query(
864
954
  ```
865
955
  </details>
866
956
 
867
- #### Trend Analysis
868
957
  <details><summary> Trend Analysis </summary>
869
958
 
870
959
  #### Description
@@ -1,3 +1,4 @@
1
+ from .baselines import generate_baseline_features, generate_baseline_calibration
1
2
  from .config_generator import ConfigGenerator
2
3
  from .dummy import dummy_code, dummy_top, apply_dummy
3
4
  from .feature_reduction import drop_categorical, remove_low_variation, remove_outcome_proxies, correlation_reduction
@@ -5,7 +6,7 @@ from .insights import marginal_effects, prescriptions
5
6
  from .memory_optimization import reduce_memory_usage, sparse_encode_df, identify_categorical_candidates, compact_categorical, memory_profile_df, memory_optimization
6
7
  from .missing import missing_values, apply_missing_values
7
8
  from .model_evaluator import ModelEvaluator
8
- from .model_metrics import model_metrics
9
+ from .monitoring_metrics import calculate_monitoring_metrics, calculate_baseline_prediction_distribution, calculate_prediction_distribution, calculate_distribution_shift, calculate_psi_numerical, calculate_psi_categorical
9
10
  from .outliers import mad_outliers, apply_outliers
10
11
  from .split_data import split_data
11
12
  from .trends import generate_sql_trend_query, trend_analysis