Kylie Ying ML for Everyone Framework
Apply a structured, beginner-accessible machine learning methodology to any classification or clustering problem — from raw data to evaluated model — without needing to re-learn the fundamentals each time.
// TL;DR
The Kylie Ying ML for Everyone Framework is a structured, beginner-accessible methodology for building, training, and evaluating machine learning models on tabular data. It walks you from raw CSV to an evaluated model through a fixed sequence: inspect data, encode categorical features, explore distributions, split into train/validation/test sets, scale features, handle class imbalance, train multiple candidate models (KNN, Naive Bayes, Logistic Regression, SVM), and report results with precision, recall, and F1. Use it whenever you have a tabular dataset and want to solve a classification, regression, or clustering problem without re-learning fundamentals each time.
// When should you use the ML for Everyone Framework?
Use this skill whenever you have a dataset and want to build, train, and evaluate a machine learning model for classification or pattern discovery. Ideal when starting from scratch with tabular data and needing to choose between multiple model types.
// What do you need before applying this ML framework?
- Datasetrequired
A tabular dataset (CSV or similar) with features and, for supervised learning, a label/target column. - Prediction Goalrequired
What you want to predict — a discrete class (classification) or a continuous value (regression). - Feature Descriptionsrequired
What each column represents and whether features are qualitative (nominal/ordinal) or quantitative (discrete/continuous). - Class Balance Info
Whether the target classes are balanced or imbalanced in the dataset. - Model Preference
Any preference or constraint on model type (KNN, Naive Bayes, Logistic Regression, SVM, Neural Net).
// What core principles power this machine learning methodology?
Supervised vs. Unsupervised Learning
Supervised learning uses labeled inputs — each sample has a known output label — so the model can compare predictions to truth and adjust. Unsupervised learning finds structure in unlabeled data through clustering, without any predefined output.
Features Matrix X and Labels Vector y
All input columns form the features matrix X — each row is one sample, each column is one feature. The target output column is the labels vector y. Every model learns the mapping from X to y.
Train / Validation / Test Split
Never train and evaluate on the same data. Split your dataset into training (≈60-80%), validation (≈10-20%), and test (≈10-20%) sets. Training adjusts the model; validation reality-checks it during training; the test set gives the final reported performance on data the model has never seen.
Loss as the Learning Signal
Loss is a numerical measure of the difference between the model's prediction and the true label. The training loop exists to minimize loss. Common loss functions: L1 loss (absolute difference), L2 loss (squared difference, penalizes outliers more), binary cross-entropy loss (for binary classification). Loss decreases as performance gets better.
Encoding Before Modeling
Computers understand numbers, not categories. Nominal (unordered) categorical features must be one-hot encoded — each category becomes its own binary column. Ordinal (ordered) categorical features can be mapped to integers that preserve their ordering. All features must be numerical before feeding into any model.
Feature Scaling
When feature columns have wildly different scales (e.g., one column ranges 0–1, another ranges 0–10,000), model performance can suffer. Apply StandardScaler (subtract the mean, divide by standard deviation) to normalize all features to a common scale before training.
Oversampling for Class Imbalance
If one class heavily outnumbers another in the training set, the model may be biased toward the majority class. Apply RandomOverSampler to the training set only — oversample the minority class to balance the distribution. Never oversample the validation or test sets, because those must reflect real-world data distribution.
Evaluation Beyond Accuracy
Accuracy alone is misleading on imbalanced datasets. Report precision (of all samples labeled as this class, how many truly are?), recall (of all truly positive samples, how many did we catch?), and F1 score (harmonic mean of precision and recall). Prefer F1 when classes are imbalanced.
Gradient Descent and Weight Updates
During neural network training, the model adjusts its internal weights by computing how much each weight contributed to the loss (via backpropagation and calculus), then stepping in the direction that reduces loss. The learning rate controls how large each step is.
Activation Functions Prevent Collapse
Without activation functions, a neural network with multiple layers collapses into a single linear model, making depth pointless. Activation functions (Sigmoid, tanh, ReLU) introduce nonlinearity so the network can learn complex patterns.
// How do you apply the ML for Everyone Framework step by step?
- 1
Inspect and label the dataset
Load the data (e.g., pandas read_csv). Assign meaningful column names if absent. Identify which column is the target label (y) and which are features (X). Call df.head() and df['target'].unique() to understand the structure. Confirm whether this is a classification or regression problem.
- 2
Encode categorical features
Identify qualitative features. Nominal features (no inherent order, e.g., country, color) → apply one-hot encoding. Ordinal features (inherent order, e.g., ratings, age groups) → map to integers preserving the order. Binary string labels (e.g., 'G'/'H', 'yes'/'no') → convert to 0/1 using comparison and astype(int).
- 3
Explore feature distributions by class
Plot histograms of each feature, separated by class label (e.g., blue for class 0, red for class 1). Set density=True to normalize distributions for fair comparison across imbalanced classes. This reveals which features are most discriminative and whether class overlap is high or low.
- 4
Split into training, validation, and test sets
Shuffle the dataset first (e.g., df.sample(frac=1)). Split into approximately 60% train, 20% validation, 20% test — or 80/10/10 for larger datasets. Keep all three splits separate throughout the entire process. The test set must never influence any training or model selection decision.
- 5
Scale features using StandardScaler
Fit the StandardScaler on the training set only (fit_transform on X_train). Transform validation and test sets using the same fitted scaler (transform only — never refit on val/test). This prevents data leakage. Rebuild the data arrays using np.hstack to combine scaled X with y.
- 6
Address class imbalance via RandomOverSampler
Check class counts in the training set. If one class outnumbers another significantly, apply RandomOverSampler to X_train and y_train only. Confirm balance by summing each class in y_train after resampling. Do NOT oversample validation or test sets.
- 7
Train and evaluate candidate models
Train at least these classifiers using scikit-learn, fitting each on X_train / y_train, predicting on X_test: (1) KNeighborsClassifier — try K=1, 3, 5; (2) GaussianNB — Naive Bayes baseline; (3) LogisticRegression — note available penalties (L1, L2); (4) SVC — Support Vector Classifier. For regression tasks, swap classifiers for their regression equivalents.
- 8
Report performance using classification_report
For each model, run sklearn.metrics.classification_report(y_test, y_pred). Record accuracy, precision, recall, and F1 score per class. On imbalanced test sets, prioritize F1 score as the primary metric. Note which classes the model struggles with (low recall = missing true positives; low precision = too many false positives).
- 9
Select the best model and tune hyperparameters
Compare F1 scores across all candidate models. Use the validation set (not test set) to tune hyperparameters — e.g., K in KNN, penalty type in LogisticRegression, kernel in SVC. Only run the final chosen model on the test set once. The test loss/accuracy is the final reported performance.
- 10
Optionally escalate to a neural network
If classical models plateau, build a neural network with: an input layer (one neuron per feature), one or more hidden layers with activation functions (ReLU is a strong default for hidden layers, Sigmoid for binary output), and an output layer. Train using gradient descent and backpropagation. Monitor training loss and validation loss per epoch to detect overfitting.
// What are real examples of this framework in action?
A healthcare analyst has a tabular patient dataset with numerical features (blood pressure, glucose, BMI, age) and a binary outcome column (disease: yes/no). Classes are imbalanced — 70% negative, 30% positive.
Encode the binary label as 0/1. Plot feature histograms by class to spot discriminative features. Split 60/20/20. Apply StandardScaler to all features. Apply RandomOverSampler to training set only to balance classes. Train KNN (K=5), GaussianNB, LogisticRegression, and SVC. Compare F1 scores on the test set. Report the final model's classification_report. If F1 is still low, build a neural network with ReLU hidden layers.
An e-commerce company wants to classify product images into three categories: electronics, clothing, apparel. They have labeled images with extracted pixel-level features.
This is multi-class classification (3 discrete classes). Ensure features are numerical. Use one-hot encoding if any categorical metadata exists. Split data, scale features. Train SVC (often strong for high-dimensional feature spaces) and a neural network. Use classification_report to check per-class precision and recall — if one class consistently has low recall, it may need oversampling or additional training data.
A researcher has sensor readings from two types of particle events but the labels are uncertain. They want to explore structure in the data.
This is an unsupervised learning scenario. Skip the labels vector y. Apply feature scaling. Use a clustering algorithm (e.g., KMeans) to find natural groupings. Visualize clusters to see if they align with domain knowledge about the two particle types.
// What mistakes should you avoid when using this framework?
- Never fit StandardScaler on the validation or test set — always fit on training data only, then transform the others. Fitting on test data is data leakage.
- Never oversample the validation or test sets. Oversampling is only for the training set. Val/test sets must reflect real-world distribution to give honest performance estimates.
- Do not use the test set to select or tune models — that is what the validation set is for. The test set is used exactly once, for final reported performance.
- Accuracy alone is misleading on imbalanced datasets. Always report and prioritize F1 score, precision, and recall, especially when classes are not equally represented.
- Without activation functions, a neural network collapses into a linear model regardless of depth. Always include nonlinear activation functions (ReLU, Sigmoid, tanh) in hidden layers.
- SVM models are not robust to outliers — a single outlier can significantly shift the support vectors and hyperplane. Check your data for outliers before applying SVC.
- KNN performance is sensitive to K — too small (K=1) overfits; too large smooths over real boundaries. Always test multiple K values and compare on validation data.
- Failing to shuffle data before splitting can introduce temporal or ordering bias into the train/val/test sets, making evaluation unreliable.
- Feeding raw categorical string values (e.g., 'G', 'H') directly into a model will cause errors or nonsensical results. Always encode all features as numbers before training.
// What key machine learning terms should you know?
- Feature Vector
- A single row of the features matrix X — all the input values for one sample/data point that are fed into the model to produce a prediction.
- Features Matrix X
- The full 2D array of all input features across all samples. Each row is one sample; each column is one feature.
- Labels Vector y
- The 1D array of true output labels or target values, one per sample. This is what the model is trying to predict.
- Loss
- A numerical quantity representing the difference between the model's prediction and the true label. Training exists to minimize loss.
- L1 Loss
- Loss function computed as the absolute value of (true value − predicted value), summed across all samples. Penalizes all errors equally regardless of magnitude.
- L2 Loss
- Loss function computed as the square of (true value − predicted value), summed across all samples. Penalizes large errors much more than small ones (quadratic penalty).
- Binary Cross-Entropy Loss
- The standard loss function used for binary classification tasks. Loss decreases as the model's predicted probability gets closer to the true binary label.
- Training Set
- The portion of data (≈60-80%) used to fit the model. The loss from this set is fed back into the model to update weights.
- Validation Set
- A held-out portion of data (≈10-20%) used as a reality check during or after training to ensure the model generalizes to unseen data. The loss here does NOT feed back into the model.
- Test Set
- A completely held-out portion of data (≈10-20%) used exactly once after model selection to report final real-world performance.
- One-Hot Encoding
- A technique for encoding nominal categorical features: each category becomes its own binary column. A sample belonging to that category gets a 1; all other category columns get 0.
- Nominal Data
- Categorical data with no inherent order between categories (e.g., nationality, color). Must be one-hot encoded.
- Ordinal Data
- Categorical data with an inherent order between categories (e.g., ratings from bad to great, age groups). Can be encoded as ordered integers.
- StandardScaler
- A preprocessing step that normalizes each feature column by subtracting its mean and dividing by its standard deviation, putting all features on a comparable scale.
- RandomOverSampler
- A technique to address class imbalance in the training set by randomly duplicating samples from the minority class until all classes are balanced.
- K Nearest Neighbors (KNN)
- A classification model that assigns a label to a new data point based on the majority label among its K closest neighbors in feature space, using Euclidean distance.
- Euclidean Distance
- The straight-line distance between two points in feature space, computed as the square root of the sum of squared differences across all feature dimensions.
- Naive Bayes
- A probabilistic classifier based on Bayes' rule that assumes all features are conditionally independent given the class label. Predicts the class with the highest posterior probability (MAP).
- MAP (Maximum A Posteriori)
- The decision rule used in Naive Bayes: pick the class K that maximizes the posterior probability — the prior probability of that class multiplied by the likelihood of the observed features given that class.
- Logistic Regression
- A binary (or multi-class) classification model that fits data to the sigmoid function, outputting a probability between 0 and 1. Simple logistic regression uses one feature; multiple logistic regression uses many.
- Sigmoid Function
- A mathematical function s(x) = 1 / (1 + e^(−x)) that maps any real number to a value between 0 and 1. Used as the output activation for binary classification.
- Support Vector Machine (SVM)
- A classifier that finds the hyperplane that best separates two classes by maximizing the margin — the distance between the hyperplane and the nearest data points from each class.
- Support Vectors
- The data points that lie on the margin lines in an SVM. These are the points that define and constrain the position of the separating hyperplane.
- Margin
- In SVM, the distance between the separating hyperplane and the nearest data points of each class. SVM maximizes this margin.
- Kernel Trick
- An SVM technique that transforms features into a higher-dimensional space (e.g., adding an x² feature) to make non-linearly separable data separable by a hyperplane.
- Hyperplane
- The decision boundary used by SVM to separate classes. In 2D it is a line; in 3D a plane; in higher dimensions a hyperplane.
- Neural Network (Neural Net)
- A model composed of an input layer, one or more hidden layers, and an output layer. Each layer contains neurons that compute a weighted sum of inputs plus a bias, passed through an activation function.
- Activation Function
- A nonlinear function applied to a neuron's output to prevent the network from collapsing into a linear model. Common examples: ReLU (max(0,x)), Sigmoid (0 to 1), tanh (−1 to 1).
- Gradient Descent
- The optimization algorithm used to train neural networks. It computes the slope of the loss with respect to each weight and updates the weights in the direction that reduces loss.
- Backpropagation
- The algorithm that computes how much each weight in a neural network contributed to the loss, enabling gradient descent to update weights layer by layer.
- Precision
- Of all samples the model labeled as a particular class, the fraction that truly belong to that class. High precision = few false positives.
- Recall
- Of all samples that truly belong to a particular class, the fraction the model correctly identified. High recall = few false negatives.
- F1 Score
- The harmonic mean of precision and recall. The preferred metric when classes are imbalanced, as it balances both false positives and false negatives.
- Classification
- A supervised learning task where the model predicts which discrete class a sample belongs to. Binary classification = two classes; multi-class classification = more than two.
- Regression
- A supervised learning task where the model predicts a continuous numerical value (e.g., price, temperature) rather than a discrete class.
// FREQUENTLY ASKED QUESTIONS
What is the Kylie Ying ML for Everyone Framework?
It's a structured, beginner-accessible machine learning methodology for taking any tabular dataset from raw data to an evaluated model. It covers the full pipeline: inspecting data, encoding categorical features, splitting into train/validation/test sets, scaling, handling class imbalance, training multiple models like KNN and SVM, and evaluating with precision, recall, and F1 score. It works for classification, regression, and clustering problems.
What is the difference between supervised and unsupervised learning?
Supervised learning uses labeled data — each sample has a known output label — so the model can compare its predictions to the truth and adjust. Unsupervised learning finds structure in unlabeled data through clustering, without any predefined output. Use supervised learning for classification and regression; use unsupervised learning (like KMeans) when you want to discover natural groupings in data you haven't labeled.
How do I use this ML framework on my own dataset?
Load your data and identify features (X) and target (y), then encode categorical columns as numbers, explore feature distributions by class, and shuffle before splitting into ~60% train, 20% validation, 20% test. Scale features with StandardScaler fit only on training data, address class imbalance with RandomOverSampler on the training set only, train several candidate models, and report F1, precision, and recall on the test set.
How do I know if my problem is classification or regression?
It's classification if you're predicting a discrete class (like disease yes/no or product category) and regression if you're predicting a continuous value (like price or temperature). Check your target column: if it contains distinct categories or labels, it's classification; if it contains continuous numbers, it's regression. This framework handles both by swapping scikit-learn classifiers for their regression equivalents.
How does this framework compare to just running a single scikit-learn model?
This framework enforces disciplined preprocessing and honest evaluation that a single quick model call skips. It requires proper train/validation/test separation, scaling fit only on training data, oversampling only the training set, and F1-based comparison across multiple models. A one-off model call often leaks test data, ignores class imbalance, and reports misleading accuracy — leading to models that look great but fail in production.
When should I use this framework instead of a no-code AutoML tool?
Use this framework when you want to understand and control each step — encoding, scaling, imbalance handling, and metric choice — rather than trusting a black box. It's ideal when learning ML fundamentals, working with tabular data, needing to justify modeling decisions, or debugging why a model underperforms. AutoML is faster but hides the exact decisions that cause data leakage and misleading accuracy on imbalanced data.
What results can I expect after applying this framework?
You'll produce a trained model with an honest, leak-free performance report showing precision, recall, and F1 per class on a held-out test set. You'll know which of several candidate models performs best, which classes it struggles with, and whether you need a neural network. Most importantly, your reported numbers reflect real-world generalization rather than inflated accuracy from data leakage or class imbalance.
How do I handle imbalanced classes in my dataset?
Apply RandomOverSampler to duplicate minority-class samples until classes are balanced — but only on the training set, never on validation or test. Then report F1 score, precision, and recall instead of accuracy, since accuracy is misleading when one class dominates. Oversampling the validation or test sets is data leakage and gives dishonest performance estimates that won't hold in production.
Why can't I train and evaluate on the same data?
Training and evaluating on the same data gives inflated performance because the model has already seen the answers — it memorizes rather than generalizes. Split into training (~60-80%), validation (~10-20%), and test (~10-20%) sets. Training adjusts the model, validation reality-checks it during tuning, and the test set — used exactly once — reports true performance on data the model has never seen.
Which model should I start with for a classification problem?
Start by training several baselines simultaneously: KNN (try K=1, 3, 5), Gaussian Naive Bayes, Logistic Regression, and SVC. Compare their F1 scores on the test set rather than picking one blindly. SVC often excels in high-dimensional feature spaces, Naive Bayes gives a fast baseline, and KNN is intuitive. Only escalate to a neural network if these classical models plateau.