Linear Regression Analysis in Python
Run simple and multiple linear regression, interpret coefficients, check assumptions, and evaluate model fit using statsmodels and scikit-learn.
What this AI workflow does
This AI Data Analyst workflow loads the Boston Housing dataset from a URL and fits a simple linear regression of RM (rooms) versus MEDV (price). It then fits a multiple linear regression using all features and generates a statsmodels OLS summary for coefficient and p-value interpretation. The workflow checks key regression assumptions with residual and Q-Q plots, evaluates homoscedasticity, and compares model fit between the simple and multiple models using R-squared.
Who this example is for
This is for analysts and students who want a guided, code-generating notebook to run and interpret linear regression in Python. It helps users validate assumptions and compare simple versus multiple regression using standard statistical outputs and diagnostics.
Expected analysis outcomes
These are the results the AI workflow is expected to generate.
- Dataset loaded from the provided CSV URL
- Simple regression scatter plot with fitted line and R-squared around 0.48
- Multiple regression OLS summary table with coefficients and p-values
- Residual and Q-Q diagnostic plots with a homoscedasticity check
- R-squared comparison showing roughly 0.48 (simple) versus 0.74 (multiple)
Tools and libraries used
Main Python packages and tooling used to run this AI data analysis task.
- pandas
- numpy
- statsmodels
- scikit-learn
- matplotlib
- seaborn
Prompt sequence
This is the exact list of prompts used in this workflow. The same prompt sequence is sent to each model so outputs and scores can be compared fairly.
- 1load boston housing data from https://raw.githubusercontent.com/pplonski/datasets-for-start/refs/heads/master/housing/data.csv and run simple linear regression: rm (rooms) vs medv (price)
- 2run multiple linear regression with all features and show the statsmodels summary
- 3check regression assumptions: residual plot, Q-Q plot, homoscedasticity
- 4compare R-squared of simple vs multiple regression
Model Comparison
We compared several LLM models on the same analysis task. The table below shows their scores side by side. You can also open each model run to check the full conversation and notebook results.
| Model Source | Score | Task | Execution | Output | Reasoning | Reliability | Run |
|---|---|---|---|---|---|---|---|
| gemma4:31b | 10/10 | 2/2 | 2/2 | 3/3 | 2/2 | 1/1 | Open gemma4:31b conversation |
| glm-5.1 | 10/10 | 2/2 | 2/2 | 3/3 | 2/2 | 1/1 | Open glm-5.1 conversation |
| gpt-5.4 | 10/10 | 2/2 | 2/2 | 3/3 | 2/2 | 1/1 | Open gpt-5.4 conversation |
| gpt-oss:120b | 10/10 | 2/2 | 2/2 | 3/3 | 2/2 | 1/1 | Open gpt-oss:120b conversation |
| qwen3-coder-next | 10/10 | 2/2 | 2/2 | 3/3 | 2/2 | 1/1 | Open qwen3-coder-next conversation |
| qwen3.5:397b | 10/10 | 2/2 | 2/2 | 3/3 | 2/2 | 1/1 | Open qwen3.5:397b conversation |
How scoring works
Each run is graded on five dimensions:
- Task Completion (0-2): how fully the workflow answered the requested analysis task and completed required steps.
- Execution Correctness (0-2): whether generated code is correct, consistent, and likely runnable without major fixes.
- Output Quality (0-3): how well tables, charts, and results match the expected analytical outcomes.
- Reasoning Quality (0-2): clarity and correctness of interpretation, explanation, and conclusions.
- Reliability (0-1): robustness of the run, including low hallucination risk and stable behavior.
The final score is the sum of these dimensions, so total score = 0-10. Higher values indicate more complete, correct, and reliable notebook results for this workflow.
AI Analysis with gemma4:31b
This run uses AI with a step-by-step list of prompts to perform the analysis task Linear Regression Analysis in Python. Below, you can review the full conversation generated with gemma4:31b. After the conversation, we show detailed score cards for this run.
Score cards for gemma4:31b for Linear Regression Analysis in Python
Total score: 10/10
Task Completion: 2/2
ExcellentAll major requested steps were completed: simple regression, multiple regression with statsmodels summary, assumption checks, and R-squared comparison.
Execution Correctness: 2/2
ExcellentThe code shown is coherent and likely runnable, and the outputs are consistent with the intended analyses.
Output Quality: 3/3
ExcellentOutputs match the expected outcomes semantically: regression line, full OLS summary, residual and Q-Q plots, Breusch-Pagan test, and R² values of about 0.48 and 0.74.
Reasoning Quality: 2/2
ExcellentThe workflow correctly interprets the regression results and connects the diagnostics to the assumptions being checked.
Reliability: 1/1
ExcellentThe workflow is consistent and not obviously hallucinated, with outputs supporting the stated conclusions.
Try MLJAR Studio
Run the same type of AI-powered data analysis on your own datasets with conversational notebooks in MLJAR Studio.
Explore More AI Analysis Examples
Discover additional workflows across categories. Each example includes prompts, conversation outputs, and model-level scoring so you can compare approaches and results.