noweda 0.2.1__tar.gz → 0.2.2__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.
- {noweda-0.2.1/noweda.egg-info → noweda-0.2.2}/PKG-INFO +27 -11
- {noweda-0.2.1 → noweda-0.2.2}/README.md +26 -10
- noweda-0.2.2/noweda/_version.py +1 -0
- {noweda-0.2.1 → noweda-0.2.2}/noweda/accessor.py +42 -450
- {noweda-0.2.1 → noweda-0.2.2}/noweda/large.py +11 -3
- noweda-0.2.2/noweda/visualization.py +714 -0
- {noweda-0.2.1 → noweda-0.2.2/noweda.egg-info}/PKG-INFO +27 -11
- {noweda-0.2.1 → noweda-0.2.2}/noweda.egg-info/SOURCES.txt +3 -1
- noweda-0.2.2/tests/test_vizall_ml.py +160 -0
- noweda-0.2.1/noweda/_version.py +0 -1
- {noweda-0.2.1 → noweda-0.2.2}/LICENSE +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/MANIFEST.in +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/examples/sample.csv +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/noweda/__init__.py +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/noweda/cli.py +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/noweda/core/__init__.py +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/noweda/core/engine.py +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/noweda/dtypes.py +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/noweda/insights/__init__.py +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/noweda/insights/generator.py +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/noweda/io.py +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/noweda/ml_recommendations.py +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/noweda/ml_tasks.py +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/noweda/ml_utils.py +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/noweda/plugins/__init__.py +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/noweda/plugins/base.py +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/noweda/plugins/correlation.py +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/noweda/plugins/duplicates.py +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/noweda/plugins/encoding.py +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/noweda/plugins/missing.py +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/noweda/plugins/outliers.py +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/noweda/plugins/pii.py +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/noweda/plugins/schema.py +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/noweda/plugins/stats.py +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/noweda/report/__init__.py +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/noweda/report/html.py +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/noweda/report/json.py +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/noweda/scoring/__init__.py +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/noweda/scoring/scorer.py +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/noweda/temporal_utils.py +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/noweda/ui.py +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/noweda.egg-info/dependency_links.txt +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/noweda.egg-info/entry_points.txt +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/noweda.egg-info/requires.txt +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/noweda.egg-info/top_level.txt +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/pyproject.toml +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/setup.cfg +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/setup.py +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/tests/test_basic.py +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/tests/test_formats.py +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/tests/test_large_mode.py +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/tests/test_ml_tasks.py +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/tests/test_progress.py +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/tests/test_regressions.py +0 -0
- {noweda-0.2.1 → noweda-0.2.2}/tests/test_release_014.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: noweda
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: Automated EDA with insights, scoring, and security-aware detection — built as a native pandas extension.
|
|
5
5
|
Author-email: Daniel Peng <danielpeng95@gmail.com>
|
|
6
6
|
License: MIT
|
|
@@ -107,8 +107,11 @@ df = pd.DataFrame({
|
|
|
107
107
|
# Start with one complete assessment.
|
|
108
108
|
df.eda.statsall()
|
|
109
109
|
|
|
110
|
-
#
|
|
111
|
-
# df.eda.vizall()
|
|
110
|
+
# With noweda[viz], rank general charts within a panel budget.
|
|
111
|
+
# df.eda.vizall(max_plots=10)
|
|
112
|
+
|
|
113
|
+
# Add target-aware diagnostics for model-family decisions.
|
|
114
|
+
# df.eda.vizall(target="segment", max_plots=15)
|
|
112
115
|
|
|
113
116
|
# Name an outcome before asking for supervised ML guidance.
|
|
114
117
|
# df.eda.mlall(target="segment")
|
|
@@ -193,19 +196,32 @@ metrics, and cautions. Stars and `/5` values are estimated dataset-fit ratings
|
|
|
193
196
|
within the selected task, not measured accuracy or expected performance. NowEDA
|
|
194
197
|
does not train models in this step. See the [ML guidance documentation](https://codewithdaniel1.github.io/NowEDA/ml-guidance/).
|
|
195
198
|
|
|
196
|
-
### 3. `df.eda.vizall()` —
|
|
199
|
+
### 3. `df.eda.vizall()` — Ranked visual diagnostics
|
|
197
200
|
|
|
198
|
-
Install `noweda[viz]` to draw distributions,
|
|
199
|
-
missingness, and applicable temporal plots.
|
|
200
|
-
|
|
201
|
+
Install `noweda[viz]` to draw a bounded set of distributions, relationships,
|
|
202
|
+
missingness, outliers, feature scales, and applicable temporal plots. Supply the
|
|
203
|
+
prediction target to add classification or regression diagnostics. NowEDA ranks
|
|
204
|
+
useful features, excludes likely identifiers and detected PII, and describes
|
|
205
|
+
model-family signals without claiming that a chart proves the best model.
|
|
201
206
|
|
|
202
207
|
```python
|
|
203
|
-
df.eda.vizall()
|
|
204
|
-
|
|
208
|
+
df.eda.vizall() # General and unsupervised structure
|
|
209
|
+
|
|
210
|
+
visuals = df.eda.vizall(
|
|
211
|
+
target="fraud_flag",
|
|
212
|
+
max_plots=15,
|
|
213
|
+
)
|
|
214
|
+
print(visuals["model_signals"])
|
|
215
|
+
|
|
216
|
+
df.eda.vizall(sample=5_000) # Optional bounded sample
|
|
205
217
|
```
|
|
206
218
|
|
|
207
|
-
|
|
208
|
-
|
|
219
|
+
`max_plots` counts individual chart panels, including subplots. The returned
|
|
220
|
+
result contains the figures, ranked associations, selected features, plot
|
|
221
|
+
titles, scope, and cautious model signals. In small mode, `sample=` bounds this
|
|
222
|
+
visual analysis without changing the loaded DataFrame.
|
|
223
|
+
See the [visual diagnostics guide](https://codewithdaniel1.github.io/NowEDA/visual-diagnostics/)
|
|
224
|
+
for classification, regression, sampling, and interpretation details.
|
|
209
225
|
|
|
210
226
|
### 4. `df.eda.profile_column("age")` — One-column profile
|
|
211
227
|
|
|
@@ -43,8 +43,11 @@ df = pd.DataFrame({
|
|
|
43
43
|
# Start with one complete assessment.
|
|
44
44
|
df.eda.statsall()
|
|
45
45
|
|
|
46
|
-
#
|
|
47
|
-
# df.eda.vizall()
|
|
46
|
+
# With noweda[viz], rank general charts within a panel budget.
|
|
47
|
+
# df.eda.vizall(max_plots=10)
|
|
48
|
+
|
|
49
|
+
# Add target-aware diagnostics for model-family decisions.
|
|
50
|
+
# df.eda.vizall(target="segment", max_plots=15)
|
|
48
51
|
|
|
49
52
|
# Name an outcome before asking for supervised ML guidance.
|
|
50
53
|
# df.eda.mlall(target="segment")
|
|
@@ -129,19 +132,32 @@ metrics, and cautions. Stars and `/5` values are estimated dataset-fit ratings
|
|
|
129
132
|
within the selected task, not measured accuracy or expected performance. NowEDA
|
|
130
133
|
does not train models in this step. See the [ML guidance documentation](https://codewithdaniel1.github.io/NowEDA/ml-guidance/).
|
|
131
134
|
|
|
132
|
-
### 3. `df.eda.vizall()` —
|
|
135
|
+
### 3. `df.eda.vizall()` — Ranked visual diagnostics
|
|
133
136
|
|
|
134
|
-
Install `noweda[viz]` to draw distributions,
|
|
135
|
-
missingness, and applicable temporal plots.
|
|
136
|
-
|
|
137
|
+
Install `noweda[viz]` to draw a bounded set of distributions, relationships,
|
|
138
|
+
missingness, outliers, feature scales, and applicable temporal plots. Supply the
|
|
139
|
+
prediction target to add classification or regression diagnostics. NowEDA ranks
|
|
140
|
+
useful features, excludes likely identifiers and detected PII, and describes
|
|
141
|
+
model-family signals without claiming that a chart proves the best model.
|
|
137
142
|
|
|
138
143
|
```python
|
|
139
|
-
df.eda.vizall()
|
|
140
|
-
|
|
144
|
+
df.eda.vizall() # General and unsupervised structure
|
|
145
|
+
|
|
146
|
+
visuals = df.eda.vizall(
|
|
147
|
+
target="fraud_flag",
|
|
148
|
+
max_plots=15,
|
|
149
|
+
)
|
|
150
|
+
print(visuals["model_signals"])
|
|
151
|
+
|
|
152
|
+
df.eda.vizall(sample=5_000) # Optional bounded sample
|
|
141
153
|
```
|
|
142
154
|
|
|
143
|
-
|
|
144
|
-
|
|
155
|
+
`max_plots` counts individual chart panels, including subplots. The returned
|
|
156
|
+
result contains the figures, ranked associations, selected features, plot
|
|
157
|
+
titles, scope, and cautious model signals. In small mode, `sample=` bounds this
|
|
158
|
+
visual analysis without changing the loaded DataFrame.
|
|
159
|
+
See the [visual diagnostics guide](https://codewithdaniel1.github.io/NowEDA/visual-diagnostics/)
|
|
160
|
+
for classification, regression, sampling, and interpretation details.
|
|
145
161
|
|
|
146
162
|
### 4. `df.eda.profile_column("age")` — One-column profile
|
|
147
163
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.2.2"
|
|
@@ -726,467 +726,42 @@ class NowEDAAccessor:
|
|
|
726
726
|
|
|
727
727
|
print(f"\n{_CYAN}{'='*70}{_RESET}\n")
|
|
728
728
|
|
|
729
|
-
def vizall(self, sample=None):
|
|
730
|
-
"""
|
|
729
|
+
def vizall(self, sample=None, target=None, max_plots=15):
|
|
730
|
+
"""Render ranked, ML-aware visual diagnostics.
|
|
731
|
+
|
|
732
|
+
``vizall()`` selects a bounded set of general diagnostics. Supplying a
|
|
733
|
+
target adds supervised feature-versus-target charts while preserving
|
|
734
|
+
the existing workflow. The returned dictionary-like result contains
|
|
735
|
+
the figures, ranked evidence, selected features, and scope metadata.
|
|
731
736
|
|
|
732
737
|
Parameters
|
|
733
738
|
----------
|
|
734
739
|
sample : int or None, default None
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
Produces
|
|
743
|
-
--------
|
|
744
|
-
- Histogram + KDE for every numeric column
|
|
745
|
-
- Bar chart of top categories for every categorical column
|
|
746
|
-
- Correlation heatmap when ≥2 numeric columns exist
|
|
747
|
-
- Missing-value bar chart when any missingness detected
|
|
748
|
-
- Time-series line plot for datetime columns (if a numeric col exists)
|
|
740
|
+
Analyze every loaded row by default, or use a deterministic sample.
|
|
741
|
+
target : column label or None, default None
|
|
742
|
+
User-selected prediction target. NowEDA infers classification or
|
|
743
|
+
regression from its observed values but never selects a target.
|
|
744
|
+
max_plots : int, default 15
|
|
745
|
+
Maximum number of individual chart panels to render.
|
|
749
746
|
"""
|
|
750
|
-
|
|
751
|
-
import matplotlib.pyplot as plt
|
|
752
|
-
import matplotlib
|
|
753
|
-
except ImportError:
|
|
754
|
-
raise ImportError(
|
|
755
|
-
"matplotlib is required for vizall(). "
|
|
756
|
-
"Install it with: pip install matplotlib"
|
|
757
|
-
)
|
|
747
|
+
from noweda.visualization import render_vizall
|
|
758
748
|
|
|
759
749
|
analysis_df = _analysis_sample(self._df, sample, "vizall()")
|
|
760
750
|
if analysis_df is not self._df:
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
self._ensure_analyzed()
|
|
764
|
-
df_full = self._df
|
|
765
|
-
|
|
766
|
-
if sample is None:
|
|
767
|
-
df = df_full
|
|
768
|
-
elif isinstance(sample, bool) or not isinstance(sample, int) or sample <= 0:
|
|
769
|
-
raise ValueError("sample must be a positive integer")
|
|
770
|
-
elif len(df_full) > sample:
|
|
771
|
-
print(
|
|
772
|
-
f"NowEDA · vizall(): sample-based charts use {sample:,} of "
|
|
773
|
-
f"{len(df_full):,} rows. Estimates may differ from the full dataset."
|
|
774
|
-
)
|
|
775
|
-
df = df_full.sample(n=sample, random_state=42)
|
|
776
|
-
else:
|
|
777
|
-
df = df_full
|
|
778
|
-
results = self._report["results"]
|
|
779
|
-
schema = results.get("schema", {})
|
|
780
|
-
missing_info = results.get("missing", {})
|
|
781
|
-
|
|
782
|
-
# Helper: exclude ID and quasi-ID columns (not useful for visualization)
|
|
783
|
-
def is_id_column(col_name, col_values):
|
|
784
|
-
"""Detect ID columns by name. Only exclude if column name suggests it's an identifier."""
|
|
785
|
-
# Check column name for ID indicators
|
|
786
|
-
col_lower = str(col_name).lower()
|
|
787
|
-
is_id_like = (
|
|
788
|
-
col_lower in ("id", "customer_id", "user_id", "record_id", "index", "idx") or
|
|
789
|
-
col_lower.endswith("_id") or
|
|
790
|
-
col_lower.startswith("id_")
|
|
791
|
-
)
|
|
792
|
-
|
|
793
|
-
# For object/string columns, also check if it's sequential IDs (like "CUST001", "USER_123")
|
|
794
|
-
if is_id_like:
|
|
795
|
-
return True
|
|
796
|
-
|
|
797
|
-
# High cardinality check: only for object columns (credit card, email, etc)
|
|
798
|
-
# Don't apply to numeric columns as continuous data naturally has high cardinality
|
|
799
|
-
if is_textual(col_values):
|
|
800
|
-
unique_ratio = col_values.nunique() / len(col_values) if len(col_values) > 0 else 0
|
|
801
|
-
if unique_ratio > 0.95: # >95% unique string values likely PII/ID
|
|
802
|
-
return True
|
|
803
|
-
|
|
804
|
-
return False
|
|
805
|
-
|
|
806
|
-
# Exclude ID columns from visualization
|
|
807
|
-
viz_cols = [c for c in df.columns if not is_id_column(c, df[c])]
|
|
808
|
-
|
|
809
|
-
# Helper: detect if a numeric column is actually PII (credit cards, etc.)
|
|
810
|
-
def is_numeric_pii(col_name, col_values):
|
|
811
|
-
"""Detect numeric PII: credit_card, account_number, etc."""
|
|
812
|
-
col_lower = str(col_name).lower()
|
|
813
|
-
pii_indicators = (
|
|
814
|
-
"credit" in col_lower or
|
|
815
|
-
"card" in col_lower or
|
|
816
|
-
"account_number" in col_lower or
|
|
817
|
-
"ssn" in col_lower or
|
|
818
|
-
"zip" in col_lower
|
|
819
|
-
)
|
|
820
|
-
return pii_indicators
|
|
821
|
-
|
|
822
|
-
numeric_cols = [
|
|
823
|
-
c for c in viz_cols
|
|
824
|
-
if df[c].dtype.kind in ("i", "u", "f")
|
|
825
|
-
and not is_numeric_pii(c, df[c]) # Exclude numeric PII
|
|
826
|
-
]
|
|
827
|
-
cat_cols = [
|
|
828
|
-
c for c in viz_cols
|
|
829
|
-
if is_textual(df[c])
|
|
830
|
-
and schema.get(c, {}).get("role") in ("categorical", "categorical_numeric", "text", None)
|
|
831
|
-
and df[c].nunique() <= 30
|
|
832
|
-
]
|
|
833
|
-
datetime_cols = [
|
|
834
|
-
c for c in viz_cols
|
|
835
|
-
if df[c].dtype.kind == "M" or schema.get(c, {}).get("role") == "datetime"
|
|
836
|
-
]
|
|
837
|
-
cols_with_missing = [
|
|
838
|
-
c for c in viz_cols
|
|
839
|
-
if df[c].isna().sum() > 0
|
|
840
|
-
]
|
|
841
|
-
|
|
842
|
-
style = "dark_background" if "dark_background" in plt.style.available else "default"
|
|
843
|
-
plt.style.use(style)
|
|
844
|
-
|
|
845
|
-
figs_shown = 0
|
|
846
|
-
|
|
847
|
-
# ── Numeric: histogram + KDE ─────────────────────────────────────────
|
|
848
|
-
if numeric_cols:
|
|
849
|
-
n = len(numeric_cols)
|
|
850
|
-
ncols_grid = min(3, n)
|
|
851
|
-
nrows_grid = -(-n // ncols_grid) # ceiling division
|
|
852
|
-
fig, axes = plt.subplots(
|
|
853
|
-
nrows_grid, ncols_grid,
|
|
854
|
-
figsize=(6 * ncols_grid, 4 * nrows_grid),
|
|
855
|
-
squeeze=False
|
|
751
|
+
result = analysis_df.eda.vizall(
|
|
752
|
+
sample=sample, target=target, max_plots=max_plots
|
|
856
753
|
)
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
ax.hist(data, bins=30, color="#4C72B0", alpha=0.7, edgecolor="white", linewidth=0.4)
|
|
862
|
-
try:
|
|
863
|
-
from scipy.stats import gaussian_kde
|
|
864
|
-
import numpy as np
|
|
865
|
-
if len(data) >= 2:
|
|
866
|
-
kde = gaussian_kde(data)
|
|
867
|
-
x = np.linspace(data.min(), data.max(), 200)
|
|
868
|
-
ax2 = ax.twinx()
|
|
869
|
-
ax2.plot(x, kde(x), color="#DD8452", linewidth=2)
|
|
870
|
-
ax2.set_yticks([])
|
|
871
|
-
except ImportError:
|
|
872
|
-
pass
|
|
873
|
-
ax.set_title(col, fontsize=11)
|
|
874
|
-
ax.set_xlabel(col)
|
|
875
|
-
ax.set_ylabel("Count")
|
|
876
|
-
# Hide empty subplots
|
|
877
|
-
for j in range(n, nrows_grid * ncols_grid):
|
|
878
|
-
axes[j // ncols_grid][j % ncols_grid].set_visible(False)
|
|
879
|
-
plt.tight_layout()
|
|
880
|
-
plt.show()
|
|
881
|
-
figs_shown += 1
|
|
882
|
-
|
|
883
|
-
# ── Categorical: bar charts with distribution ─────────────────────────
|
|
884
|
-
if cat_cols:
|
|
885
|
-
n = len(cat_cols)
|
|
886
|
-
ncols_grid = min(3, n)
|
|
887
|
-
nrows_grid = -(-n // ncols_grid)
|
|
888
|
-
fig, axes = plt.subplots(
|
|
889
|
-
nrows_grid, ncols_grid,
|
|
890
|
-
figsize=(6 * ncols_grid, 4 * nrows_grid),
|
|
891
|
-
squeeze=False
|
|
892
|
-
)
|
|
893
|
-
fig.suptitle("Categorical Distributions (top 15 values)", fontsize=14, fontweight="bold")
|
|
894
|
-
palette = ["#4C72B0", "#DD8452", "#55A868", "#C44E52", "#8172B2",
|
|
895
|
-
"#937860", "#DA8BC3", "#8C8C8C", "#CCB974", "#64B5CD"]
|
|
896
|
-
for i, col in enumerate(cat_cols):
|
|
897
|
-
ax = axes[i // ncols_grid][i % ncols_grid]
|
|
898
|
-
counts = df[col].value_counts().head(15)
|
|
899
|
-
total = counts.sum()
|
|
900
|
-
colors = [palette[j % len(palette)] for j in range(len(counts))]
|
|
901
|
-
bars = ax.bar(range(len(counts)), counts.values, color=colors, edgecolor="white", linewidth=0.4)
|
|
902
|
-
|
|
903
|
-
# Add percentage labels on bars
|
|
904
|
-
for bar in bars:
|
|
905
|
-
height = bar.get_height()
|
|
906
|
-
pct = (height / total * 100) if total > 0 else 0
|
|
907
|
-
ax.text(bar.get_x() + bar.get_width()/2., height,
|
|
908
|
-
f'{pct:.0f}%', ha='center', va='bottom', fontsize=7, color='white', fontweight='bold')
|
|
909
|
-
|
|
910
|
-
ax.set_xticks(range(len(counts)))
|
|
911
|
-
ax.set_xticklabels(
|
|
912
|
-
[str(x)[:10] for x in counts.index],
|
|
913
|
-
rotation=45, ha="right", fontsize=8
|
|
914
|
-
)
|
|
915
|
-
ax.set_title(col, fontsize=11)
|
|
916
|
-
ax.set_ylabel("Count")
|
|
917
|
-
ax.set_ylim(0, max(counts.values) * 1.15) # Space for labels
|
|
918
|
-
for j in range(n, nrows_grid * ncols_grid):
|
|
919
|
-
axes[j // ncols_grid][j % ncols_grid].set_visible(False)
|
|
920
|
-
plt.tight_layout()
|
|
921
|
-
plt.show()
|
|
922
|
-
figs_shown += 1
|
|
923
|
-
|
|
924
|
-
# ── Correlation heatmap ───────────────────────────────────────────────
|
|
925
|
-
if len(numeric_cols) >= 2:
|
|
926
|
-
try:
|
|
927
|
-
import numpy as np
|
|
928
|
-
corr = df[numeric_cols].corr()
|
|
929
|
-
n = len(numeric_cols)
|
|
930
|
-
fig_size = max(6, min(n * 1.2, 16))
|
|
931
|
-
fig, ax = plt.subplots(figsize=(fig_size, fig_size * 0.85))
|
|
932
|
-
cmap = matplotlib.colormaps.get_cmap("coolwarm") if hasattr(matplotlib, "colormaps") else plt.cm.coolwarm
|
|
933
|
-
im = ax.imshow(corr.values, cmap=cmap, vmin=-1, vmax=1, aspect="auto")
|
|
934
|
-
plt.colorbar(im, ax=ax, shrink=0.8)
|
|
935
|
-
ax.set_xticks(range(n))
|
|
936
|
-
ax.set_yticks(range(n))
|
|
937
|
-
ax.set_xticklabels(numeric_cols, rotation=45, ha="right", fontsize=9)
|
|
938
|
-
ax.set_yticklabels(numeric_cols, fontsize=9)
|
|
939
|
-
# Annotate cells
|
|
940
|
-
for row in range(n):
|
|
941
|
-
for col_i in range(n):
|
|
942
|
-
val = corr.values[row, col_i]
|
|
943
|
-
ax.text(col_i, row, f"{val:.2f}", ha="center", va="center",
|
|
944
|
-
fontsize=8, color="white" if abs(val) > 0.5 else "black")
|
|
945
|
-
ax.set_title("Correlation Heatmap", fontsize=14, fontweight="bold")
|
|
946
|
-
plt.tight_layout()
|
|
947
|
-
plt.show()
|
|
948
|
-
figs_shown += 1
|
|
949
|
-
except Exception:
|
|
950
|
-
pass
|
|
951
|
-
|
|
952
|
-
# ── Missing value chart ───────────────────────────────────────────────
|
|
953
|
-
if cols_with_missing:
|
|
954
|
-
miss_rates = {
|
|
955
|
-
c: round(df[c].isna().sum() / len(df) * 100, 2)
|
|
956
|
-
for c in cols_with_missing
|
|
754
|
+
result["scope"] = {
|
|
755
|
+
"rows": int(len(self._df)),
|
|
756
|
+
"sample_rows": int(len(analysis_df)),
|
|
757
|
+
"sample_based": True,
|
|
957
758
|
}
|
|
958
|
-
|
|
959
|
-
fig, ax = plt.subplots(figsize=(max(6, len(miss_rates) * 0.8), 5))
|
|
960
|
-
colors = ["#C44E52" if v >= 50 else "#DD8452" if v >= 20 else "#4C72B0"
|
|
961
|
-
for v in miss_rates.values()]
|
|
962
|
-
bars = ax.bar(range(len(miss_rates)), list(miss_rates.values()),
|
|
963
|
-
color=colors, edgecolor="white", linewidth=0.4)
|
|
964
|
-
ax.set_xticks(range(len(miss_rates)))
|
|
965
|
-
ax.set_xticklabels(list(miss_rates.keys()), rotation=45, ha="right", fontsize=9)
|
|
966
|
-
ax.set_ylabel("Missing %")
|
|
967
|
-
ax.set_title("Missing Values by Column", fontsize=13, fontweight="bold")
|
|
968
|
-
ax.set_ylim(0, 100)
|
|
969
|
-
for bar, val in zip(bars, miss_rates.values()):
|
|
970
|
-
ax.text(bar.get_x() + bar.get_width() / 2, bar.get_height() + 1,
|
|
971
|
-
f"{val:.1f}%", ha="center", va="bottom", fontsize=8)
|
|
972
|
-
plt.tight_layout()
|
|
973
|
-
plt.show()
|
|
974
|
-
figs_shown += 1
|
|
975
|
-
|
|
976
|
-
# ── Missing data correlation heatmap ──────────────────────────────────
|
|
977
|
-
if len(cols_with_missing) >= 2:
|
|
978
|
-
try:
|
|
979
|
-
import numpy as np
|
|
980
|
-
# Create binary matrix: 1 if missing, 0 if not
|
|
981
|
-
missing_matrix = df[cols_with_missing].isna().astype(int)
|
|
982
|
-
# Compute correlation between missing patterns
|
|
983
|
-
missing_corr = missing_matrix.corr()
|
|
984
|
-
|
|
985
|
-
if len(cols_with_missing) > 1:
|
|
986
|
-
fig, ax = plt.subplots(figsize=(8, 6))
|
|
987
|
-
cmap = matplotlib.colormaps.get_cmap("RdYlGn_r") if hasattr(matplotlib, "colormaps") else plt.cm.RdYlGn_r
|
|
988
|
-
im = ax.imshow(missing_corr.values, cmap=cmap, aspect='auto', vmin=-1, vmax=1)
|
|
989
|
-
plt.colorbar(im, ax=ax, label="Correlation in Missing Patterns")
|
|
990
|
-
|
|
991
|
-
ax.set_xticks(range(len(cols_with_missing)))
|
|
992
|
-
ax.set_yticks(range(len(cols_with_missing)))
|
|
993
|
-
ax.set_xticklabels(cols_with_missing, rotation=45, ha='right', fontsize=9)
|
|
994
|
-
ax.set_yticklabels(cols_with_missing, fontsize=9)
|
|
995
|
-
|
|
996
|
-
# Annotate
|
|
997
|
-
for i in range(len(cols_with_missing)):
|
|
998
|
-
for j in range(len(cols_with_missing)):
|
|
999
|
-
text = ax.text(j, i, f'{missing_corr.values[i, j]:.2f}',
|
|
1000
|
-
ha="center", va="center",
|
|
1001
|
-
color="black" if abs(missing_corr.values[i, j]) < 0.5 else "white",
|
|
1002
|
-
fontsize=8)
|
|
1003
|
-
|
|
1004
|
-
ax.set_title("Missing Data Patterns (Correlation)", fontsize=13, fontweight="bold")
|
|
1005
|
-
plt.tight_layout()
|
|
1006
|
-
plt.show()
|
|
1007
|
-
figs_shown += 1
|
|
1008
|
-
except Exception:
|
|
1009
|
-
pass
|
|
1010
|
-
|
|
1011
|
-
# ── Datetime line plots ───────────────────────────────────────────────
|
|
1012
|
-
if datetime_cols and numeric_cols:
|
|
1013
|
-
dt_col = datetime_cols[0]
|
|
1014
|
-
num_col = numeric_cols[0]
|
|
1015
|
-
try:
|
|
1016
|
-
sorted_df = df[[dt_col, num_col]].dropna().sort_values(dt_col)
|
|
1017
|
-
fig, ax = plt.subplots(figsize=(12, 4))
|
|
1018
|
-
ax.plot(sorted_df[dt_col], sorted_df[num_col],
|
|
1019
|
-
color="#4C72B0", linewidth=1.2)
|
|
1020
|
-
ax.set_title(f"{num_col} over {dt_col}", fontsize=13, fontweight="bold")
|
|
1021
|
-
ax.set_xlabel(dt_col)
|
|
1022
|
-
ax.set_ylabel(num_col)
|
|
1023
|
-
plt.xticks(rotation=30, ha="right")
|
|
1024
|
-
plt.tight_layout()
|
|
1025
|
-
plt.show()
|
|
1026
|
-
figs_shown += 1
|
|
1027
|
-
except Exception:
|
|
1028
|
-
pass
|
|
1029
|
-
|
|
1030
|
-
# ── Box plots: numeric vs categorical ──────────────────────────────────
|
|
1031
|
-
if numeric_cols and cat_cols:
|
|
1032
|
-
try:
|
|
1033
|
-
# Select top categorical column (by cardinality, not too many levels)
|
|
1034
|
-
cat_by_card = sorted(cat_cols, key=lambda c: df[c].nunique())
|
|
1035
|
-
cat_col = cat_by_card[0] if df[cat_by_card[0]].nunique() <= 20 else None
|
|
1036
|
-
|
|
1037
|
-
if cat_col:
|
|
1038
|
-
n = len(numeric_cols)
|
|
1039
|
-
ncols_grid = min(3, n)
|
|
1040
|
-
nrows_grid = -(-n // ncols_grid)
|
|
1041
|
-
fig, axes = plt.subplots(
|
|
1042
|
-
nrows_grid, ncols_grid,
|
|
1043
|
-
figsize=(6 * ncols_grid, 4 * nrows_grid),
|
|
1044
|
-
squeeze=False
|
|
1045
|
-
)
|
|
1046
|
-
fig.suptitle(f"Numeric Distributions by {cat_col}", fontsize=14, fontweight="bold")
|
|
1047
|
-
palette_box = ["#4C72B0", "#DD8452", "#55A868", "#C44E52", "#8172B2", "#937860"]
|
|
1048
|
-
for i, col in enumerate(numeric_cols):
|
|
1049
|
-
ax = axes[i // ncols_grid][i % ncols_grid]
|
|
1050
|
-
df_plot = df[[col, cat_col]].dropna()
|
|
1051
|
-
if len(df_plot) > 0:
|
|
1052
|
-
df_plot.boxplot(column=col, by=cat_col, ax=ax)
|
|
1053
|
-
ax.set_title(col, fontsize=11)
|
|
1054
|
-
ax.set_xlabel(cat_col)
|
|
1055
|
-
plt.sca(ax)
|
|
1056
|
-
plt.xticks(rotation=45, ha="right", fontsize=8)
|
|
1057
|
-
for j in range(n, nrows_grid * ncols_grid):
|
|
1058
|
-
axes[j // ncols_grid][j % ncols_grid].set_visible(False)
|
|
1059
|
-
plt.tight_layout()
|
|
1060
|
-
plt.show()
|
|
1061
|
-
figs_shown += 1
|
|
1062
|
-
except Exception:
|
|
1063
|
-
pass
|
|
1064
|
-
|
|
1065
|
-
# ── Feature variance/importance ranking ────────────────────────────────
|
|
1066
|
-
if numeric_cols:
|
|
1067
|
-
try:
|
|
1068
|
-
import numpy as np
|
|
1069
|
-
variances = []
|
|
1070
|
-
for col in numeric_cols:
|
|
1071
|
-
var = df[col].var()
|
|
1072
|
-
if not np.isnan(var):
|
|
1073
|
-
variances.append((col, var))
|
|
1074
|
-
|
|
1075
|
-
if variances:
|
|
1076
|
-
variances.sort(key=lambda x: -x[1])
|
|
1077
|
-
fig, ax = plt.subplots(figsize=(10, 5))
|
|
1078
|
-
cols, vars = zip(*variances[:15])
|
|
1079
|
-
# Normalize variances to 0-100 scale for readability
|
|
1080
|
-
max_var = max(vars)
|
|
1081
|
-
normalized = [v / max_var * 100 for v in vars]
|
|
1082
|
-
colors_var = ["#4C72B0" if v > 50 else "#DD8452" if v > 20 else "#8C8C8C" for v in normalized]
|
|
1083
|
-
bars = ax.barh(cols, normalized, color=colors_var, edgecolor="white", linewidth=0.5)
|
|
1084
|
-
ax.set_xlabel("Variance (normalized to 0-100)")
|
|
1085
|
-
ax.set_title("Feature Variance Ranking (Higher = More Information)", fontsize=13, fontweight="bold")
|
|
1086
|
-
ax.invert_yaxis()
|
|
1087
|
-
for i, (bar, v) in enumerate(zip(bars, vars)):
|
|
1088
|
-
ax.text(100 + 2, i, f"{v:.2e}", va='center', fontsize=8)
|
|
1089
|
-
plt.tight_layout()
|
|
1090
|
-
plt.show()
|
|
1091
|
-
figs_shown += 1
|
|
1092
|
-
except Exception:
|
|
1093
|
-
pass
|
|
1094
|
-
|
|
1095
|
-
# ── Pair plot: top correlated pairs ────────────────────────────────────
|
|
1096
|
-
if numeric_cols and len(numeric_cols) >= 2:
|
|
1097
|
-
try:
|
|
1098
|
-
corr_matrix = df[numeric_cols].corr().abs()
|
|
1099
|
-
# Find top correlations (excluding diagonal)
|
|
1100
|
-
top_pairs = []
|
|
1101
|
-
for i in range(len(numeric_cols)):
|
|
1102
|
-
for j in range(i + 1, len(numeric_cols)):
|
|
1103
|
-
corr_val = corr_matrix.iloc[i, j]
|
|
1104
|
-
if corr_val > 0.3: # threshold
|
|
1105
|
-
top_pairs.append((numeric_cols[i], numeric_cols[j], corr_val))
|
|
1106
|
-
|
|
1107
|
-
top_pairs.sort(key=lambda x: -x[2])
|
|
1108
|
-
n_pairs = min(6, len(top_pairs)) # Show up to 6 pairs in 2x3 grid
|
|
1109
|
-
|
|
1110
|
-
if n_pairs > 0:
|
|
1111
|
-
ncols_grid = min(3, n_pairs)
|
|
1112
|
-
nrows_grid = -(-n_pairs // ncols_grid)
|
|
1113
|
-
fig, axes = plt.subplots(
|
|
1114
|
-
nrows_grid, ncols_grid,
|
|
1115
|
-
figsize=(5 * ncols_grid, 4 * nrows_grid),
|
|
1116
|
-
squeeze=False
|
|
1117
|
-
)
|
|
1118
|
-
fig.suptitle("Top Correlated Feature Pairs", fontsize=14, fontweight="bold")
|
|
1119
|
-
|
|
1120
|
-
for idx, (col1, col2, corr_val) in enumerate(top_pairs[:n_pairs]):
|
|
1121
|
-
ax = axes[idx // ncols_grid][idx % ncols_grid]
|
|
1122
|
-
df_plot = df[[col1, col2]].dropna()
|
|
1123
|
-
ax.scatter(df_plot[col1], df_plot[col2], alpha=0.6, color="#4C72B0", edgecolor="white", linewidth=0.4)
|
|
1124
|
-
|
|
1125
|
-
# Add regression line
|
|
1126
|
-
z = np.polyfit(df_plot[col1], df_plot[col2], 1)
|
|
1127
|
-
p = np.poly1d(z)
|
|
1128
|
-
x_line = np.linspace(df_plot[col1].min(), df_plot[col1].max(), 100)
|
|
1129
|
-
ax.plot(x_line, p(x_line), color="#DD8452", linewidth=2, label=f"r={corr_val:.2f}")
|
|
1130
|
-
|
|
1131
|
-
ax.set_xlabel(col1, fontsize=9)
|
|
1132
|
-
ax.set_ylabel(col2, fontsize=9)
|
|
1133
|
-
ax.set_title(f"{col1} vs {col2}", fontsize=10)
|
|
1134
|
-
ax.legend(fontsize=8)
|
|
1135
|
-
ax.grid(alpha=0.3)
|
|
1136
|
-
|
|
1137
|
-
for j in range(n_pairs, nrows_grid * ncols_grid):
|
|
1138
|
-
axes[j // ncols_grid][j % ncols_grid].set_visible(False)
|
|
1139
|
-
plt.tight_layout()
|
|
1140
|
-
plt.show()
|
|
1141
|
-
figs_shown += 1
|
|
1142
|
-
except Exception:
|
|
1143
|
-
pass
|
|
1144
|
-
|
|
1145
|
-
# ── Categorical relationship heatmap (Cramér's V) ───────────────────────
|
|
1146
|
-
if len(cat_cols) >= 2:
|
|
1147
|
-
try:
|
|
1148
|
-
from noweda.ml_utils import cramers_v
|
|
1149
|
-
import numpy as np
|
|
759
|
+
return result
|
|
1150
760
|
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
if i == j:
|
|
1156
|
-
cramers_matrix[i, j] = 1.0
|
|
1157
|
-
elif i < j:
|
|
1158
|
-
try:
|
|
1159
|
-
v = cramers_v(df[col1], df[col2])
|
|
1160
|
-
cramers_matrix[i, j] = cramers_matrix[j, i] = v
|
|
1161
|
-
except Exception:
|
|
1162
|
-
pass
|
|
1163
|
-
|
|
1164
|
-
fig, ax = plt.subplots(figsize=(8, 6))
|
|
1165
|
-
cmap = matplotlib.colormaps.get_cmap("YlOrRd") if hasattr(matplotlib, "colormaps") else plt.cm.YlOrRd
|
|
1166
|
-
im = ax.imshow(np.ma.masked_invalid(cramers_matrix), cmap=cmap, aspect='auto', vmin=0, vmax=1)
|
|
1167
|
-
plt.colorbar(im, ax=ax, label="Cramér's V")
|
|
1168
|
-
|
|
1169
|
-
ax.set_xticks(range(len(cat_cols)))
|
|
1170
|
-
ax.set_yticks(range(len(cat_cols)))
|
|
1171
|
-
ax.set_xticklabels(cat_cols, rotation=45, ha='right', fontsize=9)
|
|
1172
|
-
ax.set_yticklabels(cat_cols, fontsize=9)
|
|
1173
|
-
|
|
1174
|
-
# Annotate
|
|
1175
|
-
for i in range(len(cat_cols)):
|
|
1176
|
-
for j in range(len(cat_cols)):
|
|
1177
|
-
text = ax.text(j, i, ('N/A' if np.isnan(cramers_matrix[i, j]) else f'{cramers_matrix[i, j]:.2f}'),
|
|
1178
|
-
ha="center", va="center", color="black" if np.isnan(cramers_matrix[i, j]) or cramers_matrix[i, j] < 0.5 else "white",
|
|
1179
|
-
fontsize=8)
|
|
1180
|
-
|
|
1181
|
-
ax.set_title("Categorical Association (Cramér's V)", fontsize=13, fontweight="bold")
|
|
1182
|
-
plt.tight_layout()
|
|
1183
|
-
plt.show()
|
|
1184
|
-
figs_shown += 1
|
|
1185
|
-
except Exception:
|
|
1186
|
-
pass
|
|
1187
|
-
|
|
1188
|
-
if figs_shown == 0:
|
|
1189
|
-
print("No visualizations could be generated for this dataset.")
|
|
761
|
+
self._ensure_analyzed()
|
|
762
|
+
return render_vizall(
|
|
763
|
+
self._df, self._report, target=target, max_plots=max_plots
|
|
764
|
+
)
|
|
1190
765
|
|
|
1191
766
|
def mlall(self, target=None, problem_type=None, features=None, plan=False, sample=None):
|
|
1192
767
|
"""Print task-aware ML guidance and optionally return its structured result.
|
|
@@ -1208,7 +783,24 @@ class NowEDAAccessor:
|
|
|
1208
783
|
self._df, self._report, target=target,
|
|
1209
784
|
problem_type=problem_type, features=features,
|
|
1210
785
|
)
|
|
786
|
+
if target is not None:
|
|
787
|
+
from noweda.visualization import build_visual_diagnostics
|
|
788
|
+
|
|
789
|
+
target_values = self._df.iloc[:, self._df.columns.get_loc(target)]
|
|
790
|
+
if target_values.notna().any():
|
|
791
|
+
visual = build_visual_diagnostics(
|
|
792
|
+
self._df, self._report, target=target
|
|
793
|
+
)
|
|
794
|
+
result["visual_diagnostics"] = {
|
|
795
|
+
key: value for key, value in visual.items()
|
|
796
|
+
if key not in {"numeric_scales"}
|
|
797
|
+
}
|
|
1211
798
|
format_ml_plan(result)
|
|
799
|
+
visual = result.get("visual_diagnostics")
|
|
800
|
+
if visual and visual.get("model_signals"):
|
|
801
|
+
print("\n Visual diagnostics to validate with vizall(target={!r}):".format(target))
|
|
802
|
+
for signal in visual["model_signals"]:
|
|
803
|
+
print(" - {}".format(signal))
|
|
1212
804
|
if plan:
|
|
1213
805
|
return result
|
|
1214
806
|
|
|
@@ -172,13 +172,21 @@ class LargeEDAAccessor:
|
|
|
172
172
|
}
|
|
173
173
|
return report
|
|
174
174
|
|
|
175
|
-
def vizall(self, sample=10_000):
|
|
176
|
-
"""Render charts from the large-mode sample."""
|
|
175
|
+
def vizall(self, sample=10_000, target=None, max_plots=15):
|
|
176
|
+
"""Render ranked charts from the large-mode sample."""
|
|
177
177
|
self._announce_sample("vizall()", rows=sample)
|
|
178
178
|
# Do not let the pandas accessor take a second, hidden sample of the
|
|
179
179
|
# already bounded large-mode sample. An explicit ``sample=`` remains
|
|
180
180
|
# available for callers who want smaller charts.
|
|
181
|
-
|
|
181
|
+
result = self._pandas_accessor(sample).vizall(
|
|
182
|
+
sample=sample, target=target, max_plots=max_plots
|
|
183
|
+
)
|
|
184
|
+
result["scope"] = {
|
|
185
|
+
"rows": int(self._dataset.row_count),
|
|
186
|
+
"sample_rows": int(min(sample, self._dataset.row_count)),
|
|
187
|
+
"sample_based": self._dataset.row_count > sample,
|
|
188
|
+
}
|
|
189
|
+
return result
|
|
182
190
|
|
|
183
191
|
def mlall(self, target=None, problem_type=None, features=None, plan=False, sample=10_000):
|
|
184
192
|
"""Create ML guidance from the sample and identify it as estimated."""
|