Getting Started

Overview

Beginner-first machine learning. Train a model in 3 lines.

fling wraps scikit-learn behind a clean, safe API designed for people learning ML. It handles data splitting, preprocessing, missing values, and encoding automatically - and explains every decision in plain English.

python
from fling import Classifier

model = Classifier(data="titanic.csv", target="Survived")
model.train()
model.evaluate()
output
[ok] Loaded 891 rows, 12 columns
[ok] Split: 712 training rows, 179 test rows (split before preprocessing)
[ok] Auto-handled: 5 text column(s) encoded (Pclass, Name, Sex, Ticket, Embarked)
[ok] Auto-handled: 2 column(s) had missing values - filled with median/mode (Age, Embarked)
[ok] Trained: LogisticRegression (small dataset - logistic regression is fast and interpretable)

Results:
  Accuracy:  81.6%
  In plain English: Your model correctly predicted 'Survived' for 146 out of 179 rows in the test set.

Install

bash
pip install git+https://github.com/vedanshalways/Fling.git

Quick reference

TaskCode
Classify (predict a category)Classifier(data=..., target=...)
Regress (predict a number)Regressor(data=..., target=...)
Train.train()
Evaluate on test set.evaluate()
Predict new rows.predict(new_df)
Visualize results.visualize()
Explain feature importance.explain()
Compare 5 models.compare()
Get algorithm recommendations.recommend()
See the raw sklearn code.show_sklearn_code()
Escape to sklearn.to_sklearn() / .get_splits()

What fling handles automatically

ProblemWhat fling does
Text / categorical columnsOneHotEncodes them
Missing numeric valuesFills with column median
Missing categorical valuesFills with most frequent value
Columns with > 50% missingDrops them, logs in report
ID-like columns (all unique)Drops them automatically
Choosing a modelPicks based on dataset size
Train/test split orderingAlways splits before preprocessing

How fling prevents data leakage

Data leakage is the #1 silent bug in beginner ML. It happens when test data influences the training process - making accuracy look better than it really is.

The wrong way (what most tutorials show)

python
# WRONG: scaler sees all data before the split
scaler = StandardScaler()
X_scaled = scaler.fit_transform(X)            # computes mean/std on ALL data
X_train, X_test = train_test_split(X_scaled)  # test is already contaminated
The scaler's mean and std were computed using test rows. Your accuracy score is optimistic - it won't hold up on truly new data.

The right way (what fling always does)

python
# RIGHT: split first, then fit preprocessing on train only
X_train, X_test, y_train, y_test = train_test_split(X, y)

pipeline = Pipeline([
    ("preprocessor", column_transformer),  # fitted on X_train only
    ("model", estimator),
])
pipeline.fit(X_train, y_train)   # scaler learns from train rows only
pipeline.predict(X_test)         # transforms test using train stats

You can verify this yourself:

python
model.train()
X_train, X_test, y_train, y_test = model.get_splits()
print(X_train.shape[0])  # e.g. 712 - scaler computed on these rows only

Requirements

Examples

The examples/ folder has four runnable scripts:

FileWhat it shows
01_your_first_classifier.pyBasic 3-line classifier
02_your_first_regressor.pyBasic 3-line regressor
03_compare_models.pyrecommend → train → compare → explain → visualize
04_graduate_to_sklearn.pyshow_sklearn_code → to_sklearn → get_splits
bash
python 01_your_first_classifier.py

Next steps