labeled data

what is supervised learning
Artificial Intelligence, Featured Articles

What Is Supervised Learning? A Beginner’s Guide

Supervised learning is a type of machine learning where a model learns from examples that already include the correct answer. You show the model many inputs together with their known outputs. The model finds the pattern that connects them, and then it uses that pattern to make predictions on new data it has never seen. That is the short answer to “what is supervised learning?” This guide expands on it in plain English. You will learn the key terms, see how training and prediction work, run a small Python example, and understand where supervised learning works well and where it struggles. Table of contents What is supervised learning? The key terms you need to know How supervised learning works step by step A simple supervised learning example The two main types of supervised learning Common applications Advantages and limitations Supervised vs unsupervised learning Where to go next Frequently asked questions Conclusion What is supervised learning? Think about how a child learns to recognize fruit. A parent points at an apple and says “apple.” Later the parent points at a banana and says “banana.” After enough examples, the child can name a fruit they have never seen in that exact shape or color. The parent acts as the supervisor, because the parent supplies the right answer for every example. Supervised learning works the same way. The “supervisor” is the labeled dataset. Each row of data comes with the answer the model should learn to produce. The algorithm studies thousands of these pairs and adjusts itself until its own guesses match the known answers as closely as possible. The real goal is not to memorize the examples. The goal is generalization: making good predictions on new data. Everything else in supervised learning, from splitting your data to choosing a metric, exists to check whether the model generalizes. The key terms you need to know Four terms appear in almost every supervised learning tutorial. Learn them once and the rest of the topic becomes much easier to read. Labeled dataset A labeled dataset is a table in which every example includes the correct answer. In a spam filter, each email is an example, and its label is “spam” or “not spam.” People often create labels by hand, collect them from past records, or measure them with sensors. Good labels matter a great deal, because the model learns whatever the labels teach it, including mistakes. Features Features are the input columns that describe each example. For a house, the features might be size, number of bedrooms, and neighborhood. For an email, they might be the number of links, certain words, and the sender’s domain. You may also see features called inputs, predictors, or independent variables. Programmers usually write the feature table as X. Target variable The target variable is the answer you want the model to predict. It is also called the label, the output, or the dependent variable. In the house example, the target is the sale price. Programmers usually write it as y. Model and parameters The model is the mathematical function that turns features into a prediction. It contains internal numbers called parameters (also called weights). Training means finding parameter values that make the predictions match the labels well. How supervised learning works step by step Most supervised learning projects follow the same basic path. The details change from one algorithm to another, but the outline stays the same. Step 1: Collect and prepare labeled data You gather examples and make sure each one has a label. You also clean the data, handle missing values, and convert text categories into numbers when the algorithm requires it. Step 2: Split the data You set aside part of the data before training starts. The model trains on the larger part, called the training set. You keep the smaller part, called the test set, hidden until the end. The article on training data vs testing data explains this split in detail. Step 3: Train the model During training, the algorithm makes predictions on the training examples and compares them with the true labels. A loss function measures how wrong the predictions are. The algorithm then adjusts its parameters to reduce that loss. It repeats this cycle many times, or it solves for the best parameters in one calculation, depending on the method. Step 4: Make predictions After training, you give the model features from new examples, and it returns predicted targets. In scikit-learn, this is the predict() method. The model does not see the true answers at this stage. Step 5: Evaluate and improve You compare the predictions on the test set with the real labels and calculate a metric such as accuracy or error. If performance is poor, you can try better features, a different algorithm, or different settings. The guide to supervised learning model evaluation covers the metrics in depth. A simple supervised learning example Here is a tiny example you can run yourself. Suppose a teacher records how many hours eight students studied and slept, and whether each student passed. The two numbers are the features. Passing is the target: 1 means passed and 0 means failed. from sklearn.neighbors import KNeighborsClassifier # Features: [hours_studied, hours_slept]; target: 1 = passed, 0 = failed X = [[1, 5], [2, 6], [3, 5], [4, 7], [6, 6], [7, 8], [8, 7], [9, 6]] y = [0, 0, 0, 0, 1, 1, 1, 1] model = KNeighborsClassifier(n_neighbors=3) model.fit(X, y) # training print(model.predict([[5, 7], [2, 5]])) # prediction on new students The code uses the k-nearest neighbors algorithm, one of the simplest supervised methods. The fit() call trains the model. The predict() call looks at each new student, finds the three most similar students in the training data, and lets them vote. When I ran this code, it printed: [1 0] The model predicts that the student who studied 5 hours and slept 7 hours will pass, and that the student who studied 2 hours and slept 5 hours will fail. Eight rows are far

Scroll to Top