

{"id":4957,"date":"2017-12-15T08:09:56","date_gmt":"2017-12-15T08:09:56","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=4957"},"modified":"2021-08-25T17:25:58","modified_gmt":"2021-08-25T11:55:58","slug":"classification-in-r","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/classification-in-r\/","title":{"rendered":"Classification in R Programming: The all in one tutorial to master the concept!"},"content":{"rendered":"<p>In this tutorial, we will study the classification in R thoroughly. We will also cover the Decision Tree, Na\u00efve Bayes Classification and Support Vector Machine. To understand it in the best manner, we will use images and real-time examples.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Classification-in-R.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-63033\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Classification-in-R.jpg\" alt=\"Classification in R\" width=\"802\" height=\"420\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Classification-in-R.jpg 802w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Classification-in-R-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Classification-in-R-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Classification-in-R-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Classification-in-R-520x272.jpg 520w\" sizes=\"auto, (max-width: 802px) 100vw, 802px\" \/><\/a><\/p>\n<h2>Introduction to Classification in R<\/h2>\n<p><span style=\"font-weight: 400\">We use it to predict a categorical class label, such as weather: rainy, sunny, cloudy or snowy.<\/span><\/p>\n<h3>Important points of Classification in R<\/h3>\n<p><span style=\"font-weight: 400\">There are various classifiers available:<\/span><br \/>\n<b><\/b><\/p>\n<ul>\n<li><b>Decision Trees &#8211;<\/b> These are organised in the form of sets of questions and answers in the tree structure.<\/li>\n<li><strong>Naive Bayes Classifiers<\/strong> &#8211; A probabilistic machine learning model that is used for classification.<br \/>\n<b><\/b><\/li>\n<li><b>K-NN Classifiers &#8211;<\/b><span style=\"font-weight: 400\"> Based on the similarity measures like distance, it classifies new cases.<\/span><\/li>\n<li><span style=\"font-weight: 400\"><strong>Support Vector Machines<\/strong> &#8211; It is a non-probabilistic binary linear classifier that builds a model to classify a case into one of the two categories.<\/span><br \/>\n<b><\/b><\/li>\n<\/ul>\n<p>An example of classification in R through Support Vector Machine is the usage of classification() function:<\/p>\n<p>classification(trExemplObj,classLabels,valExemplObj=NULL,kf=5,kernel=\u201dlinear\u201d)<\/p>\n<p><em><strong>Wait! Have you completed the <a href=\"https:\/\/data-flair.training\/blogs\/clustering-in-r-tutorial\/\">tutorial on Clustering in R<\/a><\/strong><\/em><\/p>\n<p><b>Arguments:<\/b><br \/>\n<b><\/b><\/p>\n<p><b>1. trExemplObj &#8211;\u00a0<\/b>It is an exemplars train eSet object.<br \/>\n<b><\/b><\/p>\n<p><b>2. classLabels &#8211;\u00a0<\/b>It is being stored in eSet object as variable name e.g &#8220;type&#8221;.<br \/>\n<b><\/b><\/p>\n<p><b>3. valExemplObj &#8211;\u00a0<\/b>It is known as exemplars validation eSet object.<br \/>\n<b><\/b><\/p>\n<p><b>4. kf &#8211;\u00a0<\/b>It is termed as the k-folds value of the cross-validation parameter. Also, the default value is 5-folds. By setting &#8220;Loo&#8221; or &#8220;LOO&#8221; a <strong>Leave-One-Out Cross-Validation<\/strong> which we have to perform.<br \/>\n<b><\/b><\/p>\n<p><b>5. kernel &#8211;\u00a0<\/b>In classification analysis, we use a type of Kernel. The default kernel is &#8220;linear&#8221;.<br \/>\n<b><\/b><\/p>\n<p><b>6. classL &#8211;\u00a0<\/b>The labels of the train set.<br \/>\n<b><\/b><\/p>\n<p><b>7. valClassL &#8211;\u00a0<\/b>It is termed as the labels of the validation set if not NULL.<br \/>\n<b><\/b><\/p>\n<p><b>8. predLbls &#8211;\u00a0<\/b>It is defined as the predicted labels according to the classification analysis.<\/p>\n<h3>Decision Tree in R<\/h3>\n<p><span style=\"font-weight: 400\">It is a type of supervised learning algorithm. We use it for classification problems. It works for both types of input and output variables. In this technique, we split the population into two or more homogeneous sets. Moreover, it is based on the most significant splitter\/differentiator in input variables.<\/span><\/p>\n<p><span style=\"font-weight: 400\">The Decision Tree is a powerful non-linear classifier. A Decision Tree makes use of a tree-like structure to generate relationship among the various features and potential outcomes. It makes use of branching decisions as its core structure.<\/span><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/decisiontree.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-63401\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/decisiontree.png\" alt=\"decision tree in R\" width=\"802\" height=\"420\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/decisiontree.png 802w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/decisiontree-150x79.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/decisiontree-300x157.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/decisiontree-768x402.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/decisiontree-520x272.png 520w\" sizes=\"auto, (max-width: 802px) 100vw, 802px\" \/><\/a><\/p>\n<p>In classifying data, the Decision Tree follows the steps mentioned below:<\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">It puts all training examples to a root.<\/span><\/li>\n<\/ul>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Based on the various selected attributes, a Decision Tree divides these training examples.\u00a0<\/span><\/li>\n<\/ul>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Then it will select attributes by using some statistical measures.<\/span><\/li>\n<\/ul>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Recursive partitioning continues until no training example remains.<\/span><\/li>\n<\/ul>\n<h3>1. Important Terminologies related to Decision Tree<\/h3>\n<ul>\n<li><b>Root Node<\/b><span style=\"font-weight: 400\">:\u00a0<\/span><span style=\"font-weight: 400\">It represents the entire population or sample. Moreover, it gets divided into two or more homogeneous sets.<\/span><\/li>\n<\/ul>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Root-node-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-63403\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Root-node-1.png\" alt=\"Root-node in Decision Tree\" width=\"512\" height=\"268\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Root-node-1.png 512w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Root-node-1-150x79.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Root-node-1-300x157.png 300w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><\/p>\n<ul>\n<li><b>Splitting<\/b><span style=\"font-weight: 400\">: In this, we carry out the division of a node into two or more sub-nodes.<\/span><\/li>\n<li><b>Decision Tree<\/b><span style=\"font-weight: 400\">: It is produced w<\/span><span style=\"font-weight: 400\">hen a sub-node splits into further sub-nodes.\u00a0<\/span><\/li>\n<li><b>Leaf\/Terminal Node<\/b><span style=\"font-weight: 400\">: Nodes that do not split is called Leaf or Terminal node.<\/span><\/li>\n<li><b>Pruning:<\/b><span style=\"font-weight: 400\"> When we remove sub-nodes of a decision node, this process is called pruning. It is the opposite process of splitting.<\/span><\/li>\n<li><b>Branch \/ Sub-Tree<\/b><span style=\"font-weight: 400\">: A subsection of the entire tree is called branch or sub-tree.<\/span><\/li>\n<li><b>Parent and Child Node<\/b><span style=\"font-weight: 400\">:\u00a0<\/span>A node, which is divided into sub-nodes is called a parent node of sub-nodes whereas sub-nodes are the child of a parent node.<\/li>\n<\/ul>\n<h3>2. Types of Decision Tree<\/h3>\n<ul>\n<li><strong>Categorical(classification) Variable Decision Tree<\/strong><span style=\"font-weight: 400\">: Decision Tree which has a categorical target variable.<\/span><\/li>\n<li><strong>Continuous(Regression) Variable Decision Tree<\/strong><b>:<\/b><span style=\"font-weight: 400\"> Decision Tree has a continuous target variable.<\/span><\/li>\n<\/ul>\n<p><em><strong>Don&#8217;t forget to check out the <a href=\"https:\/\/data-flair.training\/blogs\/r-decision-trees\/\">R Decision Trees<\/a> in detail<\/strong><\/em><\/p>\n<h3>3. Categorical (classification) Trees vs Continuous (regression) Trees<\/h3>\n<p><span style=\"font-weight: 400\">Regression trees are used when the dependent variable is continuous while classification trees are used when the dependent variable is categorical.<\/span><br \/>\n<b><\/b><\/p>\n<p><span style=\"font-weight: 400\">In continuous, a value obtained is a mean response of observation.<\/span><br \/>\n<b><\/b><\/p>\n<p><span style=\"font-weight: 400\">In classification, a value obtained by a terminal node is a mode of observations.<\/span><br \/>\n<b><\/b><\/p>\n<p><span style=\"font-weight: 400\">There is one similarity in both cases. The splitting process continues results in grown trees until it reaches to stopping criteria. But, the grown tree is likely to overfit data, leading to poor accuracy on unseen data. This brings \u2018pruning\u2019. Pruning is one of the techniques which uses tackle overfitting.<\/span><\/p>\n<h3>4. Advantages of Decision Tree in R<\/h3>\n<ul>\n<li><b>Easy to Understand:\u00a0<\/b>It does not need any statistical knowledge to read and interpret them. Its graphical representation is very intuitive and users can relate their hypothesis.<\/li>\n<li><b>Less data cleaning required<\/b><span style=\"font-weight: 400\">:\u00a0<\/span>Compared to some other modeling techniques, it requires fewer data.<\/li>\n<li><span style=\"font-weight: 400\"><strong>Data type is not a constraint:<\/strong> It can handle both numerical and categorical variables.<\/span><br \/>\n<b><\/b><\/li>\n<li><span style=\"font-weight: 400\"><strong>S<\/strong><strong style=\"font-weight: 400\">imple to understand<\/strong> and interpret.<\/span><br \/>\n<b><\/b><\/li>\n<li><span style=\"font-weight: 400\">Requires<strong> little data preparation<\/strong>.<\/span><\/li>\n<li><b><\/b><span style=\"font-weight: 400\">It works with both <strong>numerical and categorical data<\/strong>.<\/span><br \/>\n<b><\/b><\/li>\n<li><span style=\"font-weight: 400\">Handles <strong>non-linearity<\/strong>.<\/span><br \/>\n<b><\/b><\/li>\n<li><span style=\"font-weight: 400\">Possible to confirm a<strong> model using statistical tests.<\/strong>\u00a0<\/span><br \/>\n<b><\/b><\/li>\n<li><span style=\"font-weight: 400\">It is <strong>robust<\/strong>. It performs well even if you deviate from assumptions.<\/span><br \/>\n<b><\/b><\/li>\n<li><span style=\"font-weight: 400\">It <strong>scales to Big Data<\/strong>.<\/span><\/li>\n<\/ul>\n<p><em><strong>You must definitely explore the <a href=\"https:\/\/data-flair.training\/blogs\/r-nonlinear-regression\/\">R Nonlinear Regression Analysis<\/a><\/strong><\/em><\/p>\n<h3>Disadvantages of R Decision Tree<\/h3>\n<ul>\n<li><b>Overfitting<\/b><span style=\"font-weight: 400\">: It is one of the most practical difficulties for Decision Tree models. By setting constraints on model parameters and pruning, we can solve this problem in <a href=\"https:\/\/en.wikipedia.org\/wiki\/R_(programming_language)\">R<\/a>.<\/span><br \/>\n<b><\/b><\/li>\n<li><b>Not fit for continuous variables<\/b><span style=\"font-weight: 400\">: At the time of using continuous numerical variables. Whenever it categorizes variables in different categories, the Decision Tree loses information.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">To learn globally optimal tree is NP-hard, <strong>algos rely on greedy search<\/strong>.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\"><strong>Complex \u201cif-then\u201d<\/strong> relationships between features <strong>inflate tree size<\/strong>. Example &#8211; XOR gate, multiplexor.<\/span><\/li>\n<\/ul>\n<h3>Introduction to Na\u00efve Bayes Classification<\/h3>\n<p><span style=\"font-weight: 400\">We use Bayes\u2019 theorem to make the prediction. It is based on prior knowledge and current evidence.<\/span><br \/>\n<b><\/b><\/p>\n<p>Bayes\u2019 theorem is expressed by the following equation:<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/P-AB-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-63402 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/P-AB-1.png\" alt=\"P AB - Na\u00efve Bayes Classification\" width=\"301\" height=\"118\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/P-AB-1.png 301w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/P-AB-1-150x59.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/P-AB-1-300x118.png 300w\" sizes=\"auto, (max-width: 301px) 100vw, 301px\" \/><\/a><\/p>\n<p>where P(A) and P(B) are the probability of events A and B without regarding each other. P(A|B) is the probability of A conditional on B and P(B|A) is the probability of B conditional on A.<\/p>\n<h2>Introduction to Support Vector Machines<\/h2>\n<h3>What is Support Vector Machine?<\/h3>\n<p><span style=\"font-weight: 400\">We use it to find the optimal hyperplane (line in 2D, a plane in 3D and hyperplane in more than 3 dimensions). Which helps in maximizes the margin between two classes. Support Vectors are observations that support hyperplane on either side.<\/span><br \/>\n<span style=\"font-weight: 400\">It helps in solving a linear optimization problem. It also helps out in finding the hyperplane with the largest margin. We use the \u201cKernel Trick\u201d to separate instances that are inseparable.<\/span><\/p>\n<h3>Terminologies related to R SVM<\/h3>\n<p><b>Why Hyperplane?<\/b><\/p>\n<p><span style=\"font-weight: 400\">It is a line in 2D and plane in 3D. In higher dimensions (more than 3D), it&#8217;s called as a hyperplane. Moreover, SVM helps us to find a hyperplane that can separate two classes.<\/span><br \/>\n<b><\/b><\/p>\n<p><b>What is Margin?<\/b><\/p>\n<p><span style=\"font-weight: 400\">A distance between the hyperplane and the closest data point is called a margin. But if we want to double it, then it would be equal to the margin.<\/span><br \/>\n<b><\/b><\/p>\n<p><b>How to find the optimal hyperplane?<\/b><\/p>\n<p><span style=\"font-weight: 400\">First, we have to select two hyperplanes. They must separate the data with no points between them. Then maximize the distance between these two hyperplanes. The distance here is &#8216;margin&#8217;.<\/span><br \/>\n<b><\/b><\/p>\n<p><b>What is Kernel?<\/b><\/p>\n<p><span style=\"font-weight: 400\">It is a method which helps to make SVM run, in case of non-linear separable data points. We use a kernel function to transforms the data into a higher dimensional feature space. And also with the help of it, perform the linear separation.<\/span><br \/>\n<b><\/b><\/p>\n<p><b>Different Kernels<\/b><br \/>\n<b><\/b><\/p>\n<p><b>1<\/b><span style=\"font-weight: 400\">. linear: u&#8217;*v<\/span><br \/>\n<b>2<\/b><span style=\"font-weight: 400\">. polynomial: (gamma*u&#8217;*v + coef0)^degree<\/span><br \/>\n<span style=\"font-weight: 400\"><strong>3.<\/strong> radial basis (RBF) : exp(-gamma*|u-v|^2)sigmoid : tanh(gamma*u&#8217;*v + coef0)<\/span><\/p>\n<p><span style=\"font-weight: 400\">RBF is generally the most popular one.<\/span><br \/>\n<b><\/b><\/p>\n<p><b>How SVM works?<\/b><br \/>\n<b><\/b><\/p>\n<ol>\n<li><span style=\"font-weight: 400\">Choose an optimal hyperplane which maximizes margin.<\/span><br \/>\n<b><\/b><\/li>\n<li><span style=\"font-weight: 400\">Applies penalty for misclassifications (cost &#8216;c&#8217; tuning parameter).<\/span><br \/>\n<b><\/b><\/li>\n<li><span style=\"font-weight: 400\">If the non-linearly separable the data points. Then transform data to high dimensional space. It is done so in order to classify it easily with the help of linear decision surfaces.<\/span><\/li>\n<\/ol>\n<p><em><strong>Time to master the concept of <a href=\"https:\/\/data-flair.training\/blogs\/data-visualization-in-r\/\">Data Visualization in R<\/a><\/strong><\/em><\/p>\n<h4>Advantages of SVM in R<\/h4>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">If we are using Kernel trick in case of non-linear separable data then it performs very well.<\/span><\/li>\n<\/ul>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">SVM works well in high dimensional space and in case of text or image classification.<\/span><\/li>\n<\/ul>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">It does not suffer a multicollinearity problem.<\/span><\/li>\n<\/ul>\n<h4>Disadvantages of SVM in R<\/h4>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">It takes more time on large-sized data sets.<\/span><\/li>\n<\/ul>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">SVM does not return probability estimates.<\/span><\/li>\n<\/ul>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">In the case of linearly separable data, this is almost like logistic regression.<\/span><\/li>\n<\/ul>\n<h4>Support Vector Machine &#8211; Regression<\/h4>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Yes, we can use it for a regression problem, wherein the dependent or target variable is continuous.<\/span><\/li>\n<\/ul>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">The aim of SVM regression is the same as classification problem i.e. to find the largest margin.<\/span><\/li>\n<\/ul>\n<h3>Applications of Classification in R<\/h3>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">An emergency room in a hospital measures 17 variables of newly admitted patients. Variables, like blood pressure, age and many more. Furthermore, a careful decision has to be made if the patient has to be admitted to the ICU. Due to a high cost of I.C.U, those patients who may survive more than a month are given high priority. Also, the problem is to predict high-risk patients. And, to discriminate them from low-risk patients.<\/span><\/li>\n<\/ul>\n<ul>\n<li style=\"font-weight: 400\">A credit company receives hundreds of thousands of applications for new cards. The application contains information about several different attributes. Moreover, the problem is to categorize those who have good credit, bad credit or fall into a grey area.<\/li>\n<\/ul>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Astronomers have been cataloguing distant objects in the sky using long exposure C.C.D images. Thus, the object that needs to be labelled is a star, galaxy etc. The data is noisy, and the images are very faint, hence, the cataloguing can take decades to complete.<\/span><\/li>\n<\/ul>\n<h2>Summary<\/h2>\n<p>We have studied about classification in R along with their usages and pros and cons. We have also learned real-time examples which help to learn classification in a better way.<\/p>\n<p><em><strong>Next tutorial in our R DataFlair tutorial series &#8211;\u00a0<a href=\"https:\/\/data-flair.training\/blogs\/e1071-in-r\/\">e1071 Package | SVM Training and Testing Models in R<\/a><\/strong><\/em><\/p>\n<p>Still, if any doubts regarding the classification in R, ask in the comment section.<span hidden class=\"__iawmlf-post-loop-links\" data-iawmlf-links=\"[{&quot;id&quot;:1467,&quot;href&quot;:&quot;https:\\\/\\\/en.wikipedia.org\\\/wiki\\\/R_(programming_language)&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20251001042859\\\/https:\\\/\\\/en.wikipedia.org\\\/wiki\\\/R_(programming_language)&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-09 08:17:04&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-12 12:22:33&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-15 12:29:21&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-18 15:20:53&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-21 18:00:25&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-25 04:08:57&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-28 06:54:42&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-31 09:47:17&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-03 17:14:22&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-06 19:17:34&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-09 21:09:32&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-13 04:31:41&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-16 15:06:53&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-19 19:03:58&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-23 05:30:29&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-26 10:18:28&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-29 11:45:43&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-01 12:00:34&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-04 12:09:55&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-07 15:09:43&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-10 18:01:34&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-13 23:45:59&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-17 05:29:44&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-20 07:23:59&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-23 10:05:24&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-26 14:54:33&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-01 16:00:29&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-04 19:56:49&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-08 03:19:57&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-03-11 07:47:37&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-14 13:54:22&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-17 17:24:09&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-03-20 23:04:55&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-24 00:07:34&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-27 00:15:51&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-30 08:20:38&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-03 14:48:26&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-06 19:55:35&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-10 05:52:27&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-13 07:47:26&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-16 08:05:10&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-19 13:04:23&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-22 13:52:44&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-25 13:58:03&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-29 01:16:25&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-02 04:13:02&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-05 06:33:38&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-08 17:48:43&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-12 03:38:06&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-15 04:53:06&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-18 09:15:30&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-21 12:35:48&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-25 03:51:04&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-28 07:13:15&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-01 04:45:49&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-06-04 06:40:14&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-07 06:45:43&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-06-10 09:02:48&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-06-13 16:18:42&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-13 16:18:42&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;}]\"><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we will study the classification in R thoroughly. We will also cover the Decision Tree, Na\u00efve Bayes Classification and Support Vector Machine. To understand it in the best manner, we will&#46;&#46;&#46;<\/p>\n","protected":false},"author":6,"featured_media":63033,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51],"tags":[2550,8387,8996],"class_list":["post-4957","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-r","tag-classification-in-r","tag-logistic-and-multimonial-in-r","tag-naive-bayes-classification-in-r"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Classification in R Programming: The all in one tutorial to master the concept! - DataFlair<\/title>\n<meta name=\"description\" content=\"Learn about classification in R with arguments, decision tree concept with its terminologies, types and pros &amp; cons. Also, explore the Na\u00efve Bayes classification &amp; Support Vector Machines.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/classification-in-r\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Classification in R Programming: The all in one tutorial to master the concept! - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Learn about classification in R with arguments, decision tree concept with its terminologies, types and pros &amp; cons. Also, explore the Na\u00efve Bayes classification &amp; Support Vector Machines.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/classification-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2017-12-15T08:09:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-08-25T11:55:58+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Classification-in-R.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Classification in R Programming: The all in one tutorial to master the concept! - DataFlair","description":"Learn about classification in R with arguments, decision tree concept with its terminologies, types and pros & cons. Also, explore the Na\u00efve Bayes classification & Support Vector Machines.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/classification-in-r\/","og_locale":"en_US","og_type":"article","og_title":"Classification in R Programming: The all in one tutorial to master the concept! - DataFlair","og_description":"Learn about classification in R with arguments, decision tree concept with its terminologies, types and pros & cons. Also, explore the Na\u00efve Bayes classification & Support Vector Machines.","og_url":"https:\/\/data-flair.training\/blogs\/classification-in-r\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2017-12-15T08:09:56+00:00","article_modified_time":"2021-08-25T11:55:58+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Classification-in-R.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/classification-in-r\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/classification-in-r\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89"},"headline":"Classification in R Programming: The all in one tutorial to master the concept!","datePublished":"2017-12-15T08:09:56+00:00","dateModified":"2021-08-25T11:55:58+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/classification-in-r\/"},"wordCount":1667,"commentCount":6,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/classification-in-r\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Classification-in-R.jpg","keywords":["Classification in R","logistic and multimonial in R","Naive Bayes classification in R"],"articleSection":["R Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/classification-in-r\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/classification-in-r\/","url":"https:\/\/data-flair.training\/blogs\/classification-in-r\/","name":"Classification in R Programming: The all in one tutorial to master the concept! - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/classification-in-r\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/classification-in-r\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Classification-in-R.jpg","datePublished":"2017-12-15T08:09:56+00:00","dateModified":"2021-08-25T11:55:58+00:00","description":"Learn about classification in R with arguments, decision tree concept with its terminologies, types and pros & cons. Also, explore the Na\u00efve Bayes classification & Support Vector Machines.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/classification-in-r\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/classification-in-r\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/classification-in-r\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Classification-in-R.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Classification-in-R.jpg","width":802,"height":420,"caption":"Classification in R"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/classification-in-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"R Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/r\/"},{"@type":"ListItem","position":3,"name":"Classification in R Programming: The all in one tutorial to master the concept!"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"The DataFlair Team provides industry-driven content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our expert educators focus on delivering value-packed, easy-to-follow resources for tech enthusiasts and professionals.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam2\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/4957","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=4957"}],"version-history":[{"count":13,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/4957\/revisions"}],"predecessor-version":[{"id":63404,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/4957\/revisions\/63404"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/63033"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=4957"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=4957"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=4957"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}