datapilot-polars 0.3.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.
- datapilot_polars-0.3.0/PKG-INFO +618 -0
- datapilot_polars-0.3.0/README.md +585 -0
- datapilot_polars-0.3.0/datapilot/__init__.py +119 -0
- datapilot_polars-0.3.0/datapilot/ai/__init__.py +3 -0
- datapilot_polars-0.3.0/datapilot/ai/base.py +57 -0
- datapilot_polars-0.3.0/datapilot/ai/factory.py +70 -0
- datapilot_polars-0.3.0/datapilot/ai/insights.py +46 -0
- datapilot_polars-0.3.0/datapilot/ai/providers/__init__.py +0 -0
- datapilot_polars-0.3.0/datapilot/ai/providers/claude_provider.py +45 -0
- datapilot_polars-0.3.0/datapilot/ai/providers/gemini_provider.py +46 -0
- datapilot_polars-0.3.0/datapilot/ai/providers/groq_provider.py +52 -0
- datapilot_polars-0.3.0/datapilot/ai/providers/ollama_provider.py +35 -0
- datapilot_polars-0.3.0/datapilot/ai/providers/openai_provider.py +43 -0
- datapilot_polars-0.3.0/datapilot/analysis/__init__.py +0 -0
- datapilot_polars-0.3.0/datapilot/analysis/auto_clean.py +131 -0
- datapilot_polars-0.3.0/datapilot/analysis/benchmark.py +137 -0
- datapilot_polars-0.3.0/datapilot/analysis/compare.py +129 -0
- datapilot_polars-0.3.0/datapilot/analysis/correlations.py +41 -0
- datapilot_polars-0.3.0/datapilot/analysis/duplicates.py +22 -0
- datapilot_polars-0.3.0/datapilot/analysis/eda.py +96 -0
- datapilot_polars-0.3.0/datapilot/analysis/missing.py +32 -0
- datapilot_polars-0.3.0/datapilot/analysis/outliers.py +102 -0
- datapilot_polars-0.3.0/datapilot/analysis/suggest.py +126 -0
- datapilot_polars-0.3.0/datapilot/analysis/summary.py +22 -0
- datapilot_polars-0.3.0/datapilot/dashboard/__init__.py +3 -0
- datapilot_polars-0.3.0/datapilot/dashboard/dashboard.py +326 -0
- datapilot_polars-0.3.0/datapilot/ml/__init__.py +6 -0
- datapilot_polars-0.3.0/datapilot/ml/classification.py +40 -0
- datapilot_polars-0.3.0/datapilot/ml/diagnostics.py +28 -0
- datapilot_polars-0.3.0/datapilot/ml/regression.py +67 -0
- datapilot_polars-0.3.0/datapilot/utils/__init__.py +0 -0
- datapilot_polars-0.3.0/datapilot/utils/validation.py +19 -0
- datapilot_polars-0.3.0/datapilot/visualization/__init__.py +5 -0
- datapilot_polars-0.3.0/datapilot/visualization/boxplot.py +23 -0
- datapilot_polars-0.3.0/datapilot/visualization/heatmap.py +26 -0
- datapilot_polars-0.3.0/datapilot/visualization/histogram.py +25 -0
- datapilot_polars-0.3.0/datapilot_polars.egg-info/PKG-INFO +618 -0
- datapilot_polars-0.3.0/datapilot_polars.egg-info/SOURCES.txt +42 -0
- datapilot_polars-0.3.0/datapilot_polars.egg-info/dependency_links.txt +1 -0
- datapilot_polars-0.3.0/datapilot_polars.egg-info/requires.txt +29 -0
- datapilot_polars-0.3.0/datapilot_polars.egg-info/top_level.txt +1 -0
- datapilot_polars-0.3.0/pyproject.toml +56 -0
- datapilot_polars-0.3.0/setup.cfg +4 -0
- datapilot_polars-0.3.0/tests/test_analysis.py +388 -0
|
@@ -0,0 +1,618 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: datapilot-polars
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Your Data Science Copilot — Polars-native EDA, auto-cleaning, drift detection, and multi-provider AI insights
|
|
5
|
+
Classifier: Programming Language :: Python :: 3
|
|
6
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
7
|
+
Classifier: Operating System :: OS Independent
|
|
8
|
+
Requires-Python: >=3.9
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
Requires-Dist: polars>=1.0.0
|
|
11
|
+
Requires-Dist: pyarrow>=14.0.0
|
|
12
|
+
Requires-Dist: pandas>=2.0.0
|
|
13
|
+
Requires-Dist: ollama>=0.2.0
|
|
14
|
+
Requires-Dist: matplotlib>=3.5.0
|
|
15
|
+
Requires-Dist: seaborn>=0.12.0
|
|
16
|
+
Requires-Dist: scikit-learn>=1.0.0
|
|
17
|
+
Provides-Extra: dev
|
|
18
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
19
|
+
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
20
|
+
Provides-Extra: openai
|
|
21
|
+
Requires-Dist: openai>=1.0.0; extra == "openai"
|
|
22
|
+
Provides-Extra: gemini
|
|
23
|
+
Requires-Dist: google-generativeai>=0.7.0; extra == "gemini"
|
|
24
|
+
Provides-Extra: claude
|
|
25
|
+
Requires-Dist: anthropic>=0.25.0; extra == "claude"
|
|
26
|
+
Provides-Extra: groq
|
|
27
|
+
Requires-Dist: groq>=0.9.0; extra == "groq"
|
|
28
|
+
Provides-Extra: all-ai
|
|
29
|
+
Requires-Dist: openai>=1.0.0; extra == "all-ai"
|
|
30
|
+
Requires-Dist: google-generativeai>=0.7.0; extra == "all-ai"
|
|
31
|
+
Requires-Dist: anthropic>=0.25.0; extra == "all-ai"
|
|
32
|
+
Requires-Dist: groq>=0.9.0; extra == "all-ai"
|
|
33
|
+
|
|
34
|
+
# 📖 DataPilot — Your Data Science Copilot
|
|
35
|
+
|
|
36
|
+
[](https://www.python.org/)
|
|
37
|
+
[](https://github.com/yourusername/datapilot)
|
|
38
|
+
[](https://pola.rs/)
|
|
39
|
+
[](https://github.com/yourusername/datapilot)
|
|
40
|
+
[](https://opensource.org/licenses/MIT)
|
|
41
|
+
[](https://github.com/yourusername/datapilot)
|
|
42
|
+
|
|
43
|
+
> **The only EDA library that is Polars-native, multi-provider AI-powered, and actually cleans your data.**
|
|
44
|
+
|
|
45
|
+
DataPilot is an open-source Python library that automates Exploratory Data Analysis, detects data quality issues, cleans datasets, benchmarks performance, and generates intelligent AI recommendations — via Ollama (local), OpenAI, Google Gemini, Anthropic Claude, or Groq — all with minimal code.
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## 🚀 Why DataPilot?
|
|
50
|
+
|
|
51
|
+
| | ydata-profiling | sweetviz | dtale | **DataPilot** |
|
|
52
|
+
|---|:-:|:-:|:-:|:-:|
|
|
53
|
+
| Polars-native (10x faster) | ❌ | ❌ | ❌ | ✅ |
|
|
54
|
+
| Local AI (Ollama, private) | ❌ | ❌ | ❌ | ✅ |
|
|
55
|
+
| Cloud AI (OpenAI/Gemini/Claude/Groq) | ❌ | ❌ | ❌ | ✅ |
|
|
56
|
+
| Auto data cleaning | ❌ | ❌ | ❌ | ✅ |
|
|
57
|
+
| Train/test drift detection | ✅ | ✅ | ❌ | ✅ |
|
|
58
|
+
| Outlier detection | ⚠️ | ❌ | ✅ | ✅ |
|
|
59
|
+
| Smart column suggestions | ❌ | ❌ | ❌ | ✅ |
|
|
60
|
+
| Offline HTML dashboard | ✅ | ✅ | ❌ | ✅ |
|
|
61
|
+
| Regression diagnostics | ❌ | ❌ | ❌ | ✅ |
|
|
62
|
+
| ML model diagnostics | ❌ | ❌ | ❌ | ✅ |
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## 📑 Table of Contents
|
|
67
|
+
1. [Installation](#installation)
|
|
68
|
+
2. [Quick Start](#quick-start)
|
|
69
|
+
3. [Module 1: Auto EDA Pipeline](#module-1-auto-eda-pipeline)
|
|
70
|
+
4. [Module 2: Smart Column Suggestions](#module-2-smart-column-suggestions)
|
|
71
|
+
5. [Module 3: Dataset Analysis API](#module-3-dataset-analysis-api)
|
|
72
|
+
6. [Module 4: Outlier Detection](#module-4-outlier-detection)
|
|
73
|
+
7. [Module 5: Auto Data Cleaning](#module-5-auto-data-cleaning)
|
|
74
|
+
8. [Module 6: Train/Test Drift Detection](#module-6-traintest-drift-detection)
|
|
75
|
+
9. [Module 7: Visualization Engine](#module-7-visualization-engine)
|
|
76
|
+
10. [Module 8: Machine Learning Diagnostics](#module-8-machine-learning-diagnostics)
|
|
77
|
+
11. [Module 9: Standalone HTML Dashboard](#module-9-standalone-html-dashboard)
|
|
78
|
+
12. [Module 10: Performance Benchmark](#module-10-performance-benchmark)
|
|
79
|
+
13. [Module 11: AI Copilot (5 Providers)](#module-11-ai-copilot--5-providers)
|
|
80
|
+
14. [Installation & Setup](#installation--setup)
|
|
81
|
+
15. [Troubleshooting](#troubleshooting)
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Installation
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
# Clone and install in editable mode
|
|
89
|
+
git clone https://github.com/yourusername/datapilot.git
|
|
90
|
+
cd datapilot
|
|
91
|
+
|
|
92
|
+
uv venv && source .venv/bin/activate
|
|
93
|
+
uv pip install -e .
|
|
94
|
+
|
|
95
|
+
# For development / running tests
|
|
96
|
+
uv pip install -e .[dev]
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
> **System requirement:** Python 3.9+. Ollama is only required if you use `use_ai=True`.
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## Quick Start
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
import pandas as pd
|
|
107
|
+
import datapilot as dp
|
|
108
|
+
|
|
109
|
+
df = pd.read_csv("your_dataset.csv")
|
|
110
|
+
|
|
111
|
+
# Full automated EDA in one line
|
|
112
|
+
dp.analyze(df)
|
|
113
|
+
|
|
114
|
+
# Smart suggestions on what to fix
|
|
115
|
+
dp.suggest(df)
|
|
116
|
+
|
|
117
|
+
# Auto-clean the dataset
|
|
118
|
+
clean_df, log = dp.auto_clean(df)
|
|
119
|
+
|
|
120
|
+
# Export a full HTML report
|
|
121
|
+
dp.dashboard(df, "report.html")
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## Module 1: Auto EDA Pipeline
|
|
127
|
+
|
|
128
|
+
### `dp.analyze(df, use_ai=False, ai_model="llama3")`
|
|
129
|
+
|
|
130
|
+
The primary entry point. Runs all structural checks simultaneously and prints a clean console report.
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
# Standard rule-based analysis
|
|
134
|
+
dp.analyze(df)
|
|
135
|
+
|
|
136
|
+
# With local AI copilot (requires Ollama)
|
|
137
|
+
dp.analyze(df, use_ai=True, ai_model="llama3")
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
**Console Output:**
|
|
141
|
+
```
|
|
142
|
+
==================================================
|
|
143
|
+
DATAPILOT AUTOMATED EDA REPORT
|
|
144
|
+
==================================================
|
|
145
|
+
📊 Dataset Shape: 891 rows × 12 columns
|
|
146
|
+
💾 Memory Usage: 0.0815 MB
|
|
147
|
+
👥 Duplicate Rows: 0 (0.0%)
|
|
148
|
+
--------------------------------------------------
|
|
149
|
+
|
|
150
|
+
🔍 Missing Value Profile:
|
|
151
|
+
• Cabin: 687 missing (77.1%)
|
|
152
|
+
• Age: 177 missing (19.87%)
|
|
153
|
+
|
|
154
|
+
🔗 Strong Linear Correlations (|r| >= 0.6):
|
|
155
|
+
• Fare ↔ Survived (pos: 0.697)
|
|
156
|
+
==================================================
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## Module 2: Smart Column Suggestions
|
|
162
|
+
|
|
163
|
+
### `dp.suggest(df)`
|
|
164
|
+
|
|
165
|
+
Analyses every column and returns actionable, rule-based preprocessing recommendations — no AI or internet required.
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
suggestions = dp.suggest(df)
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
**Detects:**
|
|
172
|
+
- 🔴 ID/key columns (100% unique values — no signal, should be dropped)
|
|
173
|
+
- 🔴 Constant columns (zero variance — useless for ML)
|
|
174
|
+
- 🔴 Columns with >60% missing data
|
|
175
|
+
- 🟡 Columns with 20–60% missing data
|
|
176
|
+
- 🟡 Unencoded categorical strings (should be One-Hot or Target encoded)
|
|
177
|
+
- 🟡 High-cardinality strings (need embedding or target encoding)
|
|
178
|
+
- 🟡 Date strings that should be parsed to datetime
|
|
179
|
+
- 🟡 Imbalanced binary targets (class ratio < 20%)
|
|
180
|
+
|
|
181
|
+
**Console Output:**
|
|
182
|
+
```
|
|
183
|
+
========================================================
|
|
184
|
+
DATAPILOT SMART COLUMN SUGGESTIONS
|
|
185
|
+
========================================================
|
|
186
|
+
|
|
187
|
+
[1] 🔴 HIGH — PassengerId
|
|
188
|
+
Issue: 100% unique values — likely an ID or key column
|
|
189
|
+
Fix: Drop 'PassengerId' — unique identifiers leak no signal.
|
|
190
|
+
|
|
191
|
+
[2] 🟡 MEDIUM — Cabin
|
|
192
|
+
Issue: Very high missing rate (77.1%)
|
|
193
|
+
Fix: Consider dropping 'Cabin' — over 60% nulls will degrade model quality.
|
|
194
|
+
|
|
195
|
+
[3] 🟡 MEDIUM — Sex
|
|
196
|
+
Issue: Unencoded categorical string (2 unique values)
|
|
197
|
+
Fix: Encode 'Sex' using One-Hot Encoding before modelling.
|
|
198
|
+
========================================================
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
**Returns:** `List[Dict]` with keys `column`, `issue`, `severity`, `suggestion`.
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
## Module 3: Dataset Analysis API
|
|
206
|
+
|
|
207
|
+
All functions accept both `pandas.DataFrame` and `polars.DataFrame`.
|
|
208
|
+
|
|
209
|
+
### `dp.summary(df)`
|
|
210
|
+
|
|
211
|
+
```python
|
|
212
|
+
meta = dp.summary(df)
|
|
213
|
+
# Returns: {'engine_detected': 'pandas', 'rows': 891, 'columns': 12,
|
|
214
|
+
# 'datatypes': {...}, 'memory_usage_mb': 0.08, 'total_missing_values': 866}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### `dp.missing(df)`
|
|
218
|
+
|
|
219
|
+
```python
|
|
220
|
+
report = dp.missing(df)
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
| column | missing_count | missing_percentage |
|
|
224
|
+
|--------|:---:|:---:|
|
|
225
|
+
| Cabin | 687 | 77.10% |
|
|
226
|
+
| Age | 177 | 19.87% |
|
|
227
|
+
|
|
228
|
+
### `dp.duplicates(df)`
|
|
229
|
+
|
|
230
|
+
```python
|
|
231
|
+
dups = dp.duplicates(df)
|
|
232
|
+
# Returns: {'duplicate_count': 5, 'duplicate_percentage': 0.56}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### `dp.correlation(df, threshold=0.6)`
|
|
236
|
+
|
|
237
|
+
```python
|
|
238
|
+
corr = dp.correlation(df, threshold=0.6)
|
|
239
|
+
print(corr['strong_positive']) # [('Fare ↔ Survived', 0.697)]
|
|
240
|
+
print(corr['strong_negative']) # [('Pclass ↔ Fare', -0.549)]
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
## Module 4: Outlier Detection
|
|
246
|
+
|
|
247
|
+
### `dp.outliers(df, method="both", z_threshold=3.0, iqr_multiplier=1.5)`
|
|
248
|
+
|
|
249
|
+
Detects outliers across all numeric columns using **IQR fencing** and/or **Z-score** — whichever flags more values when `method="both"`.
|
|
250
|
+
|
|
251
|
+
```python
|
|
252
|
+
result = dp.outliers(df)
|
|
253
|
+
result = dp.outliers(df, method="iqr") # IQR only
|
|
254
|
+
result = dp.outliers(df, method="zscore") # Z-score only
|
|
255
|
+
result = dp.outliers(df, iqr_multiplier=3.0) # extreme outliers only
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
**Console Output:**
|
|
259
|
+
```
|
|
260
|
+
========================================================
|
|
261
|
+
DATAPILOT OUTLIER DETECTION REPORT
|
|
262
|
+
Method: BOTH | Z-threshold: 3.0 | IQR×1.5
|
|
263
|
+
========================================================
|
|
264
|
+
|
|
265
|
+
🔴 HIGH — Fare
|
|
266
|
+
Outlier count: 12 (6.7% of non-null values)
|
|
267
|
+
IQR fences: [-26.18, 65.63]
|
|
268
|
+
Extreme values: [512.3, 263.0, 211.3]
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
**Returns:** `Dict[column → {count, percentage, severity, values, lower_fence, upper_fence}]`
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
## Module 5: Auto Data Cleaning
|
|
276
|
+
|
|
277
|
+
### `dp.auto_clean(df, drop_null_threshold=0.6, impute_strategy="auto", drop_id_columns=True, drop_constant_columns=True)`
|
|
278
|
+
|
|
279
|
+
The killer feature. Automatically fixes your dataset and tells you exactly what it changed.
|
|
280
|
+
|
|
281
|
+
```python
|
|
282
|
+
clean_df, change_log = dp.auto_clean(df)
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
**What it does (in order):**
|
|
286
|
+
1. Drops columns where **all values are the same** (zero variance)
|
|
287
|
+
2. Drops **ID/key columns** where every row is unique
|
|
288
|
+
3. Drops columns with **≥60% null values**
|
|
289
|
+
4. **Imputes** remaining numeric nulls with **median**
|
|
290
|
+
5. **Imputes** remaining categorical nulls with **mode**
|
|
291
|
+
|
|
292
|
+
**Console Output:**
|
|
293
|
+
```
|
|
294
|
+
==========================================================
|
|
295
|
+
DATAPILOT AUTO-CLEAN ENGINE
|
|
296
|
+
==========================================================
|
|
297
|
+
Input: 891 rows × 12 columns
|
|
298
|
+
|
|
299
|
+
🗑️ DROP 'PassengerId' → ID-like column (all 891 values unique)
|
|
300
|
+
🗑️ DROP 'Cabin' → High null rate (77.1%) exceeds threshold (60%)
|
|
301
|
+
🔧 IMPUTE 'Age' → filled 177 null(s) with median=28.0
|
|
302
|
+
🔧 IMPUTE 'Embarked' → filled 2 null(s) with mode='S'
|
|
303
|
+
|
|
304
|
+
----------------------------------------------------------
|
|
305
|
+
Output: 891 rows × 10 columns
|
|
306
|
+
✅ 2 column(s) dropped | 2 column(s) imputed
|
|
307
|
+
==========================================================
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
**Returns:** `Tuple[cleaned_DataFrame, List[change_log_dicts]]`
|
|
311
|
+
|
|
312
|
+
---
|
|
313
|
+
|
|
314
|
+
## Module 6: Train/Test Drift Detection
|
|
315
|
+
|
|
316
|
+
### `dp.compare(df_train, df_test, threshold=0.1)`
|
|
317
|
+
|
|
318
|
+
Detects distribution shift between training and production data — the root cause of silent model degradation.
|
|
319
|
+
|
|
320
|
+
```python
|
|
321
|
+
flags = dp.compare(df_train, df_test)
|
|
322
|
+
flags = dp.compare(df_train, df_test, threshold=0.15) # stricter
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
**How it works:**
|
|
326
|
+
- **Numeric columns:** Flags if mean shifts >15% or std shifts >25%
|
|
327
|
+
- **Categorical columns:** Computes Jensen-Shannon divergence (0 = identical, 1 = completely different)
|
|
328
|
+
|
|
329
|
+
**Console Output:**
|
|
330
|
+
```
|
|
331
|
+
============================================================
|
|
332
|
+
DATAPILOT TRAIN vs TEST DRIFT REPORT
|
|
333
|
+
Train shape: 712 rows × 11 cols
|
|
334
|
+
Test shape: 179 rows × 11 cols
|
|
335
|
+
Shared columns analysed: 11
|
|
336
|
+
------------------------------------------------------------
|
|
337
|
+
|
|
338
|
+
⚠️ Age [🟡 MEDIUM] (numeric drift)
|
|
339
|
+
Mean: train=29.64 → test=30.27 (2.1% shift)
|
|
340
|
+
Std: train=14.52 → test=15.11
|
|
341
|
+
|
|
342
|
+
⚠️ Embarked [🔴 HIGH] (categorical drift)
|
|
343
|
+
JS Divergence: 0.341 (threshold: 0.1)
|
|
344
|
+
Train top value: 'S' | Test top value: 'C'
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
**Returns:** `List[Dict]` of flagged columns with drift statistics.
|
|
348
|
+
|
|
349
|
+
---
|
|
350
|
+
|
|
351
|
+
## Module 7: Visualization Engine
|
|
352
|
+
|
|
353
|
+
One-liner plots, no matplotlib syntax required.
|
|
354
|
+
|
|
355
|
+
```python
|
|
356
|
+
dp.hist(df, "Age", bins=15) # distribution with KDE overlay
|
|
357
|
+
dp.box(df, "Fare") # quartiles and outliers
|
|
358
|
+
dp.heatmap(df) # annotated Pearson correlation grid
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
---
|
|
362
|
+
|
|
363
|
+
## Module 8: Machine Learning Diagnostics
|
|
364
|
+
|
|
365
|
+
### `dp.classification_report(y_true, y_pred, average="auto")`
|
|
366
|
+
|
|
367
|
+
Auto-detects binary vs multi-class and picks the right averaging strategy.
|
|
368
|
+
|
|
369
|
+
```python
|
|
370
|
+
metrics = dp.classification_report(y_test, predictions)
|
|
371
|
+
# Returns: {'accuracy': 0.85, 'precision': 0.82, 'recall': 0.88, 'f1_score': 0.85}
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
### `dp.regression_report(y_true, y_pred)`
|
|
375
|
+
|
|
376
|
+
```python
|
|
377
|
+
metrics = dp.regression_report(y_test, predictions)
|
|
378
|
+
# Returns: {'mae': 2.14, 'mse': 7.32, 'rmse': 2.71, 'r2': 0.94, 'mape': 4.8, 'max_error': 8.3}
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
**Console Output:**
|
|
382
|
+
```
|
|
383
|
+
==================================================
|
|
384
|
+
DATAPILOT REGRESSION METRICS REPORT
|
|
385
|
+
==================================================
|
|
386
|
+
MAE (Mean Absolute Error) : 2.1400
|
|
387
|
+
MSE (Mean Squared Error) : 7.3200
|
|
388
|
+
RMSE (Root Mean Sq. Error) : 2.7055
|
|
389
|
+
R² (Coefficient of Det.) : 0.9400
|
|
390
|
+
MAPE (Mean Abs. % Error) : 4.80%
|
|
391
|
+
Max Error (Worst single pred.) : 8.3000
|
|
392
|
+
--------------------------------------------------
|
|
393
|
+
Verdict: ✅ EXCELLENT — model explains ≥90% of variance.
|
|
394
|
+
==================================================
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
### `dp.diagnose(train_score, test_score, metric_name="Accuracy")`
|
|
398
|
+
|
|
399
|
+
```python
|
|
400
|
+
dp.diagnose(train_score=0.98, test_score=0.72)
|
|
401
|
+
# → 🚨 OVERFITTING DETECTED: Add regularization, gather more data.
|
|
402
|
+
|
|
403
|
+
dp.diagnose(train_score=0.50, test_score=0.48)
|
|
404
|
+
# → ⚠️ UNDERFITTING DETECTED: Increase model complexity.
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
---
|
|
408
|
+
|
|
409
|
+
## Module 9: Standalone HTML Dashboard
|
|
410
|
+
|
|
411
|
+
### `dp.dashboard(df, output_path="datapilot_report.html")`
|
|
412
|
+
|
|
413
|
+
Generates a complete, **offline-ready** HTML report with:
|
|
414
|
+
- Summary metric cards (rows, columns, memory, duplicates, missing values)
|
|
415
|
+
- Data type overview table
|
|
416
|
+
- Missing values table + inline bar chart
|
|
417
|
+
- Pearson correlation pairs table
|
|
418
|
+
- Inline correlation heatmap image (base64 encoded — no external dependencies)
|
|
419
|
+
|
|
420
|
+
```python
|
|
421
|
+
dp.dashboard(df, output_path="my_project_report.html")
|
|
422
|
+
# → 🎉 Standalone HTML Dashboard successfully exported to: my_project_report.html
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
> ✅ **No internet required.** No backend server. Just open the `.html` file in any browser.
|
|
426
|
+
|
|
427
|
+
---
|
|
428
|
+
|
|
429
|
+
## Module 10: Performance Benchmark
|
|
430
|
+
|
|
431
|
+
### `dp.benchmark(df)`
|
|
432
|
+
|
|
433
|
+
Proves DataPilot's Polars-native speed advantage against equivalent Pandas operations.
|
|
434
|
+
|
|
435
|
+
```python
|
|
436
|
+
dp.benchmark(df)
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
**Console Output:**
|
|
440
|
+
```
|
|
441
|
+
==================================================================
|
|
442
|
+
DATAPILOT BENCHMARK — Polars vs Pandas
|
|
443
|
+
Dataset: 891 rows × 12 columns
|
|
444
|
+
==================================================================
|
|
445
|
+
Operation DataPilot Pandas Speedup
|
|
446
|
+
------------------------------------------------------------------
|
|
447
|
+
Null Count 0.09ms 0.48ms 5.3× ▓▓▓▓▓
|
|
448
|
+
Duplicate Detection 0.11ms 0.91ms 8.3× ▓▓▓▓▓▓▓▓
|
|
449
|
+
Describe / Summary Stats 0.22ms 1.47ms 6.7× ▓▓▓▓▓▓
|
|
450
|
+
Correlation Matrix 0.31ms 2.18ms 7.0× ▓▓▓▓▓▓▓
|
|
451
|
+
Group-By Mean 0.08ms 0.54ms 6.8× ▓▓▓▓▓▓
|
|
452
|
+
------------------------------------------------------------------
|
|
453
|
+
Average Speedup 6.8×
|
|
454
|
+
|
|
455
|
+
⚡ DataPilot is on average 6.8× faster than Pandas on this dataset.
|
|
456
|
+
📈 Speedup grows significantly on larger datasets (1M+ rows).
|
|
457
|
+
==================================================================
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
---
|
|
461
|
+
|
|
462
|
+
## Module 11: AI Copilot — 5 Providers
|
|
463
|
+
|
|
464
|
+
DataPilot uses a **Metadata-Only AI Pattern** — raw data rows are **never** transmitted to any provider. Only lightweight statistical summaries (e.g. `"Age has 19.8% nulls"`) are sent.
|
|
465
|
+
|
|
466
|
+
### Supported Providers
|
|
467
|
+
|
|
468
|
+
| Provider | Type | Default Model | Requires |
|
|
469
|
+
|----------|------|--------------|----------|
|
|
470
|
+
| `ollama` | 🔒 Local / Private | `llama3` | Ollama daemon running locally |
|
|
471
|
+
| `openai` | ☁️ Cloud | `gpt-4o-mini` | `pip install datapilot-polars[openai]` + API key |
|
|
472
|
+
| `gemini` | ☁️ Cloud | `gemini-1.5-flash` | `pip install datapilot-polars[gemini]` + API key |
|
|
473
|
+
| `claude` | ☁️ Cloud | `claude-3-haiku-20240307` | `pip install datapilot-polars[claude]` + API key |
|
|
474
|
+
| `groq` | ☁️ Cloud (free tier) | `llama3-70b-8192` | `pip install datapilot-polars[groq]` + API key |
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
### Usage
|
|
478
|
+
|
|
479
|
+
```python
|
|
480
|
+
# 🔒 Local — fully private, no API key needed (default)
|
|
481
|
+
dp.analyze(df, use_ai=True)
|
|
482
|
+
dp.analyze(df, use_ai=True, ai_provider="ollama", ai_model="mistral")
|
|
483
|
+
|
|
484
|
+
# ☁️ OpenAI — GPT-4o, GPT-4, GPT-3.5
|
|
485
|
+
dp.analyze(df, use_ai=True, ai_provider="openai", api_key="sk-...")
|
|
486
|
+
dp.analyze(df, use_ai=True, ai_provider="openai", ai_model="gpt-4o", api_key="sk-...")
|
|
487
|
+
|
|
488
|
+
# ☁️ Google Gemini — Gemini 1.5 Pro / Flash
|
|
489
|
+
dp.analyze(df, use_ai=True, ai_provider="gemini", api_key="AIza...")
|
|
490
|
+
dp.analyze(df, use_ai=True, ai_provider="gemini", ai_model="gemini-1.5-pro", api_key="AIza...")
|
|
491
|
+
|
|
492
|
+
# ☁️ Anthropic Claude — Claude 3.5 Sonnet / Haiku
|
|
493
|
+
dp.analyze(df, use_ai=True, ai_provider="claude", api_key="sk-ant-...")
|
|
494
|
+
dp.analyze(df, use_ai=True, ai_provider="claude", ai_model="claude-3-5-sonnet-20241022", api_key="sk-ant-...")
|
|
495
|
+
|
|
496
|
+
# ☁️ Groq — Ultra-fast free-tier inference (Llama3-70b, Mixtral, Gemma2)
|
|
497
|
+
dp.analyze(df, use_ai=True, ai_provider="groq", api_key="gsk_...")
|
|
498
|
+
dp.analyze(df, use_ai=True, ai_provider="groq", ai_model="mixtral-8x7b-32768", api_key="gsk_...")
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
### Install Only What You Need
|
|
502
|
+
|
|
503
|
+
```bash
|
|
504
|
+
pip install datapilot-polars[openai] # OpenAI only
|
|
505
|
+
pip install datapilot-polars[gemini] # Google Gemini only
|
|
506
|
+
pip install datapilot-polars[claude] # Anthropic Claude only
|
|
507
|
+
pip install datapilot-polars[groq] # Groq only (free tier)
|
|
508
|
+
pip install datapilot-polars[all-ai] # All cloud providers at once
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
### AI Output Example
|
|
512
|
+
|
|
513
|
+
```
|
|
514
|
+
🤖 AI Copilot Insights [GROQ]:
|
|
515
|
+
• The Age column has 19.8% missing values — impute with median before
|
|
516
|
+
training to avoid biased estimates in tree models.
|
|
517
|
+
• Sex and Embarked are unencoded strings — apply One-Hot Encoding;
|
|
518
|
+
Sex has only 2 values making it ideal for binary encoding.
|
|
519
|
+
• The strong positive correlation between Fare and Survived (r=0.697)
|
|
520
|
+
suggests Fare is a strong predictor — include it and check for
|
|
521
|
+
outliers before normalising.
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
> 💡 **Groq is recommended for getting started** — it has a generous free tier,
|
|
525
|
+
> runs Llama3-70b at extremely low latency, and requires just a free account at
|
|
526
|
+
> [console.groq.com](https://console.groq.com).
|
|
527
|
+
|
|
528
|
+
---
|
|
529
|
+
|
|
530
|
+
## Installation & Setup
|
|
531
|
+
|
|
532
|
+
### Basic Setup
|
|
533
|
+
|
|
534
|
+
```bash
|
|
535
|
+
git clone https://github.com/yourusername/datapilot.git
|
|
536
|
+
cd datapilot
|
|
537
|
+
|
|
538
|
+
uv venv
|
|
539
|
+
source .venv/bin/activate
|
|
540
|
+
uv pip install -e .
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
### With Cloud AI Providers
|
|
544
|
+
|
|
545
|
+
```bash
|
|
546
|
+
uv pip install -e .[openai] # Add OpenAI support
|
|
547
|
+
uv pip install -e .[groq] # Add Groq support (free)
|
|
548
|
+
uv pip install -e .[all-ai] # Add all cloud AI providers
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
### Development Setup (with tests)
|
|
552
|
+
|
|
553
|
+
```bash
|
|
554
|
+
uv pip install -e .[dev]
|
|
555
|
+
pytest
|
|
556
|
+
```
|
|
557
|
+
|
|
558
|
+
### Initializing Local AI (Ollama)
|
|
559
|
+
|
|
560
|
+
Only needed if you use `ai_provider="ollama"` (the default):
|
|
561
|
+
|
|
562
|
+
```bash
|
|
563
|
+
# Start the Ollama daemon
|
|
564
|
+
ollama serve
|
|
565
|
+
|
|
566
|
+
# Pull a model (first time only)
|
|
567
|
+
ollama pull llama3
|
|
568
|
+
```
|
|
569
|
+
|
|
570
|
+
---
|
|
571
|
+
|
|
572
|
+
## Troubleshooting
|
|
573
|
+
|
|
574
|
+
### `ModuleNotFoundError` after editing files
|
|
575
|
+
```bash
|
|
576
|
+
uv pip install -e . --force-reinstall
|
|
577
|
+
```
|
|
578
|
+
|
|
579
|
+
### AI: Ollama Connection Refused
|
|
580
|
+
```bash
|
|
581
|
+
ollama serve # make sure the Ollama daemon is running
|
|
582
|
+
```
|
|
583
|
+
|
|
584
|
+
### AI: Missing cloud provider package
|
|
585
|
+
```bash
|
|
586
|
+
# Install the extra for your chosen provider
|
|
587
|
+
pip install datapilot-polars[openai] # or gemini / claude / groq / all-ai
|
|
588
|
+
```
|
|
589
|
+
|
|
590
|
+
### AI: Invalid or missing API key
|
|
591
|
+
```python
|
|
592
|
+
# Always pass the key explicitly for cloud providers
|
|
593
|
+
dp.analyze(df, use_ai=True, ai_provider="openai", api_key="sk-...")
|
|
594
|
+
```
|
|
595
|
+
|
|
596
|
+
### Running Tests
|
|
597
|
+
```bash
|
|
598
|
+
pytest -v
|
|
599
|
+
pytest --cov=datapilot # with coverage report
|
|
600
|
+
```
|
|
601
|
+
|
|
602
|
+
---
|
|
603
|
+
|
|
604
|
+
## Contributing
|
|
605
|
+
|
|
606
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup, code style guidelines, and the pull request process.
|
|
607
|
+
|
|
608
|
+
---
|
|
609
|
+
|
|
610
|
+
## Changelog
|
|
611
|
+
|
|
612
|
+
See [CHANGELOG.md](CHANGELOG.md) for a full version history.
|
|
613
|
+
|
|
614
|
+
---
|
|
615
|
+
|
|
616
|
+
## License
|
|
617
|
+
|
|
618
|
+
MIT License — see [LICENSE](LICENSE) for details.
|