validmind 2.2.5__py3-none-any.whl → 2.3.1__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 (105) hide show
  1. validmind/__version__.py +1 -1
  2. validmind/{ai.py → ai/test_descriptions.py} +127 -69
  3. validmind/ai/utils.py +104 -0
  4. validmind/api_client.py +70 -31
  5. validmind/client.py +5 -5
  6. validmind/logging.py +38 -32
  7. validmind/models/foundation.py +10 -6
  8. validmind/models/function.py +3 -1
  9. validmind/models/metadata.py +1 -1
  10. validmind/test_suites/__init__.py +1 -7
  11. validmind/test_suites/regression.py +0 -16
  12. validmind/test_suites/statsmodels_timeseries.py +1 -1
  13. validmind/tests/data_validation/ACFandPACFPlot.py +36 -27
  14. validmind/tests/{model_validation/statsmodels → data_validation}/ADF.py +42 -13
  15. validmind/tests/data_validation/BivariateScatterPlots.py +38 -41
  16. validmind/tests/{model_validation/statsmodels → data_validation}/DFGLSArch.py +67 -11
  17. validmind/tests/data_validation/HeatmapFeatureCorrelations.py +1 -1
  18. validmind/tests/data_validation/HighPearsonCorrelation.py +12 -3
  19. validmind/tests/data_validation/IsolationForestOutliers.py +2 -2
  20. validmind/tests/{model_validation/statsmodels → data_validation}/KPSS.py +64 -11
  21. validmind/tests/{model_validation/statsmodels → data_validation}/PhillipsPerronArch.py +65 -11
  22. validmind/tests/data_validation/ScatterPlot.py +1 -1
  23. validmind/tests/data_validation/SeasonalDecompose.py +12 -7
  24. validmind/tests/data_validation/TabularDateTimeHistograms.py +29 -33
  25. validmind/tests/data_validation/WOEBinPlots.py +1 -1
  26. validmind/tests/data_validation/WOEBinTable.py +1 -1
  27. validmind/tests/{model_validation/statsmodels → data_validation}/ZivotAndrewsArch.py +65 -11
  28. validmind/tests/data_validation/nlp/CommonWords.py +1 -1
  29. validmind/tests/data_validation/nlp/Hashtags.py +1 -1
  30. validmind/tests/data_validation/nlp/Mentions.py +1 -1
  31. validmind/tests/data_validation/nlp/PolarityAndSubjectivity.py +2 -1
  32. validmind/tests/data_validation/nlp/Punctuations.py +1 -1
  33. validmind/tests/data_validation/nlp/Sentiment.py +1 -1
  34. validmind/tests/data_validation/nlp/TextDescription.py +5 -1
  35. validmind/tests/data_validation/nlp/Toxicity.py +1 -1
  36. validmind/tests/decorator.py +1 -1
  37. validmind/tests/model_validation/FeaturesAUC.py +5 -3
  38. validmind/tests/model_validation/embeddings/CosineSimilarityComparison.py +4 -0
  39. validmind/tests/model_validation/embeddings/CosineSimilarityHeatmap.py +4 -0
  40. validmind/tests/model_validation/embeddings/EuclideanDistanceComparison.py +4 -0
  41. validmind/tests/model_validation/embeddings/EuclideanDistanceHeatmap.py +4 -0
  42. validmind/tests/model_validation/embeddings/PCAComponentsPairwisePlots.py +4 -0
  43. validmind/tests/model_validation/embeddings/TSNEComponentsPairwisePlots.py +4 -0
  44. validmind/tests/model_validation/ragas/AnswerCorrectness.py +3 -3
  45. validmind/tests/model_validation/ragas/AnswerRelevance.py +5 -4
  46. validmind/tests/model_validation/ragas/AnswerSimilarity.py +5 -4
  47. validmind/tests/model_validation/ragas/AspectCritique.py +14 -8
  48. validmind/tests/model_validation/ragas/ContextEntityRecall.py +3 -4
  49. validmind/tests/model_validation/ragas/ContextPrecision.py +4 -5
  50. validmind/tests/model_validation/ragas/ContextRecall.py +3 -4
  51. validmind/tests/model_validation/ragas/ContextRelevancy.py +5 -4
  52. validmind/tests/model_validation/ragas/Faithfulness.py +6 -5
  53. validmind/tests/model_validation/ragas/utils.py +35 -9
  54. validmind/tests/model_validation/sklearn/ClusterPerformance.py +2 -2
  55. validmind/tests/model_validation/sklearn/ClusterPerformanceMetrics.py +1 -1
  56. validmind/tests/model_validation/sklearn/ModelsPerformanceComparison.py +6 -8
  57. validmind/tests/model_validation/sklearn/RegressionErrors.py +1 -1
  58. validmind/tests/model_validation/sklearn/RegressionModelsPerformanceComparison.py +14 -8
  59. validmind/tests/model_validation/sklearn/RegressionR2Square.py +1 -1
  60. validmind/tests/model_validation/statsmodels/DurbinWatsonTest.py +1 -1
  61. validmind/tests/model_validation/statsmodels/GINITable.py +1 -1
  62. validmind/tests/model_validation/statsmodels/JarqueBera.py +1 -1
  63. validmind/tests/model_validation/statsmodels/KolmogorovSmirnov.py +1 -1
  64. validmind/tests/model_validation/statsmodels/LJungBox.py +1 -1
  65. validmind/tests/model_validation/statsmodels/Lilliefors.py +1 -1
  66. validmind/tests/model_validation/statsmodels/RegressionCoeffsPlot.py +4 -0
  67. validmind/tests/model_validation/statsmodels/RegressionFeatureSignificance.py +9 -4
  68. validmind/tests/model_validation/statsmodels/RegressionModelsCoeffs.py +2 -2
  69. validmind/tests/model_validation/statsmodels/RunsTest.py +1 -1
  70. validmind/tests/model_validation/statsmodels/ShapiroWilk.py +1 -1
  71. validmind/tests/prompt_validation/Bias.py +14 -11
  72. validmind/tests/prompt_validation/Clarity.py +14 -11
  73. validmind/tests/prompt_validation/Conciseness.py +14 -11
  74. validmind/tests/prompt_validation/Delimitation.py +14 -11
  75. validmind/tests/prompt_validation/NegativeInstruction.py +14 -11
  76. validmind/tests/prompt_validation/Robustness.py +11 -11
  77. validmind/tests/prompt_validation/Specificity.py +14 -11
  78. validmind/tests/prompt_validation/ai_powered_test.py +53 -75
  79. validmind/unit_metrics/composite.py +2 -1
  80. validmind/utils.py +4 -49
  81. validmind/vm_models/dataset/dataset.py +17 -3
  82. validmind/vm_models/dataset/utils.py +2 -2
  83. validmind/vm_models/model.py +1 -1
  84. validmind/vm_models/test/metric.py +1 -8
  85. validmind/vm_models/test/result_wrapper.py +27 -34
  86. validmind/vm_models/test/test.py +3 -0
  87. validmind/vm_models/test/threshold_test.py +1 -1
  88. validmind/vm_models/test_suite/runner.py +12 -6
  89. validmind/vm_models/test_suite/summary.py +18 -7
  90. validmind/vm_models/test_suite/test.py +13 -20
  91. {validmind-2.2.5.dist-info → validmind-2.3.1.dist-info}/METADATA +1 -1
  92. {validmind-2.2.5.dist-info → validmind-2.3.1.dist-info}/RECORD +95 -104
  93. validmind/tests/data_validation/DefaultRatesbyRiskBandPlot.py +0 -114
  94. validmind/tests/data_validation/PiTCreditScoresHistogram.py +0 -150
  95. validmind/tests/data_validation/PiTPDHistogram.py +0 -152
  96. validmind/tests/model_validation/statsmodels/ADFTest.py +0 -88
  97. validmind/tests/model_validation/statsmodels/FeatureImportanceAndSignificance.py +0 -198
  98. validmind/tests/model_validation/statsmodels/PDRatingClassPlot.py +0 -151
  99. validmind/tests/model_validation/statsmodels/RegressionModelInsampleComparison.py +0 -146
  100. validmind/tests/model_validation/statsmodels/RegressionModelOutsampleComparison.py +0 -144
  101. validmind/tests/model_validation/statsmodels/RegressionModelsPerformance.py +0 -127
  102. validmind/tests/model_validation/statsmodels/ResidualsVisualInspection.py +0 -130
  103. {validmind-2.2.5.dist-info → validmind-2.3.1.dist-info}/LICENSE +0 -0
  104. {validmind-2.2.5.dist-info → validmind-2.3.1.dist-info}/WHEEL +0 -0
  105. {validmind-2.2.5.dist-info → validmind-2.3.1.dist-info}/entry_points.txt +0 -0
@@ -1,130 +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
- from dataclasses import dataclass
6
-
7
- import matplotlib.pyplot as plt
8
- import pandas as pd
9
- import seaborn as sns
10
- from scipy import stats
11
- from statsmodels.graphics.tsaplots import plot_acf
12
- from statsmodels.tsa.seasonal import seasonal_decompose
13
-
14
- from validmind.vm_models import Figure, Metric
15
-
16
-
17
- @dataclass
18
- class ResidualsVisualInspection(Metric):
19
- """
20
- Provides a comprehensive visual analysis of residuals for regression models utilizing various plot types.
21
-
22
- **Purpose**: The main purpose of this metric is to visualize and analyze the residuals (the differences between the
23
- observed and predicted values) of a regression problem. It allows for a graphical exploration of the model's
24
- errors, helping to identify statistical patterns or anomalies that may indicate a systematic bias in the model's
25
- predictions. By inspecting the residuals, we can check how well the model fits the data and meets the assumptions
26
- of the model.
27
-
28
- **Test Mechanism**: The metric generates four common types of residual plots which are: a histogram with kernel
29
- density estimation, a quantile-quantile (Q-Q) plot, a residuals series dot plot, and an autocorrelation function
30
- (ACF) plot.
31
-
32
- - The residuals histogram with kernel density estimation visualizes the distribution of residuals and allows to
33
- check if they are normally distributed.
34
- - Q-Q plot compares the observed quantiles of the data to the quantiles of a standard normal distribution, helping
35
- to assess the normality of residuals.
36
- - A residuals dot plot indicates the variation in residuals over time, which helps in identifying any time-related
37
- pattern in residuals.
38
- - ACF plot visualizes the correlation of an observation with its previous observations, helping to pinpoint any
39
- seasonality effect within residuals.
40
-
41
- **Signs of High Risk**:
42
-
43
- - Skewness or asymmetry in the histogram or a significant deviation from the straight line in the Q-Q plot, which
44
- indicates that the residuals aren't normally distributed.
45
- - Large spikes in the ACF plot, indicating that the residuals are correlated, in violation of the assumption that
46
- they are independent.
47
- - Non-random patterns in the dot plot of residuals, indicating potential model misspecification.
48
-
49
- **Strengths**:
50
-
51
- - Visual analysis of residuals is a powerful yet simple way to understand a model’s behavior across the data set
52
- and to identify problems with the model's assumptions or its fit to the data.
53
- - The test is applicable to any regression model, irrespective of complexity.
54
- - By exploring residuals, we might uncover relationships that were not captured by the model, revealing
55
- opportunities for model improvement.
56
-
57
- **Limitations**:
58
-
59
- - Visual tests are largely subjective and can be open to interpretation. Clear-cut decisions about the model based
60
- solely on these plots may not be possible.
61
- - The metrics from the test do not directly infer the action based on the results; domain-specific knowledge and
62
- expert judgement is often required to interpret the results.
63
- - These plots can indicate a problem with the model but they do not necessarily reveal the nature or cause of the
64
- problem.
65
- - The test assumes that the error terms are identically distributed, which might not always be the case in
66
- real-world scenarios.
67
- """
68
-
69
- name = "residuals_visual_inspection"
70
- required_inputs = ["dataset"]
71
- metadata = {
72
- "task_types": ["regression"],
73
- "tags": ["statsmodels", "visualization"],
74
- }
75
-
76
- @staticmethod
77
- def residual_analysis(residuals, variable_name, axes):
78
- residuals = residuals.dropna().reset_index(
79
- drop=True
80
- ) # drop NaN values and reset index
81
-
82
- # QQ plot
83
- stats.probplot(residuals, dist="norm", plot=axes[0, 1])
84
- axes[0, 1].set_title(f"Residuals Q-Q Plot ({variable_name})")
85
-
86
- # Histogram with KDE
87
- sns.histplot(residuals, kde=True, ax=axes[0, 0])
88
- axes[0, 0].set_xlabel("Residuals")
89
- axes[0, 0].set_title(f"Residuals Histogram ({variable_name})")
90
-
91
- # Residual series dot plot
92
- sns.lineplot(data=residuals, linewidth=0.5, color="red", ax=axes[1, 0])
93
- axes[1, 0].set_title(f"Residual Series Dot Plot ({variable_name})")
94
-
95
- # ACF plot
96
- n_lags = min(100, len(residuals) - 1) # Adjust the number of lags
97
- plot_acf(residuals, ax=axes[1, 1], lags=n_lags, zero=False) # Added zero=False
98
- axes[1, 1].set_title(f"ACF Plot of Residuals ({variable_name})")
99
-
100
- def run(self):
101
- x_train = self.inputs.dataset.df
102
- figures = []
103
-
104
- # TODO: specify which columns to plot via params
105
- for col in x_train.columns:
106
- sd = seasonal_decompose(x_train[col], model="additive")
107
-
108
- # Remove NaN values from the residuals and reset the index
109
- residuals = pd.Series(sd.resid).dropna().reset_index(drop=True)
110
-
111
- # Create subplots
112
- fig, axes = plt.subplots(nrows=2, ncols=2)
113
- fig.suptitle(f"Residuals Inspection for {col}", fontsize=24)
114
-
115
- self.residual_analysis(residuals, col, axes)
116
-
117
- # Adjust the layout
118
- plt.tight_layout()
119
-
120
- # Do this if you want to prevent the figure from being displayed
121
- plt.close("all")
122
-
123
- figures.append(
124
- Figure(
125
- for_object=self,
126
- key=self.key,
127
- figure=fig,
128
- )
129
- )
130
- return self.cache_results(figures=figures)