ia-regression

Public
OVERVIEW.md

A personality quiz became a test of what can be inferred from only a few answers.

For a data-modeling course project, I wanted a Big Five quiz that would not force someone to finish all 50 questions before seeing a result. The practical question was what the unanswered items could reasonably be predicted from the answers already given. I built a Streamlit quiz around that idea and trained a model to fill the missing responses, while keeping supplied and inferred answers visibly different.

Making partial answers into a learning problem

A missing answer cannot be treated as a real low score. The model therefore receives both the values entered so far and a mask marking which questions were actually answered. During training, each complete response is partly hidden at a random answer count, and a multi-output Ridge model learns to predict the full 50-item vector. The notebook compares it with simpler global-mean and within-trait-mean baselines across different numbers of visible answers. This tests whether relationships between items help when the quiz is short.

In the app, question order changes between sessions and a result becomes available after five answers. Known answers are restored exactly; predicted values are clipped to the allowed scale. The result shows all five traits and the full item set, with a lighter, meme-style headline for seven selected items. The model and quiz are connected through a saved artifact, so the interface is an actual use of the trained regression rather than a static mockup.

The result is a working demonstration of partial-response prediction. Its accuracy cue comes from offline error curves, not a calibrated promise about an individual's personality. The public dataset, response filters, and random missing-answer pattern limit what the comparison establishes; this is a course project and interactive modeling exercise, not a clinical assessment.

README.md

IA Regression (Machine learning)

Indicator-augmented regression for partial Big Five answers · meme-style quiz

IA = Indicator-Augmented — not “artificial intelligence,” though the pun is half the fun. The serious name matches what we actually do: stack observed values with binary indicators so a linear model knows what was measured versus padding.

A data-modeling project that turns the IPIP Big Five personality test into a meme-style quiz where users can quit at any time and still get a meaningful result. The more questions they answer, the more precise the result becomes — but even with only a few answers the model produces a full readout for all 50 items.

  • Technique (full write-up): Detail.md — random-K training, multi-mask augmentation, baselines, evaluation.
  • Live app: client/ — Streamlit UI that loads the trained Ridge bundle and runs the quiz.
  • Modeling: models/main.ipynb — data prep, training, evaluation, and artifact export.
  • Engineering write-up (PDF): models/main.pdf — notebook export for readers who do not use Jupyter (regenerate after changes; see Exporting main.pdf).

Built on ~1M responses from Kaggle, with multi-output Ridge on indicator-augmented features and a random-mask training scheme so one model serves every completion rate K.


Repository layout

B5Personality/
├── README.md                          # this file — setup, overview, IA technique summary
├── Detail.md                          # extended methodology (companion to README)
├── requirements.txt                   # pinned dependency ranges for pip
├── client/                            # Streamlit quiz app
│   ├── app.py                         # entry point (run with Streamlit)
│   └── app.html                       # earlier static prototype (reference)
├── models/
│   ├── main.ipynb                     # exploration, cleaning, Ridge training, evaluation
│   ├── main.pdf                       # exported notebook for engineers / readers (optional; regenerate from main.ipynb)
│   ├── usage.ipynb                    # short notebook: load artifact & sanity-check predictions
│   ├── artifacts/
│   │   └── big5_ridge.joblib          # trained model bundle (created by main.ipynb)
│   └── data/
│       ├── questionDetial.md          # the 50 IPIP item codes & texts
│       └── big-five-personality-test/ # created after first Kaggle download (kagglehub cache under models/)
│           └── IPIP-FFM-data-8Nov2018/
│               └── data-final.csv     # raw ~1M-row dataset
└── .venv/                             # recommended local Python 3.11 virtualenv (create yourself; not always committed)

Paths under models/data/big-five-personality-test/ are populated when you run main.ipynb and kagglehub downloads the Kaggle dataset.


Prerequisites

  • Python 3.11 (matches the project’s tooling and notebook).
  • Git (to clone this repository).

Optional:

  • Jupyter or VS Code / Cursor with the Jupyter extension — to run main.ipynb interactively.
  • Google Chrome — only needed if you export main.pdf using the HTML → headless-Chrome method below.

Installation

1. Clone and enter the repository

git clone <your-repo-url>
cd B5Personality

2. Create and activate a virtual environment

python -m venv .venv
.\.venv\Scripts\Activate.ps1

On macOS / Linux:

python3 -m venv .venv
source .venv/bin/activate

3. Install Python dependencies

From the repository root, install everything needed for notebooks (training), Streamlit, and notebook → PDF export:

python -m pip install --upgrade pip
pip install -r requirements.txt

See requirements.txt for package names and compatible version ranges (notebooks, Streamlit, and nbconvert for exporting models/main.pdf).

The Kaggle dataset is downloaded automatically on first notebook run via kagglehub; no manual CSV download is required.


Running the Streamlit app

The UI expects the trained artifact at models/artifacts/big5_ridge.joblib. If that file is missing, run models/main.ipynb end-to-end first (see Training pipeline).

From the repository root:

.\.venv\Scripts\Activate.ps1
streamlit run client/app.py

Or from the client folder:

cd client
streamlit run app.py

Streamlit prints a local URL (usually http://localhost:8501). Open it in your browser to use the quiz.


Training pipeline

  1. Activate the venv and ensure dependencies are installed (see Installation).
  2. Open models/main.ipynb in Jupyter or VS Code / Cursor.
  3. Run all cells top to bottom.
    • First run downloads and caches the dataset under models/data/.
    • Wall-clock is on the order of ~30 seconds on a typical laptop CPU after data is cached.
  4. Confirm models/artifacts/big5_ridge.joblib exists.

Quick checks without rerunning the full notebook: open models/usage.ipynb with working directory models/ so ./artifacts/big5_ridge.joblib resolves.


Exporting main.pdf

models/main.pdf is a static export of models/main.ipynb for anyone who wants the full methodology, plots, and outputs without opening Jupyter. It is not auto-updated when you edit the notebook — regenerate it after substantive changes.

Typical workflow (Windows, with Chrome installed):

cd models
# nbconvert is included in requirements.txt; skip this if you already ran pip install -r ../requirements.txt
python -m nbconvert --to html main.ipynb --output main.html
& "C:\Program Files\Google\Chrome\Application\chrome.exe" --headless=new --disable-gpu --no-pdf-header-footer --print-to-pdf="$PWD\main.pdf" "file:///$($PWD -replace '\\','/')/main.html"
Remove-Item main.html

Adjust the Chrome path if your browser is installed elsewhere. Other platforms can use the same idea: export HTML with nbconvert, then print to PDF from a browser or use jupyter nbconvert --to webpdf if Playwright is working on your machine.


Indicator-augmented regression (IA)

The prediction problem is matrix completion on Likert items: from a partial answer vector, predict all 50 IPIP scores. We use a single multi-output regressor whose inputs are not raw incomplete vectors alone — they are augmented with indicators.

Feature construction

For each user we form a 100-dimensional input by concatenating:

BlockRole
Masked values (50)Real answers where the user responded; 0 elsewhere as padding (not a claim that the true score is zero).
Indicators / mask (50)1 if that item was answered, 0 if it was missing for this session.

So the mask does the bookkeeping: it marks which entries are genuine observations versus padding. In missing-data language, this is the usual observation pattern (which variables were measured); in regression, it is an indicator augmentation so the model can assign different weights to “missing + padded zero” than to a hypothetical low score that was actually observed.

Estimator and training

We fit one multi-output Ridge model on these 100 features to predict all 50 items. Random-K masking during training (together with multi-mask augmentation) exposes the same underlying respondents under many different subsets K, so the same linear map works whether the user stopped after 5 questions or 50. At inference, known answers overwrite predictions and outputs are clipped to the Likert range.

For filters, baselines, the random_mask code sketch, and evaluation curves, see Detail.md — it is the long-form appendix; this README stays the quick path for GitHub visitors.


The Big Idea

Traditional personality quizzes force you through all 50 questions or give you nothing. This one does not:

  • Quit anytime. Answer a few questions or all 50 — you always get a full result page.
  • Precision grows live. A precision bar reflects how much the model can infer from what you answered.
  • Soft limit around 30. Empirically, accuracy tends to plateau near 30 answers — the UI can nudge users there without blocking further questions.
  • Randomized order each session. Repeat users get a fresh question order.

Result page — always all 50 items

TierWhatWhen shown
Primary (7 meme personalities)Branded headline labelsAlways
Secondary (43 items)Supporting detailAlways

Items the user answered show as known; the rest are filled by the model. Same layout for every K — no unlocks.

The 7 meme personalities (Tier 1)

Each meme maps to one Big Five item; high agreement triggers the label (wording in the app may differ from this table).

QuestionMeme (example label)
CSN6Frequently Forgets Items
AGR9Empath
AGR5Cold Heart
EXT4Wallflower
EST7Mood Roller-Coaster
OPN3Daydreamer
OPN10Dare to Dream

Why partial-answer prediction works

Big Five items are redundant by design — each trait has 10 items measuring related signal. A full 50-dimensional answer vector is largely determined by a few latent trait scores plus noise. Given any subset of K answers, those latents are partially pinned; indicator-augmented regression learns to map from “which items were observed + what they were” back to the full vector.


Pipeline summary (after IA setup)

Data quality (before modeling)

Respondents are filtered for plausible engagement (e.g. unique IP where applicable, reasonable completion time, non-flat answer patterns). This step is applied before dropping metadata columns and has a large impact on training quality. Details: Data quality and full pipeline in Detail.md.

Training tricks (same 100-dim IA features)

  1. Random K per row: each training row uses a random subset of answered questions; the rest are masked.
  2. Multi-mask augmentation: each row is repeated with different random masks so the model sees many “partial views” of the same person.

Estimator

Multi-output Ridge regression on masked values stacked with indicators, predicting all 50 items. Validation selects alpha across a grid; evaluation reports MAE at several K values. At inference, known answers overwrite predictions and outputs are clipped to [1, 5].


Models compared (notebook)

ModelRole
Global meanSanity floor
Trait meanStrong baseline using answered items within each trait
RidgeUses cross-item / cross-trait structure; best for low K

Using the trained artifact in Python

After training, load models/artifacts/big5_ridge.joblib:

import joblib
import numpy as np

bundle = joblib.load("models/artifacts/big5_ridge.joblib")
ridge   = bundle["ridge"]
all_q   = bundle["all_q_cols"]
memes   = bundle["meme_questions"]
col_idx = {c: i for i, c in enumerate(all_q)}

def predict(answers: dict[str, float]) -> np.ndarray:
    """answers = {'EXT1': 5, 'OPN3': 4, ...}  ->  predicted (50,) on 1..5 scale."""
    x = np.zeros((1, 50), dtype=np.float32)
    m = np.zeros((1, 50), dtype=np.float32)
    for q, v in answers.items():
        if q in col_idx:
            x[0, col_idx[q]] = float(v)
            m[0, col_idx[q]] = 1.0
    pred = ridge.predict(np.hstack([x, m]))[0]
    pred = np.where(m[0] == 1, x[0], pred)
    return np.clip(pred, 1, 5)

The notebook defines a richer predict_personality(answers) helper returning trait scores, primary/secondary splits, and counts for the UI.


Notebook walkthrough (main.ipynb)

  1. Project vision — UX goals.
  2. Setup & load — KaggleHub download and paths.
  3. Exploration — distributions and correlation structure.
  4. Clean data — quality filters, trait scores (df_scores).
  5. Modeling — train/val/test split, random_mask, baselines, Ridge + augmentation, evaluation plots, persistence and prediction helpers.

Tech stack

LayerTools
DataKaggle “Big Five Personality Test” (IPIP-FFM, Nov 2018)
Wranglingpandas, numpy
Visualizationmatplotlib, seaborn
Modelingscikit-learn (Ridge, etc.)
Serializationjoblib
AppStreamlit (client/app.py)
NotebooksJupyter / VS Code / Cursor

What’s next

Ideas for future work: iterative refinement at inference, stronger nonlinear heads for meme items, explicit reverse-coding of negatively keyed items, richer precision UI from per-K MAEs, and smarter question ordering (e.g. active learning).


Credits

License

Original code and documentation authored by Jakkarin Promsee are licensed under the MIT License. Third-party code, assets, datasets, and other materials are not covered by this license; their original terms apply.