towardsinnovationlab commited on
Commit
761ba72
·
verified ·
1 Parent(s): a4c501d

Update pages/LLM_Trial_1.py

Browse files
Files changed (1) hide show
  1. pages/LLM_Trial_1.py +3 -42
pages/LLM_Trial_1.py CHANGED
@@ -386,7 +386,6 @@ inconsistent_records = new_samples_df[
386
  st.write(f"Number of inconsistent records on synthetic data: {len(inconsistent_records)}")
387
  st.write(inconsistent_records.head()) # Show a few inconsistent rows
388
  st.write('Helps assess basic data fidelity by checking structural or logical violations.')
389
- #st.write('The generative model successfully learned the essential business logic')
390
 
391
 
392
  # ### Visual Comparison
@@ -394,9 +393,6 @@ st.write('Helps assess basic data fidelity by checking structural or logical vio
394
  # Compare selected variables using histograms
395
  st.subheader(f"Univariate distribution comparison: real vs synthetic")
396
  st.write('Shows how well each individual feature is mimicked by the synthetic data.')
397
- #st.write('The model captures variables like Exposure, VehValue, ClaimAmount, ClaimOcc, and \
398
- #ClaimNb reasonably well, showing similar overall shapes and ranges. Meanwhile for the others \
399
- #show a poor replication.')
400
 
401
  compare_real_vs_synthetic(
402
  real_df=X_train,
@@ -408,8 +404,6 @@ compare_real_vs_synthetic(
408
 
409
  st.subheader(f"Correlation matrix comparison: real vs synthetic")
410
  st.write('Evaluates preservation of feature-to-feature relationships.')
411
- #st.write('Overall the correlation structure is well-preserved, indicating this synthetic data \
412
- #generation method maintains feature relationships effectively')
413
 
414
  # Compute correlation matrices
415
  corr_matrix_X_train = X_train.corr()
@@ -441,8 +435,6 @@ st.pyplot(fig)
441
  # Kolmogorov-Smirnov test
442
  st.subheader("Kolmogorov–Smirnov Test Results")
443
  st.write('Quantifies the statistical distance between real and synthetic distributions.')
444
- #st.write('Five variables (VehAge, VehBody, Gender, ClaimOcc, ClaimNb) pass the KS test \
445
- #with p ≥ 0.05, demonstrating good distributional similarity.')
446
 
447
  results = []
448
 
@@ -478,9 +470,6 @@ st.dataframe(styled_df)
478
 
479
  st.subheader('PCA comparison')
480
  st.write('Assesses similarity in global variance structure and major latent components.')
481
- #st.write('The synthetic data points substantially overlap with the real data in the principal component space, \
482
- #indicating the synthetic generation method successfully captures the main variance structure and multivariate \
483
- #relationships present in the original dataset.')
484
  # Load the saved models
485
  img = mpimg.imread('./LLM/pca_d1_80.png')
486
  fig=plt.figure(figsize=(10, 8))
@@ -494,10 +483,6 @@ st.pyplot(fig)
494
 
495
  st.subheader('UMAP comparison')
496
  st.write('Examines nonlinear manifold structure and clustering behavior.')
497
- #st.write('This visualization shows a strong co-location across all three dimensions \
498
- #indicating the synthetic data successfully captures the complex, high-dimensional structure \
499
- #of the real data, preserving both local neighborhoods and global manifold geometry essential \
500
- #for downstream modeling tasks.')
501
  img = mpimg.imread('./LLM/umap_d1_80.png')
502
  fig=plt.figure(figsize=(10, 8))
503
  plt.imshow(img)
@@ -525,9 +510,6 @@ results_cost_2 = run_glm_cost_analysis(new_samples_df, X_test, is_sampled=True,v
525
  # --- SHAP Feature Importance for Frequency ---
526
  st.subheader('SHAP Feature Importance for Frequency Model')
527
  st.write('Shows whether drivers of frequency predictions remain consistent across datasets.')
528
- #st.write('This SHAP analysis reveals good model consistency: ClaimOcc (claim occurrence) dominates feature importance \
529
- #in both real and synthetic datasets, suggesting the model has learned stable, meaningful patterns. However, the relative \
530
- #importance of VehBody increases substantially in synthetic data compared to real data.')
531
  # Prepare data for frequency model SHAP
532
  X_train_freq = X_train.drop(['Exposure', 'ClaimNb', 'ClaimAmount'], axis=1, errors='ignore')
533
  y_train_freq = X_train['ClaimNb']
@@ -590,8 +572,7 @@ plot_glm_shap_importance(
590
  # --- SHAP Feature Importance for Severity ---
591
  st.subheader('SHAP Feature Importance for Severity Model')
592
  st.write('Assesses stability of model explanations for severity outcomes.')
593
- #st.write('The severity model shows concerning instability between real and synthetic data: \
594
- #the top features completely flip, with VehBody most important on real data but VehValue dominating synthetic data.')
595
  # Prepare data for severity model SHAP
596
  X_train_cost_prep = X_train[X_train['ClaimAmount'] != 0].copy()
597
  X_test_cost_prep = X_test[X_test['ClaimAmount'] != 0].copy()
@@ -720,14 +701,11 @@ inconsistent_records = new_samples_df[
720
  st.write(f"Number of inconsistent records on synthetic data: {len(inconsistent_records)}")
721
  st.write(inconsistent_records.head()) # Show a few inconsistent rows
722
  st.write('Helps assess basic data fidelity by checking structural or logical violations.')
723
- #st.write('The generative model replaced the business patterns in a right way')
724
 
725
 
726
  # ### Visual Comparison
727
  st.subheader('Univariate distribution comparison: real vs synthetic')
728
  st.write('Shows how well each individual feature is mimicked by the synthetic data.')
729
- #st.write('The model captures variables like ClaimAmount, ClaimOcc, ClaimNb and Gender in a good manner. \
730
- #Meanwhile fails for the others.')
731
 
732
  # Compare selected variables using histograms
733
  compare_real_vs_synthetic(
@@ -739,8 +717,6 @@ compare_real_vs_synthetic(
739
 
740
  st.subheader('Correlation matrix comparison: real vs synthetic')
741
  st.write('Evaluates preservation of feature-to-feature relationships.')
742
- #st.write('The synthetic data nearly perfectly replicates the correlation structure, with identical \
743
- #values across almost all variable pairs.')
744
 
745
  # Compute correlation matrices
746
  corr_matrix_X_train = X_train.corr()
@@ -773,9 +749,6 @@ st.pyplot(fig)
773
  # Kolmogorov-Smirnov test
774
  st.subheader('Kolmogorov–Smirnov Test Results')
775
  st.write('Quantifies the statistical distance between real and synthetic distributions.')
776
- #st.write('Only four variables (Gender, ClaimNb, ClaimAmount, ClaimOcc) pass the KS test achieving \
777
- #a perfect p = 1.0000 or close to it, but these successes are primarily on claim-related variables \
778
- #while demographic and policy features are poorly reproduced.')
779
 
780
 
781
  results = []
@@ -811,11 +784,6 @@ st.dataframe(styled_df)
811
  # ### PCA Analysis
812
  st.subheader('PCA comparison')
813
  st.write('Assesses similarity in global variance structure and major latent components.')
814
- #st.write('The synthetic points exhibit nearly identical spread, density, and boundary \
815
- #characteristics as the real data, with minimal outliers and no visible systematic shifts.')
816
- # Load the saved models
817
- #scaler = load('./LLM/scaler_pca_model_d2_llm_80.pkl')
818
- #pca = load('./LLM/pca_model_d2_llm_80.pkl')
819
 
820
  img = mpimg.imread('./LLM/pca_d2_80.png')
821
  fig=plt.figure(figsize=(10, 8))
@@ -827,9 +795,6 @@ st.pyplot(fig)
827
  # ### UMAP Analysis
828
  st.subheader('UMAP comparison')
829
  st.write('Examines nonlinear manifold structure and clustering behavior.')
830
- #st.write('The plot shows that synthetic points (red) closely overlap the real data (blue), \
831
- #indicating the generative process preserves the global structure of the feature space. \
832
- #Minor deviations appear at the edges, but overall the synthetic dataset replicates key clusters well.')
833
  img = mpimg.imread('./LLM/umap_d2_80.png')
834
  fig=plt.figure(figsize=(10, 8))
835
  plt.imshow(img)
@@ -858,9 +823,7 @@ results_cost_4 = run_glm_cost_analysis(new_samples_df, X_test, is_sampled=True,
858
  # --- SHAP Feature Importance for Frequency ---
859
  st.subheader('SHAP Feature Importance for Frequency Model')
860
  st.write('Shows whether drivers of frequency predictions remain consistent across datasets.')
861
- #st.write('The frequency model demonstrates excellent stability across real and synthetic datasets: \
862
- #both show OwnerAge as the dominant predictor followed by VehAge, with nearly identical feature importance \
863
- #rankings and similar magnitude patterns.')
864
  # Prepare data for frequency model SHAP
865
  X_train_freq = X_train.drop(['Exposure', 'ClaimNb', 'ClaimAmount'], axis=1, errors='ignore')
866
  y_train_freq = X_train['ClaimNb']
@@ -923,9 +886,7 @@ plot_glm_shap_importance(
923
  # --- SHAP Feature Importance for Severity ---
924
  st.subheader('SHAP Feature Importance for Severity Model')
925
  st.write('Assesses stability of model explanations for severity outcomes')
926
- #st.write('The severity model shows strong consistency between real and synthetic data: \
927
- #VehAge clearly dominates as the primary driver in both datasets, followed by OwnerAge \
928
- #as a distant second.')
929
  # Prepare data for severity model SHAP
930
  X_train_cost_prep = X_train[X_train['ClaimAmount'] != 0].copy()
931
  X_test_cost_prep = X_test[X_test['ClaimAmount'] != 0].copy()
 
386
  st.write(f"Number of inconsistent records on synthetic data: {len(inconsistent_records)}")
387
  st.write(inconsistent_records.head()) # Show a few inconsistent rows
388
  st.write('Helps assess basic data fidelity by checking structural or logical violations.')
 
389
 
390
 
391
  # ### Visual Comparison
 
393
  # Compare selected variables using histograms
394
  st.subheader(f"Univariate distribution comparison: real vs synthetic")
395
  st.write('Shows how well each individual feature is mimicked by the synthetic data.')
 
 
 
396
 
397
  compare_real_vs_synthetic(
398
  real_df=X_train,
 
404
 
405
  st.subheader(f"Correlation matrix comparison: real vs synthetic")
406
  st.write('Evaluates preservation of feature-to-feature relationships.')
 
 
407
 
408
  # Compute correlation matrices
409
  corr_matrix_X_train = X_train.corr()
 
435
  # Kolmogorov-Smirnov test
436
  st.subheader("Kolmogorov–Smirnov Test Results")
437
  st.write('Quantifies the statistical distance between real and synthetic distributions.')
 
 
438
 
439
  results = []
440
 
 
470
 
471
  st.subheader('PCA comparison')
472
  st.write('Assesses similarity in global variance structure and major latent components.')
 
 
 
473
  # Load the saved models
474
  img = mpimg.imread('./LLM/pca_d1_80.png')
475
  fig=plt.figure(figsize=(10, 8))
 
483
 
484
  st.subheader('UMAP comparison')
485
  st.write('Examines nonlinear manifold structure and clustering behavior.')
 
 
 
 
486
  img = mpimg.imread('./LLM/umap_d1_80.png')
487
  fig=plt.figure(figsize=(10, 8))
488
  plt.imshow(img)
 
510
  # --- SHAP Feature Importance for Frequency ---
511
  st.subheader('SHAP Feature Importance for Frequency Model')
512
  st.write('Shows whether drivers of frequency predictions remain consistent across datasets.')
 
 
 
513
  # Prepare data for frequency model SHAP
514
  X_train_freq = X_train.drop(['Exposure', 'ClaimNb', 'ClaimAmount'], axis=1, errors='ignore')
515
  y_train_freq = X_train['ClaimNb']
 
572
  # --- SHAP Feature Importance for Severity ---
573
  st.subheader('SHAP Feature Importance for Severity Model')
574
  st.write('Assesses stability of model explanations for severity outcomes.')
575
+
 
576
  # Prepare data for severity model SHAP
577
  X_train_cost_prep = X_train[X_train['ClaimAmount'] != 0].copy()
578
  X_test_cost_prep = X_test[X_test['ClaimAmount'] != 0].copy()
 
701
  st.write(f"Number of inconsistent records on synthetic data: {len(inconsistent_records)}")
702
  st.write(inconsistent_records.head()) # Show a few inconsistent rows
703
  st.write('Helps assess basic data fidelity by checking structural or logical violations.')
 
704
 
705
 
706
  # ### Visual Comparison
707
  st.subheader('Univariate distribution comparison: real vs synthetic')
708
  st.write('Shows how well each individual feature is mimicked by the synthetic data.')
 
 
709
 
710
  # Compare selected variables using histograms
711
  compare_real_vs_synthetic(
 
717
 
718
  st.subheader('Correlation matrix comparison: real vs synthetic')
719
  st.write('Evaluates preservation of feature-to-feature relationships.')
 
 
720
 
721
  # Compute correlation matrices
722
  corr_matrix_X_train = X_train.corr()
 
749
  # Kolmogorov-Smirnov test
750
  st.subheader('Kolmogorov–Smirnov Test Results')
751
  st.write('Quantifies the statistical distance between real and synthetic distributions.')
 
 
 
752
 
753
 
754
  results = []
 
784
  # ### PCA Analysis
785
  st.subheader('PCA comparison')
786
  st.write('Assesses similarity in global variance structure and major latent components.')
 
 
 
 
 
787
 
788
  img = mpimg.imread('./LLM/pca_d2_80.png')
789
  fig=plt.figure(figsize=(10, 8))
 
795
  # ### UMAP Analysis
796
  st.subheader('UMAP comparison')
797
  st.write('Examines nonlinear manifold structure and clustering behavior.')
 
 
 
798
  img = mpimg.imread('./LLM/umap_d2_80.png')
799
  fig=plt.figure(figsize=(10, 8))
800
  plt.imshow(img)
 
823
  # --- SHAP Feature Importance for Frequency ---
824
  st.subheader('SHAP Feature Importance for Frequency Model')
825
  st.write('Shows whether drivers of frequency predictions remain consistent across datasets.')
826
+
 
 
827
  # Prepare data for frequency model SHAP
828
  X_train_freq = X_train.drop(['Exposure', 'ClaimNb', 'ClaimAmount'], axis=1, errors='ignore')
829
  y_train_freq = X_train['ClaimNb']
 
886
  # --- SHAP Feature Importance for Severity ---
887
  st.subheader('SHAP Feature Importance for Severity Model')
888
  st.write('Assesses stability of model explanations for severity outcomes')
889
+
 
 
890
  # Prepare data for severity model SHAP
891
  X_train_cost_prep = X_train[X_train['ClaimAmount'] != 0].copy()
892
  X_test_cost_prep = X_test[X_test['ClaimAmount'] != 0].copy()