data-advisor 0.1.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.
@@ -0,0 +1,303 @@
1
+ Metadata-Version: 2.4
2
+ Name: data_advisor
3
+ Version: 0.1.0
4
+ Summary: A production-grade diagnostic and code generation advisor for timed data analysis exams and rapid exploratory data science.
5
+ Author: Principal Data Science Architect
6
+ License-Expression: MIT
7
+ Keywords: data-analysis,eda,data-science,hypothesis-testing,code-generation,machine-learning,automated-eda,pandas,scipy,scikit-learn
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Intended Audience :: Education
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
19
+ Classifier: Topic :: Software Development :: Code Generators
20
+ Requires-Python: >=3.9
21
+ Description-Content-Type: text/markdown
22
+ Requires-Dist: pandas>=2.0.0
23
+ Requires-Dist: numpy>=1.24.0
24
+ Requires-Dist: scipy>=1.10.0
25
+ Requires-Dist: scikit-learn>=1.2.0
26
+ Requires-Dist: matplotlib>=3.7.0
27
+ Requires-Dist: seaborn>=0.12.0
28
+ Provides-Extra: dev
29
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
30
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
31
+
32
+ # DataAdvisor (data_advisor)
33
+
34
+ > **Autonomous Data Science Diagnostic Engine & Exam Code Generator**
35
+ > Engineered for students, practitioners, and data scientists to audit unknown datasets, formulate statistical hypotheses, and generate copy-pasteable, production-ready Python pipelines during timed data analysis examinations.
36
+
37
+ ---
38
+
39
+ ## πŸš€ Key Highlights
40
+
41
+ 1. **Deterministic Auditing Engine**: Deeply profiles any `pd.DataFrame` (or CSV, TSV, Excel, Parquet file) in seconds.
42
+ 2. **Automated Hypothesis Testing**:
43
+ - Numeric vs. Numeric: **Pearson** & **Spearman** correlations with $p$-values.
44
+ - Categorical vs. Categorical: **Chi-Square Test of Independence** with CramΓ©r's V effect size.
45
+ - Numeric vs. Binary Target: **Welch's Two-Sample t-test** & **Mann-Whitney U test**.
46
+ - Numeric vs. Multi-class Target: **One-Way ANOVA** ($F$-test) & **Kruskal-Wallis $H$-test**.
47
+ 3. **Outlier & Skewness Diagnostics**: Combines **IQR fences (1.5Γ— and 3.0Γ—)** and **Z-score criteria ($|z| > 3$)**; automatically recommends `np.log1p`, Yeo-Johnson power transformations, or winsorization.
48
+ 4. **Target & Model Strategy Selector**: Automatically identifies whether the task is **Regression** or **Classification** (Binary or Multiclass), detects critical class imbalance, and selects baseline models (`LogisticRegression`, `Ridge`, `RandomForest`).
49
+ 5. **Copy-Pasteable Code Generator**: Emits clean, PEP 8 compliant, runnable Python scripts containing complete Pandas, Scipy, and Scikit-Learn code tailored to the audited dataset.
50
+
51
+ ---
52
+
53
+ ## πŸ“¦ Installation
54
+
55
+ To install `data_advisor` in editable mode directly from your local repository:
56
+
57
+ ```bash
58
+ # Navigate to the project root directory
59
+ cd "path/to/Custom Library"
60
+
61
+ # Install in editable mode with dependencies
62
+ pip install -e .
63
+ ```
64
+
65
+ ### Verified Dependencies
66
+ - Python `>= 3.9`
67
+ - `pandas >= 2.0.0`
68
+ - `numpy >= 1.24.0`
69
+ - `scipy >= 1.10.0`
70
+ - `scikit-learn >= 1.2.0`
71
+ - `matplotlib >= 3.7.0`
72
+ - `seaborn >= 0.12.0`
73
+
74
+ ---
75
+
76
+ ## ⚑ Quickstart: The 1-Line Exam Workflow
77
+
78
+ When handed an unfamiliar exam dataset (`exam_dataset.csv`), run the top-level `data_advisor` function in your Jupyter Notebook or Python terminal:
79
+
80
+ ```python
81
+ from data_advisor import data_advisor
82
+
83
+ # 1-Line Diagnostic & Code Generation:
84
+ # Outputs:
85
+ # 1. Full diagnostic report stating what all analysis to perform
86
+ # 2. Executable, copy-pasteable Python code to execute all steps
87
+ data_advisor("exam_dataset.csv")
88
+ ```
89
+
90
+ Or with an optional target column or output script:
91
+ ```python
92
+ data_advisor("exam_dataset.csv", target="churn", output_script="solution.py")
93
+ ```
94
+
95
+ You can also use the object-oriented API:
96
+ ```python
97
+ from data_advisor import DataAdvisor
98
+
99
+ advisor = DataAdvisor("exam_dataset.csv", target="churn", id_cols=["customer_id"])
100
+ advisor.report() # Diagnostic report
101
+ advisor.generate_script("solution.py") # Full Python script
102
+ clean_code = advisor.get_code_block("cleaning") # Specific stage code
103
+ ```
104
+
105
+ Or directly from your command-line terminal:
106
+ ```bash
107
+ # Diagnostic report + code prompt
108
+ data-advisor exam_dataset.csv
109
+
110
+ # Print complete executable Python code directly to the terminal
111
+ data-advisor exam_dataset.csv --code
112
+
113
+ # Save complete pipeline to a Python file
114
+ data-advisor exam_dataset.csv --output solution.py
115
+ ```
116
+
117
+ ---
118
+
119
+ ## πŸ” Instant Code Snippet Search: `search(key)`
120
+
121
+ `data_advisor` includes a search engine that searches **any keyword** across your own local code folder (`code_bank/`).
122
+
123
+ ### How It Works:
124
+ 1. **Your Folder**: Simply paste your custom Python scripts (`.py`), Jupyter Notebooks (`.ipynb`), Arduino/ESP32 sketches (`.ino`, `.cpp`), or text files into `code_bank/`.
125
+ 2. **Dynamic Scanning**: The search engine scans `code_bank/` in real time on every search callβ€”no indexing or restarts required. You can add, edit, or delete files anytime.
126
+ 3. **Any Keyword**: Search for single terms, phrases, or keyword lists.
127
+
128
+ ```python
129
+ from data_advisor import search
130
+
131
+ # 1. List all available snippets in your code_bank
132
+ search()
133
+
134
+ # 2. Search for any keyword (e.g., machine learning, IoT, algorithms)
135
+ search("linear regression")
136
+ search("dht22")
137
+ search("kmeans")
138
+ search("wokwi")
139
+
140
+ # 3. Search with multiple keywords or a list
141
+ search(["esp32", "temperature"])
142
+ search("decision tree, entropy")
143
+
144
+ # 4. Search within a custom directory
145
+ search("apriori", folder="my_other_codes")
146
+ ```
147
+
148
+ Or search directly via the CLI:
149
+ ```bash
150
+ # List all files currently in code_bank
151
+ data-advisor --search "list"
152
+
153
+ # Search for any keyword
154
+ data-advisor --search "linear regression"
155
+ data-advisor --search "wokwi"
156
+ ```
157
+
158
+ ---
159
+
160
+ ## πŸ“„ Complete File Viewing, Retrieval & Execution: `get_file()`, `read_file()`, `run_file()`
161
+
162
+ To retrieve or execute the **entire complete code file** from `code_bank/` (not just search snippets):
163
+
164
+ ### 1. View / Print Complete File
165
+ ```python
166
+ from data_advisor import get_file, view_file
167
+
168
+ # By question number:
169
+ get_file("q1") # Complete code for Question 1
170
+ get_file(24) # Complete code for Question 24
171
+ get_file("q32", line_numbers=True) # With line numbers
172
+
173
+ # By filename or keyword:
174
+ get_file("sketch.ino") # Arduino / ESP32 sketch
175
+ get_file("subscriber.py")
176
+ ```
177
+
178
+ ### 2. Retrieve Complete Raw Code String (No Printing)
179
+ ```python
180
+ from data_advisor import read_file
181
+
182
+ # Return complete raw code as a Python string
183
+ code_string = read_file("q24")
184
+ print(f"Loaded {len(code_string)} characters")
185
+ ```
186
+
187
+ ### 3. Run Any File Directly
188
+ ```python
189
+ from data_advisor import run_file
190
+
191
+ # Execute a Python file directly via subprocess
192
+ run_file("q24")
193
+ run_file("iss")
194
+ ```
195
+
196
+ ### 4. Direct CLI Commands
197
+ ```bash
198
+ # Print complete file to console
199
+ data-advisor --get q1
200
+ data-advisor -g q24 --line-numbers
201
+ data-advisor --get sketch.ino
202
+
203
+ # Execute script directly
204
+ data-advisor --run q24
205
+ data-advisor -r 14
206
+
207
+ # List all available code files
208
+ data-advisor --list
209
+ ```
210
+
211
+
212
+
213
+ ---
214
+
215
+ ## 🧠 Decision Rules Matrix
216
+
217
+ ### 1. Data Cleaning & Integrity Rules
218
+ | Condition | Severity | Recommended Action | Generated Code |
219
+ | :--- | :--- | :--- | :--- |
220
+ | **Duplicates Detected** (`> 0`) | `WARNING` / `CRITICAL` | Drop duplicate rows | `df = df.drop_duplicates().reset_index(drop=True)` |
221
+ | **High Missingness** (`>= 60%`) | `CRITICAL` | Drop column entirely | `df = df.drop(columns=[col])` |
222
+ | **Low Missingness** (`< 5%`) | `INFO` | Impute median (num) / mode (cat) | `df[col] = df[col].fillna(df[col].median())` |
223
+ | **Moderate Missingness** (`5% - 60%`) | `WARNING` | Skewed: Median; Symmetric: Mean | `SimpleImputer(strategy='median')` |
224
+ | **Constant Column** (variance = 0) | `CRITICAL` | Drop column | `df = df.drop(columns=[col])` |
225
+ | **Identifier Column** (IDs, hashes) | `WARNING` | Exclude from feature matrix $X$ | `X = df.drop(columns=[id_col])` |
226
+ | **Date String Column** | `RECOMMENDED` | Parse date & extract temporal features | `.dt.year`, `.dt.month`, `.dt.dayofweek` |
227
+
228
+ ### 2. Distribution & Outlier Rules
229
+ | Metric | Condition | Transformation Strategy | Rationale |
230
+ | :--- | :--- | :--- | :--- |
231
+ | **Skewness** | $> 1.2$ (Non-negative) | `np.log1p(df[col])` | Stabilizes variance, compresses long positive tail |
232
+ | **Skewness** | $> 1.2$ (Contains negatives) | `PowerTransformer(method='yeo-johnson')` | Normalizes non-Gaussian data with non-positive values |
233
+ | **Skewness** | $< -1.2$ (Left-skewed) | `PowerTransformer(method='yeo-johnson')` | Corrects severe left tail |
234
+ | **IQR Outliers** | $> 5\%$ of samples | IQR clipping / `RobustScaler()` | Caps extreme leverage points |
235
+
236
+ ### 3. Categorical Processing Rules
237
+ | Cardinality | Encoding Strategy | Implementation |
238
+ | :--- | :--- | :--- |
239
+ | **Binary** ($2$ levels) | Direct Binary Mapping ($0/1$) | `df[col].map({'No': 0, 'Yes': 1})` |
240
+ | **Low-to-Medium** ($3$ to $10$ levels) | One-Hot Encoding (`drop_first=True`) | `pd.get_dummies(..., drop_first=True, dtype=int)` |
241
+ | **High** ($> 10$ levels) | Frequency Encoding / Target Encoding | `df[col].map(df[col].value_counts(normalize=True))` |
242
+
243
+ ### 4. Hypothesis Testing Decision Engine
244
+ | Variable Types | Primary Test | Non-Parametric Alternative | Effect Size Metric |
245
+ | :--- | :--- | :--- | :--- |
246
+ | **2 Numeric Features** | Pearson Correlation ($r, p$) | Spearman Rank Correlation ($\rho, p$) | Correlation Coefficient ($r$) |
247
+ | **2 Categorical Features** | Chi-Square Test of Independence ($\chi^2$) | Fisher's Exact Test (for $2\times 2$) | CramΓ©r's $V$ |
248
+ | **1 Numeric + 1 Binary Cat** | Welch's Independent $t$-test | Mann-Whitney $U$ test | Cohen's $d$ / Rank-biserial |
249
+ | **1 Numeric + 1 Multi-class Cat** | One-Way ANOVA ($F, p$) | Kruskal-Wallis $H$-test | Eta-squared ($\eta^2$) |
250
+
251
+ ### 5. Target Variable & Model Baseline Matrix
252
+ | Target Type | Detected Problem | Imbalance Threshold | Recommended Baselines | Evaluation Metrics |
253
+ | :--- | :--- | :--- | :--- | :--- |
254
+ | **Continuous Numeric** | Regression | N/A | Linear Regression, Ridge ($L_2$), Random Forest Regressor | RMSE, MAE, $R^2$ Score |
255
+ | **Binary / Discrete** | Classification | Minority $< 20\%$ (Ratio $\ge 3:1$) | Logistic Regression (`class_weight='balanced'`), Random Forest Classifier | F1-Score, PR-AUC, ROC-AUC, Confusion Matrix |
256
+
257
+ ---
258
+
259
+ ## πŸ“‚ Project Architecture
260
+
261
+ ```
262
+ Custom Library/
263
+ β”œβ”€β”€ pyproject.toml # Modern setuptools packaging & dependency metadata
264
+ β”œβ”€β”€ README.md # Comprehensive library documentation & exam cheat sheet
265
+ β”œβ”€β”€ src/
266
+ β”‚ └── data_advisor/
267
+ β”‚ β”œβ”€β”€ __init__.py # Package exports (DataAdvisor, DataScanner, RuleEngine)
268
+ β”‚ β”œβ”€β”€ advisor.py # Primary facade class & CLI reporter
269
+ β”‚ β”œβ”€β”€ scanner.py # Core profiling engine & statistical test runner
270
+ β”‚ β”œβ”€β”€ rules.py # Heuristic recommendation engine & severity prioritizer
271
+ β”‚ β”œβ”€β”€ codegen.py # Sequential Python script & code block generator
272
+ β”‚ β”œβ”€β”€ visualizer.py # Publication-ready Matplotlib & Seaborn code generator
273
+ β”‚ └── cli.py # Command-line entry point (`data-advisor`)
274
+ β”œβ”€β”€ tests/
275
+ β”‚ └── test_advisor.py # Automated pytest suite covering regression & classification
276
+ └── examples/
277
+ β”œβ”€β”€ demo_exam_workflow.py # End-to-end exam simulation walkthrough
278
+ β”œβ”€β”€ student_exam_data.csv # Sample dataset with outliers, nulls, and duplicates
279
+ └── generated_analysis_pipeline.py # Fully generated, executable production script
280
+ ```
281
+
282
+ ---
283
+
284
+ ## πŸ§ͺ Running Tests
285
+
286
+ Run the test suite using `pytest`:
287
+
288
+ ```bash
289
+ python -m pytest -v
290
+ ```
291
+
292
+ All tests inspect and validate:
293
+ - Missing value audit & column dropping (>60%).
294
+ - Identifier and constant column detection.
295
+ - Skewness and IQR/Z-score outlier calculations.
296
+ - Parametric and non-parametric hypothesis testing.
297
+ - Target classification and regression auto-detection.
298
+ - Full end-to-end Python script code generation and execution.
299
+
300
+ ---
301
+
302
+ ## πŸ“œ License
303
+ MIT License. Built for rigorous data science education, competitive coding, and exam excellence.
@@ -0,0 +1,272 @@
1
+ # DataAdvisor (data_advisor)
2
+
3
+ > **Autonomous Data Science Diagnostic Engine & Exam Code Generator**
4
+ > Engineered for students, practitioners, and data scientists to audit unknown datasets, formulate statistical hypotheses, and generate copy-pasteable, production-ready Python pipelines during timed data analysis examinations.
5
+
6
+ ---
7
+
8
+ ## πŸš€ Key Highlights
9
+
10
+ 1. **Deterministic Auditing Engine**: Deeply profiles any `pd.DataFrame` (or CSV, TSV, Excel, Parquet file) in seconds.
11
+ 2. **Automated Hypothesis Testing**:
12
+ - Numeric vs. Numeric: **Pearson** & **Spearman** correlations with $p$-values.
13
+ - Categorical vs. Categorical: **Chi-Square Test of Independence** with CramΓ©r's V effect size.
14
+ - Numeric vs. Binary Target: **Welch's Two-Sample t-test** & **Mann-Whitney U test**.
15
+ - Numeric vs. Multi-class Target: **One-Way ANOVA** ($F$-test) & **Kruskal-Wallis $H$-test**.
16
+ 3. **Outlier & Skewness Diagnostics**: Combines **IQR fences (1.5Γ— and 3.0Γ—)** and **Z-score criteria ($|z| > 3$)**; automatically recommends `np.log1p`, Yeo-Johnson power transformations, or winsorization.
17
+ 4. **Target & Model Strategy Selector**: Automatically identifies whether the task is **Regression** or **Classification** (Binary or Multiclass), detects critical class imbalance, and selects baseline models (`LogisticRegression`, `Ridge`, `RandomForest`).
18
+ 5. **Copy-Pasteable Code Generator**: Emits clean, PEP 8 compliant, runnable Python scripts containing complete Pandas, Scipy, and Scikit-Learn code tailored to the audited dataset.
19
+
20
+ ---
21
+
22
+ ## πŸ“¦ Installation
23
+
24
+ To install `data_advisor` in editable mode directly from your local repository:
25
+
26
+ ```bash
27
+ # Navigate to the project root directory
28
+ cd "path/to/Custom Library"
29
+
30
+ # Install in editable mode with dependencies
31
+ pip install -e .
32
+ ```
33
+
34
+ ### Verified Dependencies
35
+ - Python `>= 3.9`
36
+ - `pandas >= 2.0.0`
37
+ - `numpy >= 1.24.0`
38
+ - `scipy >= 1.10.0`
39
+ - `scikit-learn >= 1.2.0`
40
+ - `matplotlib >= 3.7.0`
41
+ - `seaborn >= 0.12.0`
42
+
43
+ ---
44
+
45
+ ## ⚑ Quickstart: The 1-Line Exam Workflow
46
+
47
+ When handed an unfamiliar exam dataset (`exam_dataset.csv`), run the top-level `data_advisor` function in your Jupyter Notebook or Python terminal:
48
+
49
+ ```python
50
+ from data_advisor import data_advisor
51
+
52
+ # 1-Line Diagnostic & Code Generation:
53
+ # Outputs:
54
+ # 1. Full diagnostic report stating what all analysis to perform
55
+ # 2. Executable, copy-pasteable Python code to execute all steps
56
+ data_advisor("exam_dataset.csv")
57
+ ```
58
+
59
+ Or with an optional target column or output script:
60
+ ```python
61
+ data_advisor("exam_dataset.csv", target="churn", output_script="solution.py")
62
+ ```
63
+
64
+ You can also use the object-oriented API:
65
+ ```python
66
+ from data_advisor import DataAdvisor
67
+
68
+ advisor = DataAdvisor("exam_dataset.csv", target="churn", id_cols=["customer_id"])
69
+ advisor.report() # Diagnostic report
70
+ advisor.generate_script("solution.py") # Full Python script
71
+ clean_code = advisor.get_code_block("cleaning") # Specific stage code
72
+ ```
73
+
74
+ Or directly from your command-line terminal:
75
+ ```bash
76
+ # Diagnostic report + code prompt
77
+ data-advisor exam_dataset.csv
78
+
79
+ # Print complete executable Python code directly to the terminal
80
+ data-advisor exam_dataset.csv --code
81
+
82
+ # Save complete pipeline to a Python file
83
+ data-advisor exam_dataset.csv --output solution.py
84
+ ```
85
+
86
+ ---
87
+
88
+ ## πŸ” Instant Code Snippet Search: `search(key)`
89
+
90
+ `data_advisor` includes a search engine that searches **any keyword** across your own local code folder (`code_bank/`).
91
+
92
+ ### How It Works:
93
+ 1. **Your Folder**: Simply paste your custom Python scripts (`.py`), Jupyter Notebooks (`.ipynb`), Arduino/ESP32 sketches (`.ino`, `.cpp`), or text files into `code_bank/`.
94
+ 2. **Dynamic Scanning**: The search engine scans `code_bank/` in real time on every search callβ€”no indexing or restarts required. You can add, edit, or delete files anytime.
95
+ 3. **Any Keyword**: Search for single terms, phrases, or keyword lists.
96
+
97
+ ```python
98
+ from data_advisor import search
99
+
100
+ # 1. List all available snippets in your code_bank
101
+ search()
102
+
103
+ # 2. Search for any keyword (e.g., machine learning, IoT, algorithms)
104
+ search("linear regression")
105
+ search("dht22")
106
+ search("kmeans")
107
+ search("wokwi")
108
+
109
+ # 3. Search with multiple keywords or a list
110
+ search(["esp32", "temperature"])
111
+ search("decision tree, entropy")
112
+
113
+ # 4. Search within a custom directory
114
+ search("apriori", folder="my_other_codes")
115
+ ```
116
+
117
+ Or search directly via the CLI:
118
+ ```bash
119
+ # List all files currently in code_bank
120
+ data-advisor --search "list"
121
+
122
+ # Search for any keyword
123
+ data-advisor --search "linear regression"
124
+ data-advisor --search "wokwi"
125
+ ```
126
+
127
+ ---
128
+
129
+ ## πŸ“„ Complete File Viewing, Retrieval & Execution: `get_file()`, `read_file()`, `run_file()`
130
+
131
+ To retrieve or execute the **entire complete code file** from `code_bank/` (not just search snippets):
132
+
133
+ ### 1. View / Print Complete File
134
+ ```python
135
+ from data_advisor import get_file, view_file
136
+
137
+ # By question number:
138
+ get_file("q1") # Complete code for Question 1
139
+ get_file(24) # Complete code for Question 24
140
+ get_file("q32", line_numbers=True) # With line numbers
141
+
142
+ # By filename or keyword:
143
+ get_file("sketch.ino") # Arduino / ESP32 sketch
144
+ get_file("subscriber.py")
145
+ ```
146
+
147
+ ### 2. Retrieve Complete Raw Code String (No Printing)
148
+ ```python
149
+ from data_advisor import read_file
150
+
151
+ # Return complete raw code as a Python string
152
+ code_string = read_file("q24")
153
+ print(f"Loaded {len(code_string)} characters")
154
+ ```
155
+
156
+ ### 3. Run Any File Directly
157
+ ```python
158
+ from data_advisor import run_file
159
+
160
+ # Execute a Python file directly via subprocess
161
+ run_file("q24")
162
+ run_file("iss")
163
+ ```
164
+
165
+ ### 4. Direct CLI Commands
166
+ ```bash
167
+ # Print complete file to console
168
+ data-advisor --get q1
169
+ data-advisor -g q24 --line-numbers
170
+ data-advisor --get sketch.ino
171
+
172
+ # Execute script directly
173
+ data-advisor --run q24
174
+ data-advisor -r 14
175
+
176
+ # List all available code files
177
+ data-advisor --list
178
+ ```
179
+
180
+
181
+
182
+ ---
183
+
184
+ ## 🧠 Decision Rules Matrix
185
+
186
+ ### 1. Data Cleaning & Integrity Rules
187
+ | Condition | Severity | Recommended Action | Generated Code |
188
+ | :--- | :--- | :--- | :--- |
189
+ | **Duplicates Detected** (`> 0`) | `WARNING` / `CRITICAL` | Drop duplicate rows | `df = df.drop_duplicates().reset_index(drop=True)` |
190
+ | **High Missingness** (`>= 60%`) | `CRITICAL` | Drop column entirely | `df = df.drop(columns=[col])` |
191
+ | **Low Missingness** (`< 5%`) | `INFO` | Impute median (num) / mode (cat) | `df[col] = df[col].fillna(df[col].median())` |
192
+ | **Moderate Missingness** (`5% - 60%`) | `WARNING` | Skewed: Median; Symmetric: Mean | `SimpleImputer(strategy='median')` |
193
+ | **Constant Column** (variance = 0) | `CRITICAL` | Drop column | `df = df.drop(columns=[col])` |
194
+ | **Identifier Column** (IDs, hashes) | `WARNING` | Exclude from feature matrix $X$ | `X = df.drop(columns=[id_col])` |
195
+ | **Date String Column** | `RECOMMENDED` | Parse date & extract temporal features | `.dt.year`, `.dt.month`, `.dt.dayofweek` |
196
+
197
+ ### 2. Distribution & Outlier Rules
198
+ | Metric | Condition | Transformation Strategy | Rationale |
199
+ | :--- | :--- | :--- | :--- |
200
+ | **Skewness** | $> 1.2$ (Non-negative) | `np.log1p(df[col])` | Stabilizes variance, compresses long positive tail |
201
+ | **Skewness** | $> 1.2$ (Contains negatives) | `PowerTransformer(method='yeo-johnson')` | Normalizes non-Gaussian data with non-positive values |
202
+ | **Skewness** | $< -1.2$ (Left-skewed) | `PowerTransformer(method='yeo-johnson')` | Corrects severe left tail |
203
+ | **IQR Outliers** | $> 5\%$ of samples | IQR clipping / `RobustScaler()` | Caps extreme leverage points |
204
+
205
+ ### 3. Categorical Processing Rules
206
+ | Cardinality | Encoding Strategy | Implementation |
207
+ | :--- | :--- | :--- |
208
+ | **Binary** ($2$ levels) | Direct Binary Mapping ($0/1$) | `df[col].map({'No': 0, 'Yes': 1})` |
209
+ | **Low-to-Medium** ($3$ to $10$ levels) | One-Hot Encoding (`drop_first=True`) | `pd.get_dummies(..., drop_first=True, dtype=int)` |
210
+ | **High** ($> 10$ levels) | Frequency Encoding / Target Encoding | `df[col].map(df[col].value_counts(normalize=True))` |
211
+
212
+ ### 4. Hypothesis Testing Decision Engine
213
+ | Variable Types | Primary Test | Non-Parametric Alternative | Effect Size Metric |
214
+ | :--- | :--- | :--- | :--- |
215
+ | **2 Numeric Features** | Pearson Correlation ($r, p$) | Spearman Rank Correlation ($\rho, p$) | Correlation Coefficient ($r$) |
216
+ | **2 Categorical Features** | Chi-Square Test of Independence ($\chi^2$) | Fisher's Exact Test (for $2\times 2$) | CramΓ©r's $V$ |
217
+ | **1 Numeric + 1 Binary Cat** | Welch's Independent $t$-test | Mann-Whitney $U$ test | Cohen's $d$ / Rank-biserial |
218
+ | **1 Numeric + 1 Multi-class Cat** | One-Way ANOVA ($F, p$) | Kruskal-Wallis $H$-test | Eta-squared ($\eta^2$) |
219
+
220
+ ### 5. Target Variable & Model Baseline Matrix
221
+ | Target Type | Detected Problem | Imbalance Threshold | Recommended Baselines | Evaluation Metrics |
222
+ | :--- | :--- | :--- | :--- | :--- |
223
+ | **Continuous Numeric** | Regression | N/A | Linear Regression, Ridge ($L_2$), Random Forest Regressor | RMSE, MAE, $R^2$ Score |
224
+ | **Binary / Discrete** | Classification | Minority $< 20\%$ (Ratio $\ge 3:1$) | Logistic Regression (`class_weight='balanced'`), Random Forest Classifier | F1-Score, PR-AUC, ROC-AUC, Confusion Matrix |
225
+
226
+ ---
227
+
228
+ ## πŸ“‚ Project Architecture
229
+
230
+ ```
231
+ Custom Library/
232
+ β”œβ”€β”€ pyproject.toml # Modern setuptools packaging & dependency metadata
233
+ β”œβ”€β”€ README.md # Comprehensive library documentation & exam cheat sheet
234
+ β”œβ”€β”€ src/
235
+ β”‚ └── data_advisor/
236
+ β”‚ β”œβ”€β”€ __init__.py # Package exports (DataAdvisor, DataScanner, RuleEngine)
237
+ β”‚ β”œβ”€β”€ advisor.py # Primary facade class & CLI reporter
238
+ β”‚ β”œβ”€β”€ scanner.py # Core profiling engine & statistical test runner
239
+ β”‚ β”œβ”€β”€ rules.py # Heuristic recommendation engine & severity prioritizer
240
+ β”‚ β”œβ”€β”€ codegen.py # Sequential Python script & code block generator
241
+ β”‚ β”œβ”€β”€ visualizer.py # Publication-ready Matplotlib & Seaborn code generator
242
+ β”‚ └── cli.py # Command-line entry point (`data-advisor`)
243
+ β”œβ”€β”€ tests/
244
+ β”‚ └── test_advisor.py # Automated pytest suite covering regression & classification
245
+ └── examples/
246
+ β”œβ”€β”€ demo_exam_workflow.py # End-to-end exam simulation walkthrough
247
+ β”œβ”€β”€ student_exam_data.csv # Sample dataset with outliers, nulls, and duplicates
248
+ └── generated_analysis_pipeline.py # Fully generated, executable production script
249
+ ```
250
+
251
+ ---
252
+
253
+ ## πŸ§ͺ Running Tests
254
+
255
+ Run the test suite using `pytest`:
256
+
257
+ ```bash
258
+ python -m pytest -v
259
+ ```
260
+
261
+ All tests inspect and validate:
262
+ - Missing value audit & column dropping (>60%).
263
+ - Identifier and constant column detection.
264
+ - Skewness and IQR/Z-score outlier calculations.
265
+ - Parametric and non-parametric hypothesis testing.
266
+ - Target classification and regression auto-detection.
267
+ - Full end-to-end Python script code generation and execution.
268
+
269
+ ---
270
+
271
+ ## πŸ“œ License
272
+ MIT License. Built for rigorous data science education, competitive coding, and exam excellence.
@@ -0,0 +1,65 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "data_advisor"
7
+ version = "0.1.0"
8
+ description = "A production-grade diagnostic and code generation advisor for timed data analysis exams and rapid exploratory data science."
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = "MIT"
12
+ authors = [
13
+ { name = "Principal Data Science Architect" }
14
+ ]
15
+ keywords = [
16
+ "data-analysis",
17
+ "eda",
18
+ "data-science",
19
+ "hypothesis-testing",
20
+ "code-generation",
21
+ "machine-learning",
22
+ "automated-eda",
23
+ "pandas",
24
+ "scipy",
25
+ "scikit-learn"
26
+ ]
27
+ classifiers = [
28
+ "Development Status :: 4 - Beta",
29
+ "Intended Audience :: Developers",
30
+ "Intended Audience :: Education",
31
+ "Intended Audience :: Science/Research",
32
+ "Programming Language :: Python :: 3",
33
+ "Programming Language :: Python :: 3.9",
34
+ "Programming Language :: Python :: 3.10",
35
+ "Programming Language :: Python :: 3.11",
36
+ "Programming Language :: Python :: 3.12",
37
+ "Programming Language :: Python :: 3.13",
38
+ "Topic :: Scientific/Engineering :: Information Analysis",
39
+ "Topic :: Software Development :: Code Generators"
40
+ ]
41
+ dependencies = [
42
+ "pandas>=2.0.0",
43
+ "numpy>=1.24.0",
44
+ "scipy>=1.10.0",
45
+ "scikit-learn>=1.2.0",
46
+ "matplotlib>=3.7.0",
47
+ "seaborn>=0.12.0"
48
+ ]
49
+
50
+ [project.optional-dependencies]
51
+ dev = [
52
+ "pytest>=7.0.0",
53
+ "pytest-cov>=4.0.0"
54
+ ]
55
+
56
+ [project.scripts]
57
+ data-advisor = "data_advisor.cli:main"
58
+
59
+ [tool.setuptools.packages.find]
60
+ where = ["src"]
61
+
62
+ [tool.pytest.ini_options]
63
+ testpaths = ["tests"]
64
+ python_files = ["test_*.py"]
65
+ addopts = "-p no:anyio"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,38 @@
1
+ """
2
+ data_advisor - Production-grade diagnostic advisor and code generator for data science examinations.
3
+ """
4
+
5
+ from data_advisor.advisor import DataAdvisor, data_advisor
6
+ from data_advisor.codegen import CodeGenerator
7
+ from data_advisor.rules import Recommendation, RuleEngine
8
+ from data_advisor.scanner import DataScanner, load_dataset
9
+ from data_advisor.search import (
10
+ CodeSearchEngine,
11
+ get_file,
12
+ list_files,
13
+ read_file,
14
+ run_file,
15
+ search,
16
+ view_file,
17
+ )
18
+ from data_advisor.visualizer import VisualizationAdvisor
19
+
20
+ __version__ = "0.1.0"
21
+ __all__ = [
22
+ "data_advisor",
23
+ "DataAdvisor",
24
+ "DataScanner",
25
+ "RuleEngine",
26
+ "CodeGenerator",
27
+ "VisualizationAdvisor",
28
+ "Recommendation",
29
+ "CodeSearchEngine",
30
+ "search",
31
+ "get_file",
32
+ "read_file",
33
+ "view_file",
34
+ "run_file",
35
+ "list_files",
36
+ "load_dataset",
37
+ "__version__",
38
+ ]
@@ -0,0 +1,9 @@
1
+ """
2
+ __main__.py - Entry point when running data_advisor as a module: python -m data_advisor
3
+ """
4
+
5
+ import sys
6
+ from data_advisor.cli import main
7
+
8
+ if __name__ == "__main__":
9
+ sys.exit(main())