{"id":5250,"date":"2026-11-19T12:09:32","date_gmt":"2026-11-19T12:09:32","guid":{"rendered":"https:\/\/gyanipandit.com\/programming\/?p=5250"},"modified":"2026-11-19T12:09:32","modified_gmt":"2026-11-19T12:09:32","slug":"types-of-machine-learning","status":"publish","type":"post","link":"https:\/\/gyanipandit.com\/programming\/types-of-machine-learning\/","title":{"rendered":"Types of Machine Learning: Supervised, Unsupervised, Semi-Supervised and Reinforcement"},"content":{"rendered":"<p>Machine learning algorithms are usually grouped by <strong>how they learn<\/strong>: whether they are given the correct answers (labels) while learning, only some answers, or no answers at all, or whether they learn by trial and error. The four main types are <strong>supervised<\/strong>, <strong>unsupervised<\/strong>, <strong>semi-supervised<\/strong> and <strong>reinforcement learning<\/strong>. A fifth idea, <strong>self-supervised learning<\/strong>, is behind today&#8217;s large language models.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"480\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2023\/03\/Types-of-Machine-Learning.jpg\" alt=\"Types of machine learning\" class=\"wp-image-5255 aligncenter\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2023\/03\/Types-of-Machine-Learning.jpg 640w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2023\/03\/Types-of-Machine-Learning-300x225.jpg 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/p>\n<h2>Types of Machine Learning at a Glance<\/h2>\n<table>\n<thead>\n<tr>\n<th>Type<\/th>\n<th>Learns from<\/th>\n<th>Typical tasks<\/th>\n<th>Examples<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Supervised<\/td>\n<td>Labelled data (input + correct answer)<\/td>\n<td>Classification, regression<\/td>\n<td>Spam detection, house price prediction<\/td>\n<\/tr>\n<tr>\n<td>Unsupervised<\/td>\n<td>Unlabelled data<\/td>\n<td>Clustering, association, anomaly detection<\/td>\n<td>Customer groups, &#8220;bought together&#8221; products<\/td>\n<\/tr>\n<tr>\n<td>Semi-supervised<\/td>\n<td>A little labelled + a lot of unlabelled data<\/td>\n<td>Classification with few labels<\/td>\n<td>Labelling large photo or document collections<\/td>\n<\/tr>\n<tr>\n<td>Reinforcement<\/td>\n<td>Rewards and penalties from an environment<\/td>\n<td>Decision-making, control<\/td>\n<td>Game-playing agents, robot movement<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>1. Supervised Learning<\/h2>\n<p>The model is trained on examples where we already know the answer. It learns the link between inputs and outputs, then predicts answers for new inputs.<\/p>\n<ul>\n<li><strong>Classification:<\/strong> the output is a category. Is this email spam or not? Will the student pass or fail?<\/li>\n<li><strong>Regression:<\/strong> the output is a number. What will this flat sell for? How many units will we sell next month?<\/li>\n<\/ul>\n<p><strong>Common algorithms:<\/strong> linear and logistic regression, k-nearest neighbours (k-NN), decision trees, random forests, support vector machines, naive Bayes and neural networks.<\/p>\n<h3>A Tiny Supervised Example in Python<\/h3>\n<p>Here a 1-nearest-neighbour model predicts pass\/fail from study hours and attendance, using a few labelled examples. Real projects use libraries such as scikit-learn, but this shows the idea in plain Python:<\/p>\n<pre class=\"wp-block-code\"><code>students = [\n    ((1, 50), \"fail\"),\n    ((2, 60), \"fail\"),\n    ((3, 65), \"fail\"),\n    ((5, 80), \"pass\"),\n    ((6, 85), \"pass\"),\n    ((8, 90), \"pass\"),\n]   # ((hours of study per day, attendance %), result)\n\ndef distance(a, b):\n    return ((a[0] - b[0]) ** 2 + ((a[1] - b[1]) \/ 10) ** 2) ** 0.5\n\ndef predict(new):\n    nearest = min(students, key=lambda s: distance(s[0], new))\n    return nearest[1]\n\nfor new in [(4, 75), (2, 55), (7, 88)]:\n    print(new, \"-&gt;\", predict(new))<\/code><\/pre>\n<p><strong>Output:<\/strong><\/p>\n<pre class=\"wp-block-code\"><code>(4, 75) -&gt; pass\n(2, 55) -&gt; fail\n(7, 88) -&gt; pass<\/code><\/pre>\n<p>The model never saw these three students, but it predicts their result from the most similar labelled example. That is supervised learning in a nutshell.<\/p>\n<h2>2. Unsupervised Learning<\/h2>\n<p>The data has no labels. The model looks for structure on its own.<\/p>\n<ul>\n<li><strong>Clustering:<\/strong> grouping similar items, such as customer segments by buying habits.<\/li>\n<li><strong>Association rules:<\/strong> finding items that occur together, as in &#8220;people who bought bread also bought butter&#8221;.<\/li>\n<li><strong>Anomaly detection:<\/strong> spotting unusual data, such as a strange login or a faulty sensor reading.<\/li>\n<li><strong>Dimensionality reduction:<\/strong> compressing many features into a few (for example, PCA).<\/li>\n<\/ul>\n<h3>A Tiny Clustering Example<\/h3>\n<p>Here a simple version of the k-means algorithm splits marks into two groups without being told which group any mark belongs to:<\/p>\n<pre class=\"wp-block-code\"><code>marks = [35, 42, 38, 88, 91, 79, 45, 85]\nc1, c2 = min(marks), max(marks)        # starting centres\nfor _ in range(10):\n    g1 = [m for m in marks if abs(m - c1) &lt;= abs(m - c2)]\n    g2 = [m for m in marks if abs(m - c1) &gt; abs(m - c2)]\n    c1, c2 = sum(g1) \/ len(g1), sum(g2) \/ len(g2)\nprint(sorted(g1), round(c1, 1))\nprint(sorted(g2), round(c2, 1))<\/code><\/pre>\n<p><strong>Output:<\/strong><\/p>\n<pre class=\"wp-block-code\"><code>[35, 38, 42, 45] 40.0\n[79, 85, 88, 91] 85.8<\/code><\/pre>\n<h2>3. Semi-Supervised Learning<\/h2>\n<p>Labelling data is slow and expensive; a doctor labelling X-rays, for instance. Semi-supervised learning uses a small labelled set together with a large unlabelled set. The model learns from the labelled part and uses the patterns in the unlabelled part to improve. It is common in image, speech and text tasks.<\/p>\n<h2>4. Reinforcement Learning<\/h2>\n<p>An <strong>agent<\/strong> takes actions in an <strong>environment<\/strong> and receives <strong>rewards<\/strong> or <strong>penalties<\/strong>. Over many attempts it learns a strategy that earns the most reward, much like a child learning to ride a bicycle. Reinforcement learning is used in game-playing programs, robotics, recommendation systems and resource management, and a variant using human feedback is used to fine-tune chatbots.<\/p>\n<h2>What About Self-Supervised Learning?<\/h2>\n<p>In self-supervised learning, the data provides its own labels. For example, a language model hides the next word of a sentence and learns to predict it, over billions of sentences, with no human labelling. This is how large language models learn language before they are fine-tuned. It is often counted as a special case of unsupervised or supervised learning.<\/p>\n<h2>How to Choose the Right Type<\/h2>\n<ul>\n<li>You have historical data <strong>with the right answers<\/strong> and want to predict them for new cases: <strong>supervised<\/strong>.<\/li>\n<li>You have data <strong>without answers<\/strong> and want to discover groups or unusual items: <strong>unsupervised<\/strong>.<\/li>\n<li>You have a few labels and lots of unlabelled data: <strong>semi-supervised<\/strong>.<\/li>\n<li>Your system must <strong>make a series of decisions<\/strong> and learn from the outcome: <strong>reinforcement<\/strong>.<\/li>\n<\/ul>\n<h2>Frequently Asked Questions<\/h2>\n<h3>What are the 4 types of machine learning?<\/h3>\n<p>Supervised, unsupervised, semi-supervised and reinforcement learning.<\/p>\n<h3>What is the difference between supervised and unsupervised learning?<\/h3>\n<p>Supervised learning trains on labelled data (with correct answers); unsupervised learning finds patterns in data without labels.<\/p>\n<h3>Is clustering supervised or unsupervised?<\/h3>\n<p>Unsupervised, because the groups are not given in advance.<\/p>\n<p>Related: <a href=\"https:\/\/gyanipandit.com\/programming\/machine-learning-vs-ai\/\">machine learning vs AI<\/a> \u00b7 <a href=\"https:\/\/gyanipandit.com\/programming\/what-is-machine-learning\/\">what is machine learning<\/a> \u00b7 <a href=\"https:\/\/gyanipandit.com\/programming\/learn-machine-learning-with-python\/\">learn machine learning with Python<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Machine learning algorithms are usually grouped by how they learn: whether they are given the correct answers (labels) while learning, only some answers, or no answers at all, or whether they learn by trial and error. The four main types are supervised, unsupervised, semi-supervised and reinforcement learning. A fifth idea, self-supervised learning, is behind today&#8217;s &#8230; <a title=\"Types of Machine Learning: Supervised, Unsupervised, Semi-Supervised and Reinforcement\" class=\"read-more\" href=\"https:\/\/gyanipandit.com\/programming\/types-of-machine-learning\/\" aria-label=\"Read more about Types of Machine Learning: Supervised, Unsupervised, Semi-Supervised and Reinforcement\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":5255,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[152],"tags":[145,144],"class_list":["post-5250","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-machine-learning","tag-machine-learning","tag-types-of-machine-learning"],"_links":{"self":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/5250","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/comments?post=5250"}],"version-history":[{"count":6,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/5250\/revisions"}],"predecessor-version":[{"id":6147,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/5250\/revisions\/6147"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/media\/5255"}],"wp:attachment":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/media?parent=5250"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/categories?post=5250"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/tags?post=5250"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}