tensorturnBETA
Home › Machine Learning Tasks

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.

TypeWhat the model predictsExampleTypical output and loss
BinaryOne of two classesChurn vs stay, fraud vs legitimate, spam vs hamOne probability, sigmoid with log loss (binary cross-entropy)
MulticlassExactly one of three or more classesProduct category, digit 0 to 9, plant disease typeOne probability per class summing to 1, softmax with categorical cross-entropy
MultilabelAny subset of labels, zero or more at onceTags on a support ticket, objects present in a photoAn 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.

AlgorithmBest forStrengthsWatch out for
Logistic regressionBaselines, small or wide tabular data, regulated settingsFast, interpretable coefficients, well-calibrated probabilitiesMisses non-linear interactions unless you engineer features; needs scaling and encoding
Random forestMedium tabular data with mixed feature typesRobust with little tuning, hard to overfit badly, gives feature importanceLarger models, slower inference, probabilities often need calibration
XGBoost / LightGBMMost tabular classification problemsUsually the top performer on structured data, handles missing values natively, fastNeeds early stopping and some tuning; can overfit small datasets
Linear SVM or Naive BayesSparse text features such as TF-IDFVery fast, strong text baselinesLimited on dense, non-linear tabular data
Neural networks (CNN, transformer, MLP)Images, text, audio, very large datasetsLearn features directly from raw data, transfer learning from pretrained modelsNeed 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.

MetricWhat it tells youUse it when
AccuracyShare of all predictions that are correctClasses are roughly balanced and errors cost the same
PrecisionOf the rows flagged positive, how many really areFalse alarms are expensive (blocking a good customer)
RecallOf the real positives, how many you caughtMissing a positive is expensive (fraud, disease)
F1 scoreHarmonic mean of precision and recallYou need one number that balances both
ROC-AUCHow well the model ranks positives above negatives across all thresholdsComparing models on reasonably balanced data
PR-AUCPrecision-recall trade-off across thresholdsThe positive class is rare
Log lossHow good the predicted probabilities are, not just the rankingYou 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

How to train a classification model online with TensorTurn

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.

Start building free

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.