Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

36 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– Autolysis β€” Automated Data Analysis & AI Narrative Engine

TDS Project 2 Β· Drop in any CSV. Get statistics, visualizations, and an AI-generated narrative β€” fully automated.

Python OpenAI License Status Datasets


πŸ“Œ Table of Contents


🧭 Overview

Autolysis is a zero-configuration data analysis pipeline. Pass it any CSV file and it will:

  1. Load & clean the data (handles encoding quirks, missing values, type inference)
  2. Analyze it β€” summary statistics, correlations, and IQR-based outlier detection
  3. Visualize β€” correlation heatmaps, outlier bar charts, and distribution plots saved as PNGs
  4. Narrate β€” calls an LLM (GPT-4o-mini via AI Proxy) to generate a written story from the findings
  5. Report β€” outputs a fully-formed README.md with embedded charts and narrative

No configuration files. No manual steps. One command.

python autolysis.py dataset.csv

βš™οΈ How It Works

CSV Input
    β”‚
    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Data Loading        β”‚  pandas Β· ISO-8859-1 encoding support
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚
    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Statistical         β”‚  describe() Β· isnull() Β· .corr()
β”‚  Analysis            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚
    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Outlier Detection   β”‚  IQR method (Q1 - 1.5Γ—IQR / Q3 + 1.5Γ—IQR)
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚
    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Visualization       β”‚  seaborn Β· matplotlib β†’ PNG files
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚
    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  LLM Narrative       β”‚  GPT-4o-mini via AIPROXY_TOKEN
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚
    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  README Generation   β”‚  Markdown report with embedded visuals
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“ Repository Structure

Tools-In-Data-Science-Project-2/
β”‚
β”œβ”€β”€ autolysis.py              # Core analysis engine (single-file, self-contained)
β”‚
β”œβ”€β”€ goodreads/                # Analysis output β€” Goodreads dataset
β”‚   β”œβ”€β”€ README.md
β”‚   β”œβ”€β”€ correlation_matrix.png
β”‚   β”œβ”€β”€ outliers.png
β”‚   └── distribution_*.png
β”‚
β”œβ”€β”€ happiness/                # Analysis output β€” World Happiness dataset
β”‚   β”œβ”€β”€ README.md
β”‚   β”œβ”€β”€ correlation_matrix.png
β”‚   β”œβ”€β”€ outliers.png
β”‚   └── distribution_*.png
β”‚
β”œβ”€β”€ media/                    # Analysis output β€” Media consumption dataset
β”‚   β”œβ”€β”€ README.md
β”‚   β”œβ”€β”€ correlation_matrix.png
β”‚   β”œβ”€β”€ outliers.png
β”‚   └── distribution_*.png
β”‚
β”œβ”€β”€ LICENSE                   # MIT
└── README.md                 # You are here

πŸ“Š Datasets Analyzed

πŸ“š Goodreads

Book ratings, author profiles, genre distribution, and publication trends. Key questions: What makes a book highly rated? Which authors dominate by volume vs. quality?

🌍 Happiness (World Happiness Report)

Country-level happiness scores correlated against GDP, social support, health, freedom, and corruption. Key questions: What factors most strongly predict national happiness?

🎬 Media

Media consumption data β€” views, ratings, and genre breakdown. Key questions: Are certain genres consistently better rated? What does engagement look like across media types?


πŸ”¬ Pipeline Breakdown

1. analyze_data(df)

Runs df.describe() for summary stats, counts nulls per column, and computes a full Pearson correlation matrix on all numeric columns.

2. detect_outliers(df)

Uses the IQR method β€” values beyond Q1 βˆ’ 1.5Γ—IQR or Q3 + 1.5Γ—IQR are flagged as outliers, counted per column.

3. visualize_data(...)

Generates three charts per dataset:

  • Correlation Heatmap β€” Blues palette, annotated cells
  • Outlier Bar Chart β€” only rendered when outliers are detected
  • Distribution Plot β€” KDE-smoothed histogram of the first numeric column

4. question_llm(prompt, context)

Posts to the AI Proxy endpoint (aiproxy.sanand.workers.dev) with GPT-4o-mini. Passes summary stats and missing value counts as context. Returns a narrative string appended to the report.

headers = {"Authorization": f"Bearer {token}"}
data = {"model": "gpt-4o-mini", "messages": [...], "max_tokens": 1000}
response = requests.post(api_url, headers=headers, data=json.dumps(data))

5. create_readme(...)

Assembles a Markdown report with embedded PNG references, summary stat tables (via .to_markdown()), and the LLM narrative.


πŸš€ Getting Started

Prerequisites

Dependencies are declared inline via PEP 723 script metadata and can be installed with:

pip install pandas seaborn matplotlib numpy scipy openai scikit-learn requests

Environment Variable

The LLM narrative step requires an AI Proxy token:

export AIPROXY_TOKEN=your_token_here

The tool uses https://aiproxy.sanand.workers.dev β€” a cost-efficient proxy to OpenAI's API. Without a token, the analysis still runs; only the narrative generation step fails gracefully.

Run

python autolysis.py path/to/your/dataset.csv

Output is written to an output/ directory created automatically in the current working directory.


πŸ“€ Output Files

File Description
README.md Full analysis report with embedded charts and LLM narrative
correlation_matrix.png Heatmap of Pearson correlations between numeric columns
outliers.png Bar chart of outlier counts per column (if any found)
distribution_<col>.png KDE histogram of the first numeric column

πŸ— Technical Architecture

Component Technology
Data loading pandas (ISO-8859-1 encoding)
Statistics pandas, numpy
Outlier detection IQR method via numpy
Visualizations seaborn, matplotlib
LLM integration OpenAI GPT-4o-mini via AI Proxy
Report generation Python file I/O + Markdown
CLI argparse / sys.argv
Dependency spec PEP 723 inline script metadata

πŸ“‹ Sample Results

Happiness Dataset β€” Notable Correlation: GDP per capita and Life Ladder (happiness score) show strong positive correlation, confirming economic prosperity as a primary driver of reported well-being across nations.

Goodreads Dataset β€” Notable Finding: Books with higher ratings tend to have more text reviews than star-only ratings, suggesting engaged readers leave qualitative feedback more than disengaged ones.

Media Dataset β€” Notable Finding: Overall quality ratings cluster tightly regardless of language, suggesting audience satisfaction is driven more by content quality than production origin.


πŸ‘€ Author

Aman Mani Tiwari github.com/AmanManiTiwari


πŸ“„ License

MIT β€” see LICENSE for details.


Built as part of the Tools in Data Science course. Analysis powered by the GitHub API, OpenAI GPT-4o-mini, and standard Python data science libraries.

About

An automated data analysis tool that loads datasets, generates statistical summaries and visualizations, and uses OpenAI's API to produce narrative insights - demonstrated on Goodreads, media, and happiness datasets.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages