Skip to content

Repository files navigation

title CSV Predictor
emoji 📊
colorFrom blue
colorTo indigo
sdk docker
app_port 8501
pinned false
short_description Upload a CSV, train a model, view metrics & importances.
tags
streamlit

CSV Predictor

A Streamlit web application for uploading a CSV file, auto-detecting the ML task, training a Random Forest model, and displaying test-set metrics and feature importances.

Live demo: huggingface.co/spaces/voidalc07/csv-predictor

Screenshot

CSV Predictor — trained view showing metrics and feature-importance chart


How to run

# Create and activate a virtual environment
python3 -m venv .venv
source .venv/bin/activate

# Install dependencies
pip install -r requirements.txt

# Launch the app
streamlit run app.py

# Run the test suite
pytest tests/

Project structure

Path Responsibility
app.py Streamlit UI only — renders widgets and calls into data_utils. Contains no data-processing logic.
data_utils.py Pure data functions: loading CSVs and inferring column types. No UI imports.
tests/test_data_utils.py Pytest unit tests for data_utils.
sample_data/example.csv Generated synthetic dataset: 600-row binary classification of 30-day hospital readmission. Produced by scripts/generate_sample_data.py — do not edit by hand.
scripts/generate_sample_data.py Seeded script that regenerates example.csv deterministically. Documents the built-in signal, noise features, and missing-value injection.
requirements.txt Pinned Python dependencies.
.streamlit/config.toml Streamlit theme configuration.
conftest.py Empty pytest hook that anchors the project root on sys.path, allowing test modules to import top-level packages without install.

Design decisions

UI and logic are separated (app.py vs data_utils.py) so that data functions can be tested independently of Streamlit and reused by future modules (e.g. a training pipeline) without importing any UI code. This boundary is enforced: data_utils.py has no Streamlit import, and app.py has no data-processing logic.


Modelling approach

Task detection (detect_task) uses a three-rule heuristic: non-numeric target → classification; numeric target with low cardinality (≤ 20 unique values and ≤ 5 % of row count) → classification; otherwise → regression. This is a best guess — users will be able to override it in the UI.

Preprocessing is handled by a ColumnTransformer inside an sklearn Pipeline: median imputation + standard scaling for numeric columns; most-frequent imputation + one-hot encoding for categoricals. Keeping preprocessing inside the pipeline ensures the test split is never exposed to fit statistics from the training set.

ModelRandomForestClassifier / RandomForestRegressor with 100 estimators. Chosen as a robust baseline: resistant to feature scale, handles mixed types after encoding, rarely overfits on small datasets with default hyper-parameters, and exposes feature importances natively for a later UI step.

Metrics — classification returns accuracy, macro-F1, and (for binary targets) ROC-AUC. Regression returns R² and RMSE. Multiclass ROC-AUC is deferred until a multi-label probability display is added to the UI.

About

Live demo Upload a CSV, auto-detect the ML task, train a Random Forest, and see test-set metrics and feature importances — deployed on Hugging Face Spaces.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages