Classification in Machine Learning: Types, Algorithms, Metrics and How to Train One Online
Classification in machine learning is the task of predicting a discrete label, such as spam or not spam, which of five product categories an item belongs to, or which tags apply to a document. A classification model learns that mapping from labeled examples and outputs a class, or a probability for each class. For most tabular data a gradient-boosted tree model such as XGBoost or LightGBM is the strongest starting point, while images and text usually call for neural networks. On TensorTurn you can train a classification model online by uploading a labeled dataset and describing the model in plain English: it writes and runs the full Python notebook for you.
What is classification in machine learning?
Classification is a form of supervised learning. You give the algorithm rows of input features (age, plan type, number of logins, pixel values, words) together with a known label for each row. The algorithm learns a decision rule that separates the classes, and then applies that rule to new rows whose label is unknown. The output is either a hard class (approve or decline) or, more usefully, a probability that you can rank, threshold and act on.
Classification differs from regression in one simple way: the target is a category, not a continuous number. Predicting whether a house sells above asking price is classification; predicting the sale price itself is regression. If your target has a handful of distinct values with no meaningful order, you are almost certainly looking at a classification problem.
Binary vs multiclass vs multilabel classification
Before choosing an algorithm, pin down the shape of the target. The three variants look similar but need different output layers, losses and metrics.
| Type | What the model predicts | Example | Typical output and loss |
|---|---|---|---|
| Binary | One of two classes | Churn vs stay, fraud vs legitimate, spam vs ham | One probability, sigmoid with log loss (binary cross-entropy) |
| Multiclass | Exactly one of three or more classes | Product category, digit 0 to 9, plant disease type | One probability per class summing to 1, softmax with categorical cross-entropy |
| Multilabel | Any subset of labels, zero or more at once | Tags on a support ticket, objects present in a photo | An independent sigmoid per label, binary cross-entropy per label |
A common mistake is to treat a multilabel problem as multiclass by concatenating labels into combinations. That explodes the number of classes and starves rare combinations of examples. Use one output per label instead, or a one-vs-rest wrapper around a binary classifier.
Which classification algorithms should you use?
There is no single best classifier, but there is a sensible default for each kind of data. Start simple, establish a baseline, and only add complexity when the baseline clearly underfits.
| Algorithm | Best for | Strengths | Watch out for |
|---|---|---|---|
| Logistic regression | Baselines, small or wide tabular data, regulated settings | Fast, interpretable coefficients, well-calibrated probabilities | Misses non-linear interactions unless you engineer features; needs scaling and encoding |
| Random forest | Medium tabular data with mixed feature types | Robust with little tuning, hard to overfit badly, gives feature importance | Larger models, slower inference, probabilities often need calibration |
| XGBoost / LightGBM | Most tabular classification problems | Usually the top performer on structured data, handles missing values natively, fast | Needs early stopping and some tuning; can overfit small datasets |
| Linear SVM or Naive Bayes | Sparse text features such as TF-IDF | Very fast, strong text baselines | Limited on dense, non-linear tabular data |
| Neural networks (CNN, transformer, MLP) | Images, text, audio, very large datasets | Learn features directly from raw data, transfer learning from pretrained models | Need more data and GPU compute; usually overkill for small tables |
How to evaluate a classification model
Accuracy is the metric everyone reaches for first and the one most likely to mislead you. If 95 percent of transactions are legitimate, a model that always says legitimate scores 95 percent accuracy and catches no fraud at all. Pick the metric that matches the cost of each kind of error.
| Metric | What it tells you | Use it when |
|---|---|---|
| Accuracy | Share of all predictions that are correct | Classes are roughly balanced and errors cost the same |
| Precision | Of the rows flagged positive, how many really are | False alarms are expensive (blocking a good customer) |
| Recall | Of the real positives, how many you caught | Missing a positive is expensive (fraud, disease) |
| F1 score | Harmonic mean of precision and recall | You need one number that balances both |
| ROC-AUC | How well the model ranks positives above negatives across all thresholds | Comparing models on reasonably balanced data |
| PR-AUC | Precision-recall trade-off across thresholds | The positive class is rare |
| Log loss | How good the predicted probabilities are, not just the ranking | You act on probabilities directly, such as pricing or risk scores |
Always look at the confusion matrix alongside a summary number. It shows exactly which classes get confused with which, and that is usually where the next improvement comes from. Remember that the default 0.5 decision threshold is arbitrary; for many business problems a different threshold gives a far better trade-off.
Common classification mistakes
- Data leakage: a feature that is only known after the outcome (a refund flag, a cancellation date) makes validation scores look superb and production scores collapse.
- Random splits on time-ordered data: if the model will predict the future, validate on a later period, not on shuffled rows.
- Ignoring class imbalance: use stratified splits, class weights and recall or PR-AUC instead of accuracy.
- Noisy labels: a few percent of wrong labels can cap the accuracy of any model, so audit labels before tuning algorithms.
- Tuning on the test set: once you choose hyperparameters by looking at test scores, the test score is no longer an honest estimate.
How to train a classification model online with TensorTurn
- Upload your data as CSV, TSV, JSON or JSONL, Parquet or Excel, or import it from a URL, Hugging Face or Kaggle. For image classification, upload a zip, rar or 7z archive of images.
- Pick your target column. Target analysis shows the class balance, the predictive signal of each feature, leakage flags for features that look suspiciously predictive, and whether missing values depend on the target.
- Fix problems in the AI data editor: describe the change in plain English, review the planned steps, and approve them. Your rows stay in your browser.
- Describe the classifier in chat, for example: predict the churned column with LightGBM, use a stratified split and report recall and PR-AUC. TensorTurn generates and runs the whole notebook with scikit-learn, XGBoost, LightGBM, PyTorch or Keras.
- Run it on isolated cloud GPUs, or free on your own connected GPU. If a cell errors, the AI reads the traceback, patches only that cell and retries.
- Review the reported metrics, ask for changes in plain English, then save the best weights and deploy an authenticated /predict API endpoint that scales to zero.
For worked, end-to-end examples, see the use-case guides for customer churn prediction, spam detection and image classification, which apply these steps to a specific dataset.
Frequently asked questions
What is the difference between classification and regression?
Classification predicts a category, such as yes or no or one of several product types. Regression predicts a continuous number, such as a price or a temperature. The choice depends only on the type of target you want to predict.
Which algorithm is best for classification?
For tabular data, gradient boosting with XGBoost or LightGBM is usually the strongest option, with logistic regression as a fast, interpretable baseline. For images and text, neural networks, often fine-tuned from a pretrained model, usually win.
How many examples do I need to train a classifier?
A simple tabular classifier can work with a few hundred labeled rows, but thousands are better, and every class needs enough examples for the model to learn its pattern. Image classifiers built with transfer learning can work with a few hundred images per class.
Why is my classifier's accuracy high but its predictions useless?
This usually means the classes are imbalanced and the model mostly predicts the majority class, or that a leaky feature gives away the answer. Check the confusion matrix, recall and PR-AUC, and look for features that would not exist at prediction time.
Can I train a classification model online without coding?
Yes. On TensorTurn you upload a labeled dataset, describe the model in plain English, and it generates and runs the full Python notebook. You can still read and edit every cell if you want control over the code.