Skip to content

Latest commit

 

History

History
232 lines (156 loc) · 11.8 KB

File metadata and controls

232 lines (156 loc) · 11.8 KB

AutoInsight

AutoInsight is an end-to-end automated machine learning (AutoML) web application built with Streamlit. It is designed to let anyone, including people without deep machine learning knowledge, upload a CSV file and receive a full model training pipeline, performance evaluation, SHAP-based explainability, and plain-language insights generated by a large language model (LLM). The entire process runs inside the browser with no code required from the user.

The project was built as a personal exploration of what a lightweight, transparent, and privacy-aware AutoML tool could look like for tabular data.

NOTE: Some plots do not render on live deployment due to resource constraints, please run locally to gaurentee everything is running as it should

What It Does

A user uploads a CSV file and selects a target column. AutoInsight then loads and validates the file with automatic encoding detection, profiles the dataset to identify missing values, column types, correlations, and class imbalance, and then preprocesses the data through imputation, encoding, scaling, and feature selection. After preprocessing, it trains multiple machine learning models in parallel and evaluates all of them to produce a ranked leaderboard. The user can then optionally trigger Bayesian hyperparameter tuning on the top-ranked models. Once training is complete, AutoInsight computes SHAP feature importances and dependency plots for the best models, sends only aggregated metrics to a Groq-hosted LLM which generates a human-readable explanation, and allows the user to ask follow-up questions about the results in a chat-style Q&A tab. The entire session can be exported as a structured JSON report.

The interface is a four-tab Streamlit layout covering the pipeline overview, model results, SHAP analysis, and LLM insights.


Key Design Decision

The LLM receives only aggregated metrics such as leaderboard scores, SHAP values, feature importances, and profiling summaries. It never sees the raw dataset. This was a deliberate design choice for two reasons. First, it reduces the risk of hallucinations because the model cannot fabricate dataset-specific claims beyond what it is given. Second, it avoids sending potentially sensitive user data to an external API.

The LLM is also constrained through its system prompt to respond only in valid JSON and to avoid comparing results against external benchmarks unless those benchmarks are explicitly provided.


Models Trained

AutoInsight automatically detects whether the task is classification or regression based on the target column.

For classification tasks, it trains Logistic Regression, Random Forest, Extra Trees, Gradient Boosting, XGBoost, LightGBM, and CatBoost. For regression tasks, it trains Linear Regression, Random Forest, Extra Trees, Gradient Boosting, XGBoost, LightGBM, and CatBoost. All models are trained with cross-validation. If a model fails during training, the pipeline continues with the remaining ones and only crashes if every single model fails.


Preprocessing Pipeline

The preprocessing module runs a sequence of transformations before any model sees the data.

Missing values in numerical columns are filled with the median if the column is skewed (absolute skew above 1.0) or with the mean otherwise. Categorical columns are filled with the most frequent value. Datetime columns are not dropped but are instead decomposed into five numerical features representing year, month, day, hour, and day of week, which allows temporal patterns to be captured without building a full time-series model. Columns where a single value appears in more than 95 percent of rows are removed before training because they carry almost no predictive signal.

Outliers in numerical features are capped using an IQR-based method fitted only on the training set and then applied to both training and test sets, using a default IQR factor of 3.0. For categorical encoding, columns with 10 or fewer unique values are one-hot encoded while columns with more than 10 unique values are label encoded to avoid dimensionality explosion. All numerical features are then standardized using StandardScaler fitted on the training data only. Finally, SelectKBest with mutual information scoring retains the top 30 features by default, which helps reduce noise for high-dimensional datasets. The train/test split defaults to 80 and 20 percent respectively, with stratified splitting used for classification tasks to preserve class ratios.

All thresholds above can be changed through config.yaml or overridden through environment variables.


Hyperparameter Tuning

Tuning is optional and user-triggered from the UI. When enabled, it runs Optuna's TPE (Tree-structured Parzen Estimator) sampler for 40 trials by default on the top-ranked models from the leaderboard. Each model has a defined search space covering parameters like tree depth, number of estimators, learning rate, regularization strength, and leaf count. SHAP analysis always prefers the tuned version of a model over the original when both are available.


Evaluation Metrics

For classification tasks, AutoInsight reports AUC (using standard scoring for binary tasks and one-vs-rest for multiclass), weighted F1 score, accuracy, and a confusion matrix. For regression tasks, it reports RMSE, MAE, and R2 score. All results are collected into a ranked leaderboard shown in the UI, ordered by the primary metric for the detected task type.


LLM Integration

The LLM layer uses the Groq API with models such as llama-3.3-70b-versatile or qwen/qwen3-32b. Calls are made at temperature 0.2 to keep outputs consistent and conservative. The module supports both standard blocking calls for the initial results explanation and streaming calls for the Q&A tab so that responses appear word by word as they are generated.

Prompts are stored as plain text files in the prompts/ directory and loaded at runtime. This makes it straightforward to edit the system behavior without touching any Python code.


Dataset Profiling

Before any model is trained, AutoInsight runs a profiling step that identifies column types as numerical, categorical, or datetime, computes missing value ratios per column, flags near-constant features where a single value appears in more than 95 percent of rows, detects high-correlation pairs using a Pearson threshold of 0.85, and checks class balance in the target column where a dominant class above 80 percent is flagged as imbalanced. These findings are shown in the UI and also passed to the LLM as part of its context.


Project Structure

AutoInsight/
├── app.py                    # Main Streamlit application (UI, state management)
├── config.yaml               # Default configuration for all pipeline thresholds
├── requirements.txt          # Python dependencies
├── Example.env               # Template for environment variables
│
├── pipeline/
│   ├── ingestion.py          # CSV loading, encoding detection, basic validation
│   ├── profiling.py          # Column type detection, missing values, correlations
│   ├── preprocessing.py      # Imputation, encoding, scaling, feature selection
│   ├── automl.py             # Model definitions and parallel training
│   ├── evaluation.py         # Metrics computation and leaderboard builder
│   ├── tuning.py             # Optuna search spaces and tuning orchestration
│   ├── shap_analysis.py      # SHAP value computation and plot data
│   ├── llm_reasoning.py      # Groq API calls, streaming, prompt assembly
│   └── config_loader.py      # Reads config.yaml with env var overrides
│
├── utils/
│   ├── validators.py         # Input validation logic
│   ├── formatters.py         # Data transformation for UI display and JSON export
│   └── logger.py             # Logging setup
│
├── prompts/
│   ├── system_prompt.txt     # LLM role definition and JSON-only constraint
│   ├── model_explanation.txt # Template for results explanation
│   └── qa_prompt.txt         # Template for interactive Q&A
│
├── tests/
│   ├── test_profiling.py
│   ├── test_preprocessing.py
│   ├── test_automl.py
│   ├── test_llm_reasoning.py
│   └── test_integration.py
│
└── scripts/
    └── run_benchmarks.py     # Benchmarks the pipeline on public datasets

Installation

You will need Python 3.9 or higher and a Groq API key, which is available for free at console.groq.com.

Step 1 — Clone the repository

git clone https://github.com/your-username/AutoInsight.git
cd AutoInsight

Step 2 — Create a virtual environment

python -m venv .venv
source .venv/bin/activate       # on Mac or Linux
.venv\Scripts\activate          # on Windows

Step 3 — Install dependencies

pip install -r requirements.txt

Step 4 — Set up environment variables

Copy Example.env to .env and fill in your Groq API key.

GROQ_API_KEY=your_api_key_here
GROQ_MODEL=llama-3.3-70b-versatile

Step 5 — Run the app

streamlit run app.py

The app will open automatically in your browser.


Configuration

All pipeline defaults live in config.yaml. You can edit them there or override any value using an environment variable.

Setting Default Environment Variable
Random seed 42 RANDOM_SEED
Test set size 0.2 DEFAULT_TEST_SIZE
Max file size (MB) 50 MAX_FILE_SIZE_MB
Optuna trials 40 OPTUNA_TRIALS
LLM max retries 3 MAX_RETRIES_LLM
LLM temperature 0.2 (config.yaml only)
Max LLM tokens 800 (config.yaml only)
Near-constant threshold 0.95 (config.yaml only)
High-cardinality threshold 10 (config.yaml only)
Outlier IQR factor 3.0 (config.yaml only)
Feature selection k 30 (config.yaml only)
High-correlation threshold 0.85 (config.yaml only)

Running Tests

pytest tests/

Tests cover profiling logic, preprocessing transformations, model training, LLM prompt construction, and an end-to-end integration test. No real API calls are made during tests because the LLM module is mocked.


Running Benchmarks

The benchmark script evaluates the full pipeline on several publicly available datasets and saves the results to benchmark_results.json. Datasets used include Titanic, Heart Disease, Adult Income, and California Housing, covering both classification and regression tasks.

python scripts/run_benchmarks.py

Tech Stack

Layer Library
UI Streamlit
Data handling pandas, numpy
Machine learning scikit-learn, XGBoost, LightGBM, CatBoost
Explainability SHAP
Hyperparameter tuning Optuna
LLM API Groq (requests-based)
Visualizations Plotly
Encoding detection chardet
Configuration python-dotenv, PyYAML
Testing pytest

Limitations

The pipeline currently supports only tabular CSV data, so images, text corpora, and time-series data with proper sequential dependencies are not handled. Datetime columns are decomposed into component features rather than being modeled as a true time series. The quality of LLM explanations depends on the Groq model selected and may vary slightly between runs even at low temperature. Datasets above 50 MB are rejected at upload by default to keep the in-browser experience responsive. A stacking ensemble is available in the codebase but is not exposed through the main UI.


License

This project is licensed under the GNU General Public License v3.0. See the LICENSE file for details.


Author

Built by Rahul Ray. Feel free to connect on LinkedIn.