validmind 2.7.12__py3-none-any.whl → 2.8.12__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.
Files changed (163) hide show
  1. validmind/__init__.py +58 -10
  2. validmind/__version__.py +1 -1
  3. validmind/ai/test_descriptions.py +17 -73
  4. validmind/api_client.py +18 -1
  5. validmind/models/r_model.py +5 -1
  6. validmind/tests/comparison.py +28 -2
  7. validmind/tests/data_validation/ACFandPACFPlot.py +4 -1
  8. validmind/tests/data_validation/AutoMA.py +1 -1
  9. validmind/tests/data_validation/BivariateScatterPlots.py +5 -1
  10. validmind/tests/data_validation/BoxPierce.py +3 -1
  11. validmind/tests/data_validation/ClassImbalance.py +1 -1
  12. validmind/tests/data_validation/DatasetDescription.py +1 -1
  13. validmind/tests/data_validation/DickeyFullerGLS.py +1 -1
  14. validmind/tests/data_validation/FeatureTargetCorrelationPlot.py +5 -10
  15. validmind/tests/data_validation/HighCardinality.py +5 -1
  16. validmind/tests/data_validation/HighPearsonCorrelation.py +1 -1
  17. validmind/tests/data_validation/IQROutliersBarPlot.py +5 -3
  18. validmind/tests/data_validation/IQROutliersTable.py +5 -2
  19. validmind/tests/data_validation/IsolationForestOutliers.py +5 -4
  20. validmind/tests/data_validation/JarqueBera.py +2 -2
  21. validmind/tests/data_validation/LJungBox.py +2 -2
  22. validmind/tests/data_validation/LaggedCorrelationHeatmap.py +1 -1
  23. validmind/tests/data_validation/MissingValues.py +14 -10
  24. validmind/tests/data_validation/MissingValuesBarPlot.py +3 -1
  25. validmind/tests/data_validation/MutualInformation.py +2 -1
  26. validmind/tests/data_validation/PearsonCorrelationMatrix.py +1 -1
  27. validmind/tests/data_validation/ProtectedClassesCombination.py +2 -0
  28. validmind/tests/data_validation/ProtectedClassesDescription.py +2 -2
  29. validmind/tests/data_validation/ProtectedClassesDisparity.py +9 -5
  30. validmind/tests/data_validation/ProtectedClassesThresholdOptimizer.py +10 -2
  31. validmind/tests/data_validation/RollingStatsPlot.py +2 -1
  32. validmind/tests/data_validation/ScoreBandDefaultRates.py +4 -2
  33. validmind/tests/data_validation/SeasonalDecompose.py +1 -1
  34. validmind/tests/data_validation/ShapiroWilk.py +2 -2
  35. validmind/tests/data_validation/SpreadPlot.py +1 -1
  36. validmind/tests/data_validation/TabularCategoricalBarPlots.py +1 -1
  37. validmind/tests/data_validation/TabularDateTimeHistograms.py +1 -1
  38. validmind/tests/data_validation/TargetRateBarPlots.py +4 -1
  39. validmind/tests/data_validation/TimeSeriesFrequency.py +1 -1
  40. validmind/tests/data_validation/TimeSeriesOutliers.py +7 -2
  41. validmind/tests/data_validation/WOEBinPlots.py +1 -1
  42. validmind/tests/data_validation/WOEBinTable.py +1 -1
  43. validmind/tests/data_validation/ZivotAndrewsArch.py +5 -2
  44. validmind/tests/data_validation/nlp/CommonWords.py +1 -1
  45. validmind/tests/data_validation/nlp/Hashtags.py +1 -1
  46. validmind/tests/data_validation/nlp/LanguageDetection.py +1 -1
  47. validmind/tests/data_validation/nlp/Mentions.py +1 -1
  48. validmind/tests/data_validation/nlp/PolarityAndSubjectivity.py +5 -1
  49. validmind/tests/data_validation/nlp/Punctuations.py +1 -1
  50. validmind/tests/data_validation/nlp/Sentiment.py +3 -1
  51. validmind/tests/data_validation/nlp/TextDescription.py +1 -1
  52. validmind/tests/data_validation/nlp/Toxicity.py +1 -1
  53. validmind/tests/model_validation/BertScore.py +7 -1
  54. validmind/tests/model_validation/BleuScore.py +7 -1
  55. validmind/tests/model_validation/ClusterSizeDistribution.py +3 -1
  56. validmind/tests/model_validation/ContextualRecall.py +9 -1
  57. validmind/tests/model_validation/FeaturesAUC.py +1 -1
  58. validmind/tests/model_validation/MeteorScore.py +7 -1
  59. validmind/tests/model_validation/ModelPredictionResiduals.py +5 -1
  60. validmind/tests/model_validation/RegardScore.py +6 -1
  61. validmind/tests/model_validation/RegressionResidualsPlot.py +10 -1
  62. validmind/tests/model_validation/RougeScore.py +3 -1
  63. validmind/tests/model_validation/TimeSeriesPredictionWithCI.py +2 -0
  64. validmind/tests/model_validation/TimeSeriesPredictionsPlot.py +10 -2
  65. validmind/tests/model_validation/TimeSeriesR2SquareBySegments.py +6 -2
  66. validmind/tests/model_validation/TokenDisparity.py +5 -1
  67. validmind/tests/model_validation/ToxicityScore.py +3 -1
  68. validmind/tests/model_validation/embeddings/ClusterDistribution.py +1 -1
  69. validmind/tests/model_validation/embeddings/CosineSimilarityComparison.py +5 -1
  70. validmind/tests/model_validation/embeddings/CosineSimilarityDistribution.py +5 -1
  71. validmind/tests/model_validation/embeddings/CosineSimilarityHeatmap.py +5 -1
  72. validmind/tests/model_validation/embeddings/DescriptiveAnalytics.py +2 -0
  73. validmind/tests/model_validation/embeddings/EmbeddingsVisualization2D.py +5 -1
  74. validmind/tests/model_validation/embeddings/EuclideanDistanceComparison.py +6 -2
  75. validmind/tests/model_validation/embeddings/EuclideanDistanceHeatmap.py +3 -1
  76. validmind/tests/model_validation/embeddings/PCAComponentsPairwisePlots.py +4 -1
  77. validmind/tests/model_validation/embeddings/StabilityAnalysisKeyword.py +5 -1
  78. validmind/tests/model_validation/embeddings/StabilityAnalysisRandomNoise.py +5 -1
  79. validmind/tests/model_validation/embeddings/StabilityAnalysisSynonyms.py +5 -1
  80. validmind/tests/model_validation/embeddings/StabilityAnalysisTranslation.py +5 -1
  81. validmind/tests/model_validation/embeddings/TSNEComponentsPairwisePlots.py +6 -1
  82. validmind/tests/model_validation/embeddings/utils.py +6 -9
  83. validmind/tests/model_validation/ragas/AnswerCorrectness.py +1 -1
  84. validmind/tests/model_validation/ragas/AspectCritic.py +4 -1
  85. validmind/tests/model_validation/ragas/ContextEntityRecall.py +1 -1
  86. validmind/tests/model_validation/ragas/ContextPrecision.py +1 -1
  87. validmind/tests/model_validation/ragas/ContextPrecisionWithoutReference.py +1 -1
  88. validmind/tests/model_validation/ragas/ContextRecall.py +1 -1
  89. validmind/tests/model_validation/ragas/Faithfulness.py +1 -1
  90. validmind/tests/model_validation/ragas/NoiseSensitivity.py +1 -1
  91. validmind/tests/model_validation/ragas/ResponseRelevancy.py +1 -1
  92. validmind/tests/model_validation/ragas/SemanticSimilarity.py +1 -1
  93. validmind/tests/model_validation/ragas/utils.py +8 -7
  94. validmind/tests/model_validation/sklearn/AdjustedMutualInformation.py +9 -9
  95. validmind/tests/model_validation/sklearn/AdjustedRandIndex.py +9 -9
  96. validmind/tests/model_validation/sklearn/CalibrationCurve.py +5 -2
  97. validmind/tests/model_validation/sklearn/ClassifierThresholdOptimization.py +15 -2
  98. validmind/tests/model_validation/sklearn/ClusterCosineSimilarity.py +5 -1
  99. validmind/tests/model_validation/sklearn/ClusterPerformanceMetrics.py +24 -14
  100. validmind/tests/model_validation/sklearn/CompletenessScore.py +8 -9
  101. validmind/tests/model_validation/sklearn/ConfusionMatrix.py +22 -3
  102. validmind/tests/model_validation/sklearn/FeatureImportance.py +6 -2
  103. validmind/tests/model_validation/sklearn/FowlkesMallowsScore.py +12 -9
  104. validmind/tests/model_validation/sklearn/HomogeneityScore.py +14 -9
  105. validmind/tests/model_validation/sklearn/HyperParametersTuning.py +4 -2
  106. validmind/tests/model_validation/sklearn/KMeansClustersOptimization.py +6 -1
  107. validmind/tests/model_validation/sklearn/MinimumAccuracy.py +12 -7
  108. validmind/tests/model_validation/sklearn/MinimumF1Score.py +12 -7
  109. validmind/tests/model_validation/sklearn/MinimumROCAUCScore.py +18 -7
  110. validmind/tests/model_validation/sklearn/OverfitDiagnosis.py +8 -2
  111. validmind/tests/model_validation/sklearn/PermutationFeatureImportance.py +5 -1
  112. validmind/tests/model_validation/sklearn/PopulationStabilityIndex.py +5 -1
  113. validmind/tests/model_validation/sklearn/PrecisionRecallCurve.py +6 -1
  114. validmind/tests/model_validation/sklearn/ROCCurve.py +3 -1
  115. validmind/tests/model_validation/sklearn/RegressionErrors.py +6 -2
  116. validmind/tests/model_validation/sklearn/RegressionPerformance.py +13 -8
  117. validmind/tests/model_validation/sklearn/RegressionR2Square.py +8 -5
  118. validmind/tests/model_validation/sklearn/RobustnessDiagnosis.py +5 -1
  119. validmind/tests/model_validation/sklearn/SHAPGlobalImportance.py +6 -1
  120. validmind/tests/model_validation/sklearn/ScoreProbabilityAlignment.py +10 -2
  121. validmind/tests/model_validation/sklearn/SilhouettePlot.py +5 -1
  122. validmind/tests/model_validation/sklearn/VMeasure.py +12 -9
  123. validmind/tests/model_validation/statsmodels/CumulativePredictionProbabilities.py +5 -1
  124. validmind/tests/model_validation/statsmodels/DurbinWatsonTest.py +6 -1
  125. validmind/tests/model_validation/statsmodels/GINITable.py +8 -1
  126. validmind/tests/model_validation/statsmodels/KolmogorovSmirnov.py +2 -2
  127. validmind/tests/model_validation/statsmodels/PredictionProbabilitiesHistogram.py +6 -2
  128. validmind/tests/model_validation/statsmodels/RegressionCoeffs.py +8 -2
  129. validmind/tests/model_validation/statsmodels/RegressionFeatureSignificance.py +3 -1
  130. validmind/tests/model_validation/statsmodels/RegressionModelForecastPlot.py +7 -2
  131. validmind/tests/model_validation/statsmodels/RegressionModelForecastPlotLevels.py +2 -0
  132. validmind/tests/model_validation/statsmodels/RegressionModelSensitivityPlot.py +2 -0
  133. validmind/tests/model_validation/statsmodels/RegressionModelSummary.py +11 -9
  134. validmind/tests/model_validation/statsmodels/RegressionPermutationFeatureImportance.py +3 -1
  135. validmind/tests/ongoing_monitoring/CalibrationCurveDrift.py +11 -1
  136. validmind/tests/ongoing_monitoring/ClassificationAccuracyDrift.py +10 -2
  137. validmind/tests/ongoing_monitoring/ConfusionMatrixDrift.py +8 -1
  138. validmind/tests/ongoing_monitoring/CumulativePredictionProbabilitiesDrift.py +18 -2
  139. validmind/tests/ongoing_monitoring/FeatureDrift.py +9 -2
  140. validmind/tests/ongoing_monitoring/PredictionAcrossEachFeature.py +8 -2
  141. validmind/tests/ongoing_monitoring/PredictionCorrelation.py +13 -2
  142. validmind/tests/ongoing_monitoring/PredictionProbabilitiesHistogramDrift.py +13 -2
  143. validmind/tests/ongoing_monitoring/ROCCurveDrift.py +16 -2
  144. validmind/tests/ongoing_monitoring/ScoreBandsDrift.py +11 -2
  145. validmind/tests/ongoing_monitoring/TargetPredictionDistributionPlot.py +13 -2
  146. validmind/tests/prompt_validation/Clarity.py +1 -1
  147. validmind/tests/prompt_validation/NegativeInstruction.py +1 -1
  148. validmind/tests/prompt_validation/Robustness.py +6 -1
  149. validmind/tests/prompt_validation/Specificity.py +1 -1
  150. validmind/tests/prompt_validation/ai_powered_test.py +5 -4
  151. validmind/tests/run.py +5 -1
  152. validmind/utils.py +13 -0
  153. validmind/vm_models/result/result.py +43 -2
  154. {validmind-2.7.12.dist-info → validmind-2.8.12.dist-info}/METADATA +3 -2
  155. {validmind-2.7.12.dist-info → validmind-2.8.12.dist-info}/RECORD +158 -163
  156. validmind/ai/test_result_description/config.yaml +0 -29
  157. validmind/ai/test_result_description/context.py +0 -73
  158. validmind/ai/test_result_description/image_processing.py +0 -124
  159. validmind/ai/test_result_description/system.jinja +0 -39
  160. validmind/ai/test_result_description/user.jinja +0 -30
  161. {validmind-2.7.12.dist-info → validmind-2.8.12.dist-info}/LICENSE +0 -0
  162. {validmind-2.7.12.dist-info → validmind-2.8.12.dist-info}/WHEEL +0 -0
  163. {validmind-2.7.12.dist-info → validmind-2.8.12.dist-info}/entry_points.txt +0 -0
@@ -1,124 +0,0 @@
1
- # Copyright © 2023-2024 ValidMind Inc. All rights reserved.
2
- # See the LICENSE file in the root of this repository for details.
3
- # SPDX-License-Identifier: AGPL-3.0 AND ValidMind Commercial
4
-
5
- import base64
6
- import io
7
-
8
- import numpy as np
9
- from PIL import Image, ImageEnhance, ImageFilter
10
-
11
- DOWNSAMPLE_PERCENTAGE = 50
12
-
13
-
14
- def open_base64_image(base64_string):
15
- if base64_string.startswith("data:image/png;base64,"):
16
- base64_string = base64_string.split(",")[1]
17
-
18
- image_data = base64.b64decode(base64_string)
19
- image_buffer = io.BytesIO(image_data)
20
- image = Image.open(image_buffer)
21
-
22
- return image
23
-
24
-
25
- def downsample_image(base64_string):
26
- image = open_base64_image(base64_string)
27
-
28
- # Calculate the target dimensions based on the reduction percentage
29
- target_width = int(image.width * (1 - DOWNSAMPLE_PERCENTAGE / 100))
30
- target_height = int(image.height * (1 - DOWNSAMPLE_PERCENTAGE / 100))
31
-
32
- # If the image is already smaller than the target size, return the original
33
- if image.width <= target_width and image.height <= target_height:
34
- return base64_string
35
-
36
- # remove any margins from the image
37
- # Find the bounding box of non-uniform pixels (margin detection)
38
- width, height = image.size
39
- background = image.getpixel((0, 0)) # Assume top-left pixel is background color
40
-
41
- def is_different(pixel):
42
- return pixel != background
43
-
44
- left = next(
45
- x
46
- for x in range(width)
47
- if any(is_different(image.getpixel((x, y))) for y in range(height))
48
- )
49
- right = next(
50
- x
51
- for x in range(width - 1, -1, -1)
52
- if any(is_different(image.getpixel((x, y))) for y in range(height))
53
- )
54
- top = next(
55
- y
56
- for y in range(height)
57
- if any(is_different(image.getpixel((x, y))) for x in range(width))
58
- )
59
- bottom = next(
60
- y
61
- for y in range(height - 1, -1, -1)
62
- if any(is_different(image.getpixel((x, y))) for x in range(width))
63
- )
64
-
65
- # Crop the image to remove the uniform margin (with some padding)
66
- bbox = (left - 5, top - 5, right + 6, bottom + 6)
67
- image = image.crop(bbox)
68
-
69
- # If the image has an alpha channel, remove any transparent margins
70
- if image.mode in ("RGBA", "LA"):
71
- alpha = image.getchannel("A")
72
- bbox = alpha.getbbox()
73
- if bbox:
74
- image = image.crop(bbox)
75
-
76
- # Apply unsharp mask to enhance edges
77
- image = image.filter(ImageFilter.UnsharpMask(radius=2, percent=150, threshold=3))
78
-
79
- # Calculate new dimensions
80
- aspect_ratio = image.width / image.height
81
- new_height = target_height
82
- new_width = int(new_height * aspect_ratio)
83
-
84
- # print(f"downsampling from {width}x{height} to {new_width}x{new_height}")
85
-
86
- # Ensure we don't exceed the target width
87
- if new_width > target_width:
88
- new_width = target_width
89
- new_height = int(new_width / aspect_ratio)
90
-
91
- # print(f"downsampling from {image.width}x{image.height} to {new_width}x{new_height}")
92
-
93
- # Convert to numpy array for custom downsampling
94
- img_array = np.array(image)
95
-
96
- # Optimized area interpolation
97
- h_factor = img_array.shape[0] / new_height
98
- w_factor = img_array.shape[1] / new_width
99
-
100
- h_indices = (np.arange(new_height).reshape(-1, 1) * h_factor).astype(int)
101
- w_indices = (np.arange(new_width).reshape(1, -1) * w_factor).astype(int)
102
-
103
- h_indices = np.minimum(h_indices, img_array.shape[0] - 1)
104
- w_indices = np.minimum(w_indices, img_array.shape[1] - 1)
105
-
106
- # Convert back to PIL Image
107
- image = Image.fromarray(img_array[h_indices, w_indices].astype(np.uint8))
108
-
109
- # Enhance contrast slightly
110
- enhancer = ImageEnhance.Contrast(image)
111
- image = enhancer.enhance(1.2)
112
-
113
- # Sharpen the image
114
- image = image.filter(ImageFilter.SHARPEN)
115
-
116
- # Convert the image to bytes in PNG format
117
- buffered = io.BytesIO()
118
- image.save(buffered, format="PNG")
119
- img_bytes = buffered.getvalue()
120
-
121
- # Encode the bytes to base64
122
- b64_encoded = base64.b64encode(img_bytes).decode("utf-8")
123
-
124
- return f"data:image/png;base64,{b64_encoded}"
@@ -1,39 +0,0 @@
1
- You are an expert data scientist and MRM specialist.
2
- You are tasked with analyzing the results of a quantitative test run on some model or dataset.
3
- Your goal is to create a test description that will act as part of the model documentation.
4
- You will provide both the developer and other consumers of the documentation with a clear and concise "interpretation" of the results they will see.
5
- The overarching theme to maintain is MRM documentation.
6
-
7
- Examine the provided statistical test results and compose a description of the results.
8
- The results are either in the form of serialized tables or images of plots.
9
- Compose a description and interpretation of the result to accompany it in MRM documentation.
10
- It will be read by other data scientists and developers and by validators and stakeholders.
11
-
12
- Use valid Markdown syntax to format the response.
13
- Avoid long sentences and complex vocabulary.
14
- Avoid overly verbose explanations - the goal is to explain to a user what they are seeing in the results.
15
- Structure the response clearly and logically.
16
- Respond only with your analysis and insights, not the verbatim test results.
17
- Respond only with the markdown content, no explanation or context for your response is necessary.
18
- Use the Test ID that is provided to form the Test Name e.g. "ClassImbalance" -> "Class Imbalance".
19
-
20
- Explain the test, its purpose, its mechanism/formula etc and why it is useful.
21
- If relevant, provide a very brief description of the way this test is used in model/dataset evaluation and how it is interpreted.
22
- Highlight the key insights from the test results. The key insights should be concise and easily understood.
23
- An insight should only be included if it is something not entirely obvious from the test results.
24
- End the response with any closing remarks, summary or additional useful information.
25
-
26
- Use the following format for the response (feel free to stray from it if necessary - this is a suggested starting point):
27
-
28
- <ResponseFormat>
29
- **<Test Name>** calculates the xyz <continue to explain what it does in detail>...
30
-
31
- This test is useful for <explain why and for what this test is useful>...
32
-
33
- **Key Insights:**
34
-
35
- The following key insights can be identified in the test results:
36
-
37
- - **<key insight 1 - title>**: <concise explanation of key insight 1>
38
- - ...<continue with any other key insights using the same format>
39
- </ResponseFormat>
@@ -1,30 +0,0 @@
1
- **Test ID**: `{{ test_name }}`
2
-
3
- **Test Description**:
4
-
5
- {{ test_description }}
6
-
7
- ---
8
-
9
- Generate a description of the following result of the test using the instructions given in your system prompt.
10
-
11
- {%- if context %}
12
- **Context**:
13
- {{ context }}
14
- {%- endif %}
15
-
16
- {%- if summary %}
17
- **Test Result Tables** *(Raw Data)*:
18
- {{ summary }}
19
- {%- endif %}
20
-
21
- {%- if figures %}
22
- The following images make up the results of the test.
23
- {%- for b64_image_url in figures %}
24
- [[IMAGE:{{ b64_image_url }}]]
25
- {%- endfor %}
26
- {%- endif %}
27
-
28
- Keep your response concise and to the point!
29
- Only include content in your response if its something truly insightful or interesting!
30
- DO NOT VERBOSELY EXPLAIN THE TEST OR THE RESULTS!!!