intelaish 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.
- intelaish-0.1.0/PKG-INFO +15 -0
- intelaish-0.1.0/README.md +0 -0
- intelaish-0.1.0/intelaish/__init__.py +9 -0
- intelaish-0.1.0/intelaish/cleaning.py +69 -0
- intelaish-0.1.0/intelaish/explain.py +66 -0
- intelaish-0.1.0/intelaish/ingestion.py +33 -0
- intelaish-0.1.0/intelaish/insights.py +98 -0
- intelaish-0.1.0/intelaish/models.py +75 -0
- intelaish-0.1.0/intelaish/sql_engine.py +56 -0
- intelaish-0.1.0/intelaish/visuals.py +91 -0
- intelaish-0.1.0/intelaish.egg-info/PKG-INFO +15 -0
- intelaish-0.1.0/intelaish.egg-info/SOURCES.txt +15 -0
- intelaish-0.1.0/intelaish.egg-info/dependency_links.txt +1 -0
- intelaish-0.1.0/intelaish.egg-info/requires.txt +9 -0
- intelaish-0.1.0/intelaish.egg-info/top_level.txt +1 -0
- intelaish-0.1.0/pyproject.toml +21 -0
- intelaish-0.1.0/setup.cfg +4 -0
intelaish-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: intelaish
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Next-generation automated EDA, cleaning, and AI insights.
|
|
5
|
+
Requires-Python: >=3.8
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: pandas>=2.0.0
|
|
8
|
+
Requires-Dist: numpy>=1.24.0
|
|
9
|
+
Requires-Dist: plotly>=5.14.0
|
|
10
|
+
Requires-Dist: scikit-learn>=1.2.0
|
|
11
|
+
Requires-Dist: google-genai>=0.2.0
|
|
12
|
+
Requires-Dist: rich>=13.0.0
|
|
13
|
+
Requires-Dist: statsmodels>=0.14.0
|
|
14
|
+
Requires-Dist: shap>=0.42.0
|
|
15
|
+
Requires-Dist: matplotlib>=3.7.0
|
|
File without changes
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
from .ingestion import smart_read
|
|
2
|
+
from .cleaning import smart_clean
|
|
3
|
+
from .visuals import smart_viz, advanced_viz
|
|
4
|
+
from .insights import SmartInsights
|
|
5
|
+
from .models import problem_card
|
|
6
|
+
from .explain import explain_model
|
|
7
|
+
from .sql_engine import SQLBridge
|
|
8
|
+
|
|
9
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
import numpy as np
|
|
3
|
+
from rich.console import Console
|
|
4
|
+
from rich.table import Table
|
|
5
|
+
|
|
6
|
+
console = Console()
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def smart_clean(df: pd.DataFrame, target: str = None, outlier_strategy: str = "iqr") -> pd.DataFrame:
|
|
10
|
+
"""
|
|
11
|
+
Automatically detects and fixes missing values and outliers in a DataFrame.
|
|
12
|
+
Skips outlier detection for the specified target variable to prevent data destruction.
|
|
13
|
+
"""
|
|
14
|
+
cleaned_df = df.copy()
|
|
15
|
+
console.print(
|
|
16
|
+
"\n[bold blue]๐งน Starting Intelligent Data Cleaning Engine (Robust IQR)...[/bold blue]")
|
|
17
|
+
actions = []
|
|
18
|
+
|
|
19
|
+
for col in cleaned_df.columns:
|
|
20
|
+
# 1. Handle Missing Values (We still want to fill missing target values if they exist)
|
|
21
|
+
missing_count = cleaned_df[col].isnull().sum()
|
|
22
|
+
if missing_count > 0:
|
|
23
|
+
if cleaned_df[col].dtype in ['int64', 'float64']:
|
|
24
|
+
fill_val = cleaned_df[col].median()
|
|
25
|
+
cleaned_df[col] = cleaned_df[col].fillna(fill_val)
|
|
26
|
+
actions.append({"Column": col, "Issue": "Missing Values",
|
|
27
|
+
"Action": f"Filled {missing_count} rows with Median ({fill_val})"})
|
|
28
|
+
else:
|
|
29
|
+
fill_val = cleaned_df[col].mode()[0]
|
|
30
|
+
cleaned_df[col] = cleaned_df[col].fillna(fill_val)
|
|
31
|
+
actions.append({"Column": col, "Issue": "Missing Values",
|
|
32
|
+
"Action": f"Filled {missing_count} rows with Mode ('{fill_val}')"})
|
|
33
|
+
|
|
34
|
+
# 2. Handle Outliers using IQR (SKIP if it is the target variable!)
|
|
35
|
+
if cleaned_df[col].dtype in ['int64', 'float64'] and col != target:
|
|
36
|
+
Q1 = cleaned_df[col].quantile(0.25)
|
|
37
|
+
Q3 = cleaned_df[col].quantile(0.75)
|
|
38
|
+
IQR = Q3 - Q1
|
|
39
|
+
|
|
40
|
+
# Avoid divide by zero/zero variance issues
|
|
41
|
+
if IQR > 0:
|
|
42
|
+
lower_bound = Q1 - 1.5 * IQR
|
|
43
|
+
upper_bound = Q3 + 1.5 * IQR
|
|
44
|
+
|
|
45
|
+
outliers = (cleaned_df[col] < lower_bound) | (
|
|
46
|
+
cleaned_df[col] > upper_bound)
|
|
47
|
+
outlier_count = outliers.sum()
|
|
48
|
+
|
|
49
|
+
if outlier_count > 0:
|
|
50
|
+
cleaned_df[col] = np.clip(
|
|
51
|
+
cleaned_df[col], lower_bound, upper_bound)
|
|
52
|
+
actions.append({"Column": col, "Issue": "Outliers Detected",
|
|
53
|
+
"Action": f"Capped {outlier_count} values using IQR Bounds"})
|
|
54
|
+
|
|
55
|
+
# Print summary layout
|
|
56
|
+
if actions:
|
|
57
|
+
table = Table(title="โจ intelguruai Cleaning Summary",
|
|
58
|
+
show_header=True, header_style="bold magenta")
|
|
59
|
+
table.add_column("Column Name", style="cyan")
|
|
60
|
+
table.add_column("Issue Found", style="yellow")
|
|
61
|
+
table.add_column("Action Taken", style="green")
|
|
62
|
+
|
|
63
|
+
for act in actions:
|
|
64
|
+
table.add_row(act["Column"], act["Issue"], act["Action"])
|
|
65
|
+
console.print(table)
|
|
66
|
+
else:
|
|
67
|
+
console.print("[bold green]๐ Dataset is already clean![/bold green]")
|
|
68
|
+
|
|
69
|
+
return cleaned_df
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
import shap
|
|
3
|
+
import matplotlib.pyplot as plt
|
|
4
|
+
from sklearn.ensemble import RandomForestClassifier, RandomForestRegressor
|
|
5
|
+
from sklearn.preprocessing import LabelEncoder
|
|
6
|
+
from rich.console import Console
|
|
7
|
+
|
|
8
|
+
console = Console()
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def explain_model(df: pd.DataFrame, target: str, is_classification: bool = True):
|
|
12
|
+
"""
|
|
13
|
+
Trains a baseline model and uses SHAP values to explain feature importance,
|
|
14
|
+
acting as a foundation for bias detection and model interpretability.
|
|
15
|
+
"""
|
|
16
|
+
console.print(
|
|
17
|
+
f"\n[bold magenta]๐ Launching Interpretability & Bias Detection Engine...[/bold magenta]")
|
|
18
|
+
|
|
19
|
+
# 1. Prepare data (Drop NaNs for the background model)
|
|
20
|
+
df_clean = df.dropna().copy()
|
|
21
|
+
if target not in df_clean.columns:
|
|
22
|
+
console.print(f"[bold red]โ Target '{target}' not found.[/bold red]")
|
|
23
|
+
return
|
|
24
|
+
|
|
25
|
+
X = df_clean.drop(columns=[target])
|
|
26
|
+
y = df_clean[target]
|
|
27
|
+
|
|
28
|
+
# 2. Encode categorical variables for the model
|
|
29
|
+
for col in X.select_dtypes(include=['object', 'category']).columns:
|
|
30
|
+
X[col] = LabelEncoder().fit_transform(X[col].astype(str))
|
|
31
|
+
|
|
32
|
+
if y.dtype == 'object' or str(y.dtype) == 'category':
|
|
33
|
+
y = LabelEncoder().fit_transform(y.astype(str))
|
|
34
|
+
|
|
35
|
+
# 3. Train the baseline model
|
|
36
|
+
model = RandomForestClassifier(
|
|
37
|
+
random_state=42) if is_classification else RandomForestRegressor(random_state=42)
|
|
38
|
+
model.fit(X, y)
|
|
39
|
+
|
|
40
|
+
# 4. Calculate SHAP values for interpretability
|
|
41
|
+
console.print(
|
|
42
|
+
"[bold cyan]โ๏ธ Calculating SHAP values for feature importance...[/bold cyan]")
|
|
43
|
+
explainer = shap.TreeExplainer(model)
|
|
44
|
+
|
|
45
|
+
# Use a sample if the dataset is massive to save time
|
|
46
|
+
X_sample = X.sample(min(len(X), 500)) if len(X) > 500 else X
|
|
47
|
+
shap_values = explainer.shap_values(X_sample)
|
|
48
|
+
|
|
49
|
+
# 5. Render the plot
|
|
50
|
+
console.print("[bold green]โ
SHAP Summary Plot Generated![/bold green]")
|
|
51
|
+
|
|
52
|
+
if is_classification and isinstance(shap_values, list):
|
|
53
|
+
shap.summary_plot(shap_values[1], X_sample, show=False)
|
|
54
|
+
else:
|
|
55
|
+
shap.summary_plot(shap_values, X_sample, show=False)
|
|
56
|
+
|
|
57
|
+
plt.title(f"Feature Importance & Bias Check for '{target}'")
|
|
58
|
+
plt.tight_layout()
|
|
59
|
+
|
|
60
|
+
# Save the file instead of blocking the terminal
|
|
61
|
+
file_name = f"shap_summary_{target}.png"
|
|
62
|
+
plt.savefig(file_name, bbox_inches='tight', dpi=300, facecolor='white')
|
|
63
|
+
plt.close()
|
|
64
|
+
|
|
65
|
+
console.print(
|
|
66
|
+
f"[bold green]โ
SHAP Summary Plot saved to your folder as '{file_name}'![/bold green]")
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
from rich.console import Console
|
|
3
|
+
from rich.panel import Panel
|
|
4
|
+
|
|
5
|
+
console = Console()
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def smart_read(file_path: str) -> pd.DataFrame:
|
|
9
|
+
"""
|
|
10
|
+
Reads a CSV file, prints a beautiful summary to the console,
|
|
11
|
+
and returns a pandas DataFrame.
|
|
12
|
+
"""
|
|
13
|
+
console.print(
|
|
14
|
+
f"[bold green]โณ Loading dataset from:[/bold green] {file_path}")
|
|
15
|
+
|
|
16
|
+
try:
|
|
17
|
+
# Load the data
|
|
18
|
+
df = pd.read_csv(file_path)
|
|
19
|
+
|
|
20
|
+
# Print a beautiful confirmation panel
|
|
21
|
+
console.print(Panel(
|
|
22
|
+
f"[bold green]โ
Successfully Loaded![/bold green]\n\n"
|
|
23
|
+
f"๐ [bold]Rows:[/bold] {df.shape[0]} | [bold]Columns:[/bold] {df.shape[1]}\n"
|
|
24
|
+
f"๐พ [bold]Memory Usage:[/bold] {df.memory_usage(deep=True).sum() / 1024**2:.2f} MB",
|
|
25
|
+
title="intelguruai Ingestion Engine",
|
|
26
|
+
expand=False
|
|
27
|
+
))
|
|
28
|
+
|
|
29
|
+
return df
|
|
30
|
+
|
|
31
|
+
except Exception as e:
|
|
32
|
+
console.print(f"[bold red]โ Error loading file:[/bold red] {str(e)}")
|
|
33
|
+
raise e
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
import json
|
|
3
|
+
from google import genai
|
|
4
|
+
from rich.console import Console
|
|
5
|
+
from rich.panel import Panel
|
|
6
|
+
|
|
7
|
+
console = Console()
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class SmartInsights:
|
|
11
|
+
def __init__(self, api_key: str = None):
|
|
12
|
+
"""
|
|
13
|
+
Initializes the AI insight engine. If an API key is provided,
|
|
14
|
+
it prepares the modern Gemini client. Otherwise, it uses local statistical heuristics.
|
|
15
|
+
"""
|
|
16
|
+
self.api_key = api_key
|
|
17
|
+
if api_key:
|
|
18
|
+
try:
|
|
19
|
+
# Upgraded Initialization: Using the new unified SDK client
|
|
20
|
+
self.client = genai.Client(api_key=api_key)
|
|
21
|
+
self.ai_enabled = True
|
|
22
|
+
except Exception as e:
|
|
23
|
+
console.print(
|
|
24
|
+
f"[bold yellow]โ ๏ธ Failed to initialize Gemini API. Error: {e}[/bold yellow]")
|
|
25
|
+
self.ai_enabled = False
|
|
26
|
+
else:
|
|
27
|
+
self.ai_enabled = False
|
|
28
|
+
|
|
29
|
+
def generate_profile(self, df: pd.DataFrame, target_col: str = None) -> str:
|
|
30
|
+
"""
|
|
31
|
+
Analyzes the dataset and returns data insights.
|
|
32
|
+
"""
|
|
33
|
+
console.print(
|
|
34
|
+
"\n[bold brain]๐ง Extracting Smart Insights...[/bold brain]")
|
|
35
|
+
|
|
36
|
+
# 1. Compute Local Statistical Metadata (Preserves Data Privacy)
|
|
37
|
+
summary_stats = {
|
|
38
|
+
"total_rows": int(df.shape[0]),
|
|
39
|
+
"total_columns": int(df.shape[1]),
|
|
40
|
+
"numeric_columns_analysis": {},
|
|
41
|
+
"target_variable": target_col
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
for col in df.select_dtypes(include=['int64', 'float64']).columns:
|
|
45
|
+
summary_stats["numeric_columns_analysis"][col] = {
|
|
46
|
+
"mean": float(df[col].mean()),
|
|
47
|
+
"skewness": float(df[col].skew()),
|
|
48
|
+
"correlation_with_target": float(df[col].corr(df[target_col])) if target_col and target_col in df.columns and col != target_col else None
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
# 2. Path A: Generate Contextual AI Insights via LLM
|
|
52
|
+
if self.ai_enabled:
|
|
53
|
+
prompt = f"""
|
|
54
|
+
Act as an elite Data Scientist and ML Engineer. I have calculated summary statistics for a processed dataset:
|
|
55
|
+
{json.dumps(summary_stats, indent=2)}
|
|
56
|
+
|
|
57
|
+
Provide an executive summary highlighting key data patterns, unexpected distributions, and strategic recommendations for building a predictive model.
|
|
58
|
+
Keep it clear, impactful, and under 4 sentences. Do not mention JSON or raw code.
|
|
59
|
+
"""
|
|
60
|
+
try:
|
|
61
|
+
# Upgraded Generation Method: Accessed via client.models
|
|
62
|
+
response = self.client.models.generate_content(
|
|
63
|
+
model='gemini-2.5-flash',
|
|
64
|
+
contents=prompt
|
|
65
|
+
)
|
|
66
|
+
insight_text = response.text.strip()
|
|
67
|
+
self._display_panel(
|
|
68
|
+
insight_text, title="๐ค AI-Generated Strategic Insights")
|
|
69
|
+
return insight_text
|
|
70
|
+
except Exception as e:
|
|
71
|
+
console.print(
|
|
72
|
+
f"[bold red]โ LLM Generation failed: {e}. Defaulting to rule engine.[/bold red]")
|
|
73
|
+
|
|
74
|
+
# 3. Path B: Fallback Local Statistical Heuristics (Zero-Cost, Offline)
|
|
75
|
+
fallback_insights = []
|
|
76
|
+
for col, metrics in summary_stats["numeric_columns_analysis"].items():
|
|
77
|
+
if abs(metrics["skewness"]) > 1.0:
|
|
78
|
+
fallback_insights.append(
|
|
79
|
+
f"โข [bold cyan]{col}[/bold cyan] shows high distribution skewness ({metrics['skewness']:.2f}). Consider a log transform.")
|
|
80
|
+
if metrics["correlation_with_target"] and abs(metrics["correlation_with_target"]) > 0.5:
|
|
81
|
+
fallback_insights.append(
|
|
82
|
+
f"โข Strong linear relationship detected between [bold cyan]{col}[/bold cyan] and target ({metrics['correlation_with_target']:.2f}).")
|
|
83
|
+
|
|
84
|
+
if not fallback_insights:
|
|
85
|
+
fallback_insights.append(
|
|
86
|
+
"โข Columns show highly stable distributions. Data is well-structured for baseline estimators.")
|
|
87
|
+
|
|
88
|
+
insight_text = "\n".join(fallback_insights)
|
|
89
|
+
self._display_panel(insight_text, title="๐ Local Statistical Insights")
|
|
90
|
+
return insight_text
|
|
91
|
+
|
|
92
|
+
def _display_panel(self, text: str, title: str):
|
|
93
|
+
console.print(Panel(
|
|
94
|
+
text,
|
|
95
|
+
title=title,
|
|
96
|
+
border_style="purple",
|
|
97
|
+
expand=False
|
|
98
|
+
))
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
from rich.console import Console
|
|
3
|
+
from rich.panel import Panel
|
|
4
|
+
|
|
5
|
+
console = Console()
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def problem_card(df: pd.DataFrame, target: str):
|
|
9
|
+
"""
|
|
10
|
+
Analyzes the target variable to determine the ML problem type (Classification/Regression),
|
|
11
|
+
checks for class imbalances, and recommends baseline machine learning models.
|
|
12
|
+
"""
|
|
13
|
+
console.print(
|
|
14
|
+
f"\n[bold yellow]๐ฏ Generating ML Problem Card for target: '{target}'[/bold yellow]")
|
|
15
|
+
|
|
16
|
+
if target not in df.columns:
|
|
17
|
+
console.print(
|
|
18
|
+
f"[bold red]โ Error: Target column '{target}' not found in dataset.[/bold red]")
|
|
19
|
+
return
|
|
20
|
+
|
|
21
|
+
target_data = df[target]
|
|
22
|
+
unique_vals = target_data.nunique()
|
|
23
|
+
dtype = target_data.dtype
|
|
24
|
+
|
|
25
|
+
# 1. Determine Problem Type Heuristics
|
|
26
|
+
problem_type = "Unknown"
|
|
27
|
+
recommended_models = []
|
|
28
|
+
imbalance_warning = ""
|
|
29
|
+
|
|
30
|
+
# If it's numeric and has a wide spread of unique values, it's likely Regression
|
|
31
|
+
if dtype in ['int64', 'float64'] and unique_vals > 15:
|
|
32
|
+
problem_type = "Regression ๐"
|
|
33
|
+
recommended_models = [
|
|
34
|
+
"Linear Regression (Baseline)",
|
|
35
|
+
"Random Forest Regressor (Non-linear)",
|
|
36
|
+
"XGBoost Regressor (Advanced)"
|
|
37
|
+
]
|
|
38
|
+
imbalance_warning = "[bold green]โน๏ธ Continuous target detected. Class imbalance does not apply.[/bold green]"
|
|
39
|
+
|
|
40
|
+
# Otherwise, it's Classification
|
|
41
|
+
else:
|
|
42
|
+
problem_type = "Classification ๐๏ธ"
|
|
43
|
+
recommended_models = [
|
|
44
|
+
"Logistic Regression (Baseline)",
|
|
45
|
+
"Random Forest Classifier (Robust)",
|
|
46
|
+
"Gradient Boosting / LightGBM (Advanced)"
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
# 2. Check for Class Imbalance (Crucial ML step)
|
|
50
|
+
value_counts = target_data.value_counts(normalize=True)
|
|
51
|
+
min_class_ratio = value_counts.min()
|
|
52
|
+
|
|
53
|
+
if min_class_ratio < 0.2: # If the smallest class makes up less than 20% of data
|
|
54
|
+
imbalance_warning = f"[bold red]โ ๏ธ Warning: Severe Class Imbalance Detected![/bold red]\n Smallest class is only {min_class_ratio*100:.1f}% of the dataset.\n Consider SMOTE, oversampling, or class weighting before training."
|
|
55
|
+
else:
|
|
56
|
+
imbalance_warning = f"[bold green]โ
Class distribution is relatively balanced. Safe to proceed.[/bold green]"
|
|
57
|
+
|
|
58
|
+
# 3. Build and Display the UI Panel
|
|
59
|
+
report = (
|
|
60
|
+
f"[bold]Target Variable:[/bold] {target}\n"
|
|
61
|
+
f"[bold]Problem Type Detected:[/bold] {problem_type}\n"
|
|
62
|
+
f"[bold]Unique Classes/Values:[/bold] {unique_vals}\n\n"
|
|
63
|
+
f"{imbalance_warning}\n\n"
|
|
64
|
+
f"[bold cyan]๐ค Recommended ML Models:[/bold cyan]\n"
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
for i, model in enumerate(recommended_models, 1):
|
|
68
|
+
report += f" {i}. {model}\n"
|
|
69
|
+
|
|
70
|
+
console.print(Panel(
|
|
71
|
+
report,
|
|
72
|
+
title="๐ intelguruai ML Problem Card",
|
|
73
|
+
border_style="yellow",
|
|
74
|
+
expand=False
|
|
75
|
+
))
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
from google import genai
|
|
3
|
+
from rich.console import Console
|
|
4
|
+
from rich.panel import Panel
|
|
5
|
+
|
|
6
|
+
console = Console()
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class SQLBridge:
|
|
10
|
+
def __init__(self, api_key: str = None):
|
|
11
|
+
self.api_key = api_key
|
|
12
|
+
if api_key:
|
|
13
|
+
try:
|
|
14
|
+
self.client = genai.Client(api_key=api_key)
|
|
15
|
+
self.ai_enabled = True
|
|
16
|
+
except Exception:
|
|
17
|
+
self.ai_enabled = False
|
|
18
|
+
else:
|
|
19
|
+
self.ai_enabled = False
|
|
20
|
+
|
|
21
|
+
def generate_schema(self, df: pd.DataFrame, table_name: str = "dataset") -> str:
|
|
22
|
+
"""Translates a Pandas DataFrame into a SQL CREATE TABLE schema."""
|
|
23
|
+
schema = f"CREATE TABLE {table_name} (\n"
|
|
24
|
+
for col, dtype in df.dtypes.items():
|
|
25
|
+
sql_type = "FLOAT" if dtype in [
|
|
26
|
+
'float64'] else "INT" if dtype in ['int64'] else "VARCHAR(255)"
|
|
27
|
+
schema += f" {col} {sql_type},\n"
|
|
28
|
+
schema = schema.rstrip(",\n") + "\n);"
|
|
29
|
+
return schema
|
|
30
|
+
|
|
31
|
+
def text_to_sql(self, df: pd.DataFrame, question: str, table_name: str = "dataset"):
|
|
32
|
+
"""Uses AI to translate a plain English question into a SQL query based on the dataframe schema."""
|
|
33
|
+
console.print(
|
|
34
|
+
f"\n[bold blue]๐๏ธ Translating Question to SQL...[/bold blue]")
|
|
35
|
+
schema = self.generate_schema(df, table_name)
|
|
36
|
+
|
|
37
|
+
if not self.ai_enabled:
|
|
38
|
+
console.print(
|
|
39
|
+
"[bold red]โ AI not enabled. Please provide a Gemini API key to use the SQL Bridge.[/bold red]")
|
|
40
|
+
return
|
|
41
|
+
|
|
42
|
+
prompt = f"Given the following SQL schema:\n{schema}\n\nWrite a SQL query to answer this question: '{question}'. Return ONLY the raw SQL code. Do not include markdown formatting or explanations."
|
|
43
|
+
|
|
44
|
+
try:
|
|
45
|
+
response = self.client.models.generate_content(
|
|
46
|
+
model='gemini-2.5-flash', contents=prompt)
|
|
47
|
+
sql_query = response.text.strip().replace("```sql", "").replace("```", "")
|
|
48
|
+
|
|
49
|
+
console.print(Panel(
|
|
50
|
+
f"[bold green]Question:[/bold green] {question}\n\n[bold cyan]Generated SQL Query:[/bold cyan]\n{sql_query}",
|
|
51
|
+
title="๐ค intelguruai SQL Bridge",
|
|
52
|
+
border_style="blue",
|
|
53
|
+
expand=False
|
|
54
|
+
))
|
|
55
|
+
except Exception as e:
|
|
56
|
+
console.print(f"[bold red]โ SQL Generation failed: {e}[/bold red]")
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
import plotly.express as px
|
|
3
|
+
from rich.console import Console
|
|
4
|
+
from sklearn.cluster import KMeans
|
|
5
|
+
import plotly.graph_objects as go
|
|
6
|
+
|
|
7
|
+
console = Console()
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def smart_viz(df: pd.DataFrame, target: str = None):
|
|
11
|
+
"""
|
|
12
|
+
Automatically analyzes the dataset columns and generates
|
|
13
|
+
the most relevant interactive Plotly charts.
|
|
14
|
+
"""
|
|
15
|
+
console.print(
|
|
16
|
+
"\n[bold cyan]๐จ Launching Automated Visualization Engine...[/bold cyan]")
|
|
17
|
+
|
|
18
|
+
# Separate numeric and categorical columns
|
|
19
|
+
numeric_cols = df.select_dtypes(
|
|
20
|
+
include=['int64', 'float64']).columns.tolist()
|
|
21
|
+
categorical_cols = df.select_dtypes(
|
|
22
|
+
include=['object', 'category']).columns.tolist()
|
|
23
|
+
|
|
24
|
+
# 1. Plot Distributions for Numeric Columns
|
|
25
|
+
for col in numeric_cols:
|
|
26
|
+
console.print(
|
|
27
|
+
f"๐ Generating distribution plot for numeric feature: [bold cyan]{col}[/bold cyan]")
|
|
28
|
+
fig = px.histogram(
|
|
29
|
+
df,
|
|
30
|
+
x=col,
|
|
31
|
+
marginal="box",
|
|
32
|
+
title=f"Distribution of {col}",
|
|
33
|
+
template="plotly_dark",
|
|
34
|
+
color_discrete_sequence=['#00ffcc']
|
|
35
|
+
)
|
|
36
|
+
fig.show()
|
|
37
|
+
|
|
38
|
+
# 2. Plot Counts for Categorical Columns
|
|
39
|
+
for col in categorical_cols:
|
|
40
|
+
console.print(
|
|
41
|
+
f"๐ Generating bar chart for categorical feature: [bold magenta]{col}[/bold magenta]")
|
|
42
|
+
fig = px.bar(
|
|
43
|
+
df,
|
|
44
|
+
x=col,
|
|
45
|
+
title=f"Value Counts of {col}",
|
|
46
|
+
template="plotly_dark",
|
|
47
|
+
color_discrete_sequence=['#ff007f'] # Fix applied here!
|
|
48
|
+
)
|
|
49
|
+
fig.show()
|
|
50
|
+
|
|
51
|
+
# 3. Relationship Plot (If a target column is provided)
|
|
52
|
+
if target and target in df.columns:
|
|
53
|
+
console.print(
|
|
54
|
+
f"๐ฏ Target variable specified. Generating relationship plots for: [bold yellow]{target}[/bold yellow]")
|
|
55
|
+
for col in numeric_cols:
|
|
56
|
+
if col != target:
|
|
57
|
+
fig = px.scatter(
|
|
58
|
+
df,
|
|
59
|
+
x=col,
|
|
60
|
+
y=target,
|
|
61
|
+
trendline="ols",
|
|
62
|
+
title=f"Relationship: {col} vs {target}",
|
|
63
|
+
template="plotly_dark"
|
|
64
|
+
)
|
|
65
|
+
fig.show()
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def advanced_viz(df: pd.DataFrame, n_clusters: int = 3):
|
|
69
|
+
"""Generates a 3D interactive scatter plot."""
|
|
70
|
+
console.print(
|
|
71
|
+
"\n[bold cyan]๐ Generating 3D Cluster Visualizations...[/bold cyan]")
|
|
72
|
+
numeric_df = df.select_dtypes(include=['int64', 'float64']).dropna()
|
|
73
|
+
|
|
74
|
+
if numeric_df.shape[1] < 3:
|
|
75
|
+
console.print(
|
|
76
|
+
"[bold red]โ Need at least 3 numeric columns for 3D visualization.[/bold red]")
|
|
77
|
+
return
|
|
78
|
+
|
|
79
|
+
kmeans = KMeans(n_clusters=n_clusters, n_init=10, random_state=42)
|
|
80
|
+
clusters = kmeans.fit_predict(numeric_df)
|
|
81
|
+
|
|
82
|
+
cols = numeric_df.columns
|
|
83
|
+
fig = go.Figure(data=[go.Scatter3d(
|
|
84
|
+
x=numeric_df[cols[0]], y=numeric_df[cols[1]], z=numeric_df[cols[2]],
|
|
85
|
+
mode='markers', marker=dict(size=8, color=clusters, colorscale='Viridis', opacity=0.8)
|
|
86
|
+
)])
|
|
87
|
+
|
|
88
|
+
fig.update_layout(title="3D Cluster Visualization", template="plotly_dark")
|
|
89
|
+
console.print(
|
|
90
|
+
"[bold green]โ
3D Cluster Visualization Generated![/bold green]")
|
|
91
|
+
fig.show()
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: intelaish
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Next-generation automated EDA, cleaning, and AI insights.
|
|
5
|
+
Requires-Python: >=3.8
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: pandas>=2.0.0
|
|
8
|
+
Requires-Dist: numpy>=1.24.0
|
|
9
|
+
Requires-Dist: plotly>=5.14.0
|
|
10
|
+
Requires-Dist: scikit-learn>=1.2.0
|
|
11
|
+
Requires-Dist: google-genai>=0.2.0
|
|
12
|
+
Requires-Dist: rich>=13.0.0
|
|
13
|
+
Requires-Dist: statsmodels>=0.14.0
|
|
14
|
+
Requires-Dist: shap>=0.42.0
|
|
15
|
+
Requires-Dist: matplotlib>=3.7.0
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
intelaish/__init__.py
|
|
4
|
+
intelaish/cleaning.py
|
|
5
|
+
intelaish/explain.py
|
|
6
|
+
intelaish/ingestion.py
|
|
7
|
+
intelaish/insights.py
|
|
8
|
+
intelaish/models.py
|
|
9
|
+
intelaish/sql_engine.py
|
|
10
|
+
intelaish/visuals.py
|
|
11
|
+
intelaish.egg-info/PKG-INFO
|
|
12
|
+
intelaish.egg-info/SOURCES.txt
|
|
13
|
+
intelaish.egg-info/dependency_links.txt
|
|
14
|
+
intelaish.egg-info/requires.txt
|
|
15
|
+
intelaish.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
intelaish
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "intelaish"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Next-generation automated EDA, cleaning, and AI insights."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
dependencies = [
|
|
12
|
+
"pandas>=2.0.0",
|
|
13
|
+
"numpy>=1.24.0",
|
|
14
|
+
"plotly>=5.14.0",
|
|
15
|
+
"scikit-learn>=1.2.0",
|
|
16
|
+
"google-genai>=0.2.0",
|
|
17
|
+
"rich>=13.0.0",
|
|
18
|
+
"statsmodels>=0.14.0",
|
|
19
|
+
"shap>=0.42.0",
|
|
20
|
+
"matplotlib>=3.7.0"
|
|
21
|
+
]
|