<?xml version="1.0" encoding="utf-8" ?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:tt="http://teletype.in/" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/"><title>Priya Reddy</title><author><name>Priya Reddy</name></author><id>https://teletype.in/atom/realfacts</id><link rel="self" type="application/atom+xml" href="https://teletype.in/atom/realfacts?offset=0"></link><link rel="alternate" type="text/html" href="https://teletype.in/@realfacts?utm_source=teletype&amp;utm_medium=feed_atom&amp;utm_campaign=realfacts"></link><link rel="next" type="application/rss+xml" href="https://teletype.in/atom/realfacts?offset=10"></link><link rel="search" type="application/opensearchdescription+xml" title="Teletype" href="https://teletype.in/opensearch.xml"></link><updated>2026-05-14T05:45:27.520Z</updated><entry><id>realfacts:-UlG6uAP4pd</id><link rel="alternate" type="text/html" href="https://teletype.in/@realfacts/-UlG6uAP4pd?utm_source=teletype&amp;utm_medium=feed_atom&amp;utm_campaign=realfacts"></link><title>Machine Learning in R for Beginners with Example</title><published>2021-09-21T08:11:23.563Z</published><updated>2021-09-21T08:11:23.563Z</updated><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img3.teletype.in/files/e1/4c/e14c2642-431b-4f1c-aa01-8ee02bdd8d74.png"></media:thumbnail><summary type="html">&lt;img src=&quot;https://www.edureka.co/blog/wp-content/uploads/2018/03/Picture1-3.png&quot;&gt;Machine learning is the present and the future! From Netflix’s recommendation engine to Google’s self-driving car, it’s all machine learning. This blog on Machine Learning with R helps you understand the core concepts of machine learning followed by different machine learning algorithms and implementing those machine learning algorithms with R.</summary><content type="html">
  &lt;h2 id=&quot;Fc7I&quot;&gt;&lt;strong&gt;Machine Learning with R&lt;/strong&gt;&lt;/h2&gt;
  &lt;p id=&quot;NFaQ&quot;&gt;Machine learning is the present and the future! From Netflix’s recommendation engine to Google’s self-driving car, it’s all machine learning. This blog on Machine Learning with R helps you understand the core concepts of machine learning followed by different machine learning algorithms and implementing those machine learning algorithms with R.&lt;/p&gt;
  &lt;p id=&quot;2QU8&quot;&gt;This blog on “Machine Learning with R” comprises of these sections:&lt;/p&gt;
  &lt;ul id=&quot;uH0b&quot;&gt;
    &lt;li id=&quot;ktUR&quot;&gt;Understanding Machine Learning&lt;/li&gt;
    &lt;li id=&quot;2nIF&quot;&gt;Types of Machine Learning Algorithms&lt;/li&gt;
    &lt;li id=&quot;gpdu&quot;&gt;Implementing Machine Learning Algorithms with R&lt;/li&gt;
  &lt;/ul&gt;
  &lt;h2 id=&quot;yhES&quot;&gt;&lt;strong&gt;Understanding Machine Learning&lt;/strong&gt;&lt;/h2&gt;
  &lt;figure id=&quot;p8Bd&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://www.edureka.co/blog/wp-content/uploads/2018/03/Picture1-3.png&quot; width=&quot;419&quot; /&gt;
  &lt;/figure&gt;
  &lt;figure id=&quot;vAOv&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/uploads/2018/03/Picture2.png&quot; width=&quot;418&quot; /&gt;
  &lt;/figure&gt;
  &lt;figure id=&quot;eeW9&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/uploads/2018/03/Picture3.png&quot; width=&quot;420&quot; /&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;4mzU&quot;&gt;&lt;strong&gt;How do you know all of those are fish? &lt;/strong&gt;&lt;/p&gt;
  &lt;p id=&quot;P5Jl&quot;&gt;As a kid, you might have come across a picture of a fish and you would have been told by your kindergarten teachers or parents that this is a fish and it has some specific features associated with it like it has fins, gills, a pair of eyes, a tail and so on. Now, whenever your brain comes across an image with those set of features, it automatically registers it as a fish because your brain has &lt;em&gt;learned &lt;/em&gt;that it is a fish. To get in-depth knowledge on R Programming Please go through &lt;strong&gt;&lt;a href=&quot;https://codingvidya.com/best-r-books/&quot; target=&quot;_blank&quot;&gt;R Books for Beginners&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
  &lt;p id=&quot;V67I&quot;&gt;That’s how our brain functions but what about a machine? If the same image is fed to a machine, how will the machine identify it to be a fish?&lt;/p&gt;
  &lt;figure id=&quot;zchE&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/uploads/2018/03/Picture6.png&quot; width=&quot;600&quot; /&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;USGQ&quot;&gt;This is where M&lt;em&gt;achine Learning&lt;/em&gt; comes in. We’ll keep on feeding images of a fish to a computer with the tag “fish” until the &lt;em&gt;machine learns all the features associated&lt;/em&gt; with a&lt;em&gt; fish. &lt;/em&gt;&lt;/p&gt;
  &lt;figure id=&quot;oV2j&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/uploads/2018/03/Picture7.png&quot; width=&quot;600&quot; /&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;hwEt&quot;&gt;Once the machine learns all the features associated with a fish, we will feed it new data to determine how much has it learned.&lt;/p&gt;
  &lt;figure id=&quot;YrLp&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/uploads/2018/03/Picture8.png&quot; width=&quot;600&quot; /&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;NXd7&quot;&gt;In other words,&lt;em&gt; Raw Data/Training Data &lt;/em&gt;is given to the machine, so that it &lt;em&gt;learns &lt;/em&gt;all the features associated with the &lt;em&gt;Training Data. &lt;/em&gt;Once, the learning is done, it is given &lt;em&gt;New Data/Test Data &lt;/em&gt;to determine how well the machine has learned.&lt;/p&gt;
  &lt;p id=&quot;BgTB&quot;&gt;Let us move ahead in this Machine Learning with R blog and understand about types of Machine Learning.&lt;/p&gt;
  &lt;h2 id=&quot;Fhhk&quot;&gt;&lt;strong&gt;Types of Machine Learning&lt;/strong&gt;&lt;/h2&gt;
  &lt;ul id=&quot;39ic&quot;&gt;
    &lt;li id=&quot;Rkft&quot;&gt;&lt;strong&gt;Supervised Learning: &lt;/strong&gt;&lt;/li&gt;
  &lt;/ul&gt;
  &lt;p id=&quot;MlQu&quot;&gt;Supervised Learning algorithm learns from a known data-set(Training Data) which has labels to make predictions.&lt;/p&gt;
  &lt;figure id=&quot;Bml7&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/uploads/2018/03/Picture9.png&quot; width=&quot;600&quot; /&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;Qu5r&quot;&gt;Regression and Classification are some examples of Supervised Learning.&lt;/p&gt;
  &lt;h4 id=&quot;pI1D&quot;&gt;&lt;strong&gt;#Classification:&lt;/strong&gt;&lt;/h4&gt;
  &lt;p id=&quot;LjPP&quot;&gt;Classification determines to which set of categories does a new observation belongs i.e. a classification algorithm learns all the features and labels of the training data and when new data is given to it, it has to assign labels to the new observations depending on what it has learned from the training data.&lt;/p&gt;
  &lt;figure id=&quot;bUVn&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/uploads/2018/03/Picture10.png&quot; width=&quot;600&quot; /&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;ckqU&quot;&gt;For this example, if the first observation is given the label “Man” then it is rightly classified but if it is given the label “Woman”, the classification is wrong. Similarly for the second observation, if the label given is “Woman”, it is rightly classified, else the classification is wrong.&lt;/p&gt;
  &lt;h4 id=&quot;q2WW&quot;&gt;&lt;strong&gt;#Regression: &lt;/strong&gt;&lt;/h4&gt;
  &lt;p id=&quot;4FXB&quot;&gt;Regression is a supervised learning algorithm which helps in determining how does one variable influence another variable.&lt;/p&gt;
  &lt;figure id=&quot;RfKk&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/uploads/2018/03/Picture11.png&quot; width=&quot;600&quot; /&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;85LY&quot;&gt;Over here, “living_area” is the independent variable and “price” is the dependent variable i.e. we are determining how does “price” vary with respect to “living_area”.&lt;/p&gt;
  &lt;ul id=&quot;08xx&quot;&gt;
    &lt;li id=&quot;JZqI&quot;&gt;&lt;strong&gt;Unsupervised Learning:&lt;/strong&gt;&lt;/li&gt;
  &lt;/ul&gt;
  &lt;p id=&quot;HuKH&quot;&gt;Unsupervised learning algorithm draws inferences from data which does not have labels.&lt;/p&gt;
  &lt;p id=&quot;CnkX&quot;&gt;&lt;a href=&quot;https://www.edureka.co/data-science-r-programming-certification-course&quot; target=&quot;_blank&quot;&gt;Data Science with R Programming Certification Training CourseInstructor-led SessionsReal-life Case StudiesAssignmentsLifetime AccessExplore Curriculum&lt;/a&gt;&lt;/p&gt;
  &lt;figure id=&quot;Ffn0&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/uploads/2018/03/Picture12.png&quot; width=&quot;600&quot; /&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;4gpD&quot;&gt;&lt;em&gt;Clustering&lt;/em&gt; is an example of unsupervised learning. “K-means”, “Hierarchical”, “Fuzzy C-Means” are some examples of clustering algorithms.&lt;/p&gt;
  &lt;figure id=&quot;Jt5d&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/uploads/2018/03/Picture13.png&quot; width=&quot;600&quot; /&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;hVb4&quot;&gt;In this example, the set of observations is divided into two clusters. Clustering is done on the basis of similarity between the observations. There is a high intra-cluster similarity and low inter-cluster similarity i.e. there is a very high similarity between all the buses but low similarity between the buses and cars.&lt;/p&gt;
  &lt;ul id=&quot;4QKs&quot;&gt;
    &lt;li id=&quot;2PBO&quot;&gt;&lt;strong&gt;Reinforcement Learning:&lt;/strong&gt;&lt;/li&gt;
  &lt;/ul&gt;
  &lt;p id=&quot;fFVq&quot;&gt;Reinforcement Learning is a type of machine learning algorithm where the &lt;em&gt;machine/agent&lt;/em&gt; in an &lt;em&gt;environment &lt;/em&gt;learns ideal behavior in order to maximize its performance. Simple reward feedback is required for the agent to learn its behavior, this is known as the &lt;em&gt;reinforcement signal&lt;/em&gt;.&lt;/p&gt;
  &lt;p id=&quot;qhta&quot;&gt;Let’s take &lt;em&gt;pacman&lt;/em&gt; for example. As long as pacman keeps eating food, it earns points but when it crashes against a monster it loses it’s life. Thus pacman learns that it needs to eat more food and avoid monsters so as to improve it’s performance.&lt;/p&gt;
  &lt;h2 id=&quot;GFiD&quot;&gt;&lt;strong&gt;Implementing Machine Learning with R:&lt;/strong&gt;&lt;/h2&gt;
  &lt;h3 id=&quot;ulcy&quot;&gt;&lt;strong&gt;Linear Regression:&lt;/strong&gt;&lt;/h3&gt;
  &lt;p id=&quot;F55m&quot;&gt;We’ll be working with the diamonds data-set to implement linear regression algorithm:&lt;/p&gt;
  &lt;figure id=&quot;ygdR&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/uploads/2018/03/diamond.png&quot; width=&quot;610&quot; /&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;1VIw&quot;&gt;Description of the data-set:&lt;/p&gt;
  &lt;figure id=&quot;BPtP&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/uploads/2018/03/diamond_description.png&quot; width=&quot;614&quot; /&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;ZDeL&quot;&gt;Prior to building any model on the data, we are supposed to split the data into “train” and “test” sets. The model will be built on the “train” set and it’s accuracy will be checked on the “test” set.&lt;/p&gt;
  &lt;p id=&quot;Ytuf&quot;&gt;We need to load the “caTools” package to split the data into two sets.&lt;/p&gt;
  &lt;pre id=&quot;a6dJ&quot;&gt;library(caTools)&lt;/pre&gt;
  &lt;p id=&quot;UakI&quot;&gt;“caTools” package provides a function “sample.split()” which helps in splitting the data.&lt;/p&gt;
  &lt;pre id=&quot;ddux&quot;&gt;sample.split(diamonds$price,SplitRatio = 0.65)-&amp;gt;split_index&lt;/pre&gt;
  &lt;p id=&quot;JFdb&quot;&gt;65% of the observations from price column have been assigned the “true” label and the rest 35% have been assigned “false” label.&lt;/p&gt;
  &lt;pre id=&quot;8b73&quot;&gt;subset(diamonds,split_index==T)-&amp;gt;train
subset(diamonds,split_index==F)-&amp;gt;test&lt;/pre&gt;
  &lt;p id=&quot;pQb1&quot;&gt;All the observations which have “true” label have been stored in the “&lt;em&gt;train” object&lt;/em&gt; and those observations having “false” label have been assigned to the “test” set.&lt;/p&gt;
  &lt;p id=&quot;FUQX&quot;&gt;Now that the splitting is done and we have our “train” and “test” sets, it’s time to build the linear regression model on the training set.&lt;/p&gt;
  &lt;p id=&quot;z0yY&quot;&gt;We’ll be using the “lm()” function to build the linear regression model on the “train” data. We are determining the &lt;em&gt;price&lt;/em&gt; of the diamonds with respect to all other variables of the data-set. The built model is stored in the object “mod_regress”.&lt;/p&gt;
  &lt;pre id=&quot;bbhY&quot;&gt;lm(price~.,data = train)-&amp;gt;mod_regress &lt;/pre&gt;
  &lt;p id=&quot;mixR&quot;&gt;Now, that we have built the model, we need to make predictions on the “test” set. “predict()” function is used to get predictions. It takes two arguments: the &lt;em&gt;built model&lt;/em&gt; and the &lt;em&gt;test set. &lt;/em&gt;The predicted results are stored in the “result_regress” object.&lt;/p&gt;
  &lt;pre id=&quot;7VHj&quot;&gt;predict(mod_regress,test)-&amp;gt;result_regress&lt;/pre&gt;
  &lt;p id=&quot;JVAE&quot;&gt;Let’s bind the actual price values from the “test” data-set and the predicted values into a single data-set using the “cbind()” function. The new data-frame is stored in “Final_Data”&lt;/p&gt;
  &lt;pre id=&quot;LLx3&quot;&gt;cbind(Actual=test$price,Predicted=result_regress)-&amp;gt;Final_Data &lt;/pre&gt;
  &lt;pre id=&quot;I64v&quot;&gt;as.data.frame(Final_Data)-&amp;gt;Final_Data&lt;/pre&gt;
  &lt;p id=&quot;xK6h&quot;&gt;A glance at the “Final_Data” which comprises of actual values and predicted values:&lt;/p&gt;
  &lt;figure id=&quot;LB2B&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/uploads/2018/03/final-data.png&quot; width=&quot;166&quot; /&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;TGFI&quot;&gt;Let’s find the error by subtracting the predicted values from the actual values and add this error as a new column to the “Final_Data”:&lt;/p&gt;
  &lt;pre id=&quot;XyBX&quot;&gt;(Final_Data$Actual- Final_Data$Predicted)-&amp;gt;error&lt;/pre&gt;
  &lt;pre id=&quot;nDLt&quot;&gt;cbind(Final_Data,error)-&amp;gt;Final_Data&lt;/pre&gt;
  &lt;p id=&quot;Azdv&quot;&gt;A glance at the “Final_Data” which also comprises of the error in prediction:&lt;/p&gt;
  &lt;figure id=&quot;huwS&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/uploads/2018/03/final-data2.png&quot; width=&quot;248&quot; /&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;9QuC&quot;&gt;Now, we’ll go ahead and calculate “&lt;em&gt;Root Mean Square Error” &lt;/em&gt;which gives an aggregate error for all the predictions&lt;/p&gt;
  &lt;pre id=&quot;b1o8&quot;&gt;rmse1&amp;lt;-sqrt(mean(Final_Data$error^2)) &lt;/pre&gt;
  &lt;pre id=&quot;XZtV&quot;&gt;rmse1&lt;/pre&gt;
  &lt;figure id=&quot;ObRt&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://www.edureka.co/blog/wp-content/uploads/2018/03/rmse1.png&quot; width=&quot;132&quot; /&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;OP5D&quot;&gt;Going ahead, let’s build another model, so that we can compare the accuracy of both these models and determine which is a better one.&lt;/p&gt;
  &lt;p id=&quot;9Rkt&quot;&gt;We’ll build a new linear regression model on the “train” set but this time, we’ll be dropping the ‘x’ and ‘y’ columns from the independent variables i.e. the “price” of the diamonds is determined by all the columns except ‘x’ and ‘y’.&lt;/p&gt;
  &lt;p id=&quot;4xUV&quot;&gt;The model built is stored in “mod_regress2”:&lt;/p&gt;
  &lt;pre id=&quot;ncwd&quot;&gt;lm(price~.-y-z,data = train)-&amp;gt;mod_regress2&lt;/pre&gt;
  &lt;p id=&quot;JS1V&quot;&gt;The predicted results are stored in “result_regress2”&lt;/p&gt;
  &lt;pre id=&quot;husQ&quot;&gt;predict(mod_regress2,test)-&amp;gt;result_regress2&lt;/pre&gt;
  &lt;p id=&quot;MYLJ&quot;&gt;Actual and Predicted values are combined and stored in “Final_Data2”:&lt;/p&gt;
  &lt;pre id=&quot;4zww&quot;&gt;cbind(Actual=test$price,Predicted=result_regress2)-&amp;gt;Final_Data2 &lt;/pre&gt;
  &lt;pre id=&quot;mOpv&quot;&gt;as.data.frame(Final_Data2)-&amp;gt;Final_Data2&lt;/pre&gt;
  &lt;p id=&quot;3EyJ&quot;&gt;Let’s also add the error in prediction to “Final_Data2”&lt;/p&gt;
  &lt;pre id=&quot;ksSh&quot;&gt;(Final_Data2$Actual- Final_Data2$Predicted)-&amp;gt;error2&lt;/pre&gt;
  &lt;pre id=&quot;bHNi&quot;&gt;cbind(Final_Data2,error2)-&amp;gt;Final_Data2&lt;/pre&gt;
  &lt;p id=&quot;Tqpb&quot;&gt;A glance at “Final_Data2”:&lt;/p&gt;
  &lt;figure id=&quot;MeeY&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/uploads/2018/03/final-data2.png&quot; width=&quot;248&quot; /&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;y9hp&quot;&gt;Finding Root Mean Square Error to get the aggregate error:&lt;/p&gt;
  &lt;pre id=&quot;eReO&quot;&gt;rmse2&amp;lt;-sqrt(mean(Final_Data2$error^2))&lt;/pre&gt;
  &lt;figure id=&quot;IdSr&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://www.edureka.co/blog/wp-content/uploads/2018/03/rmse2.png&quot; width=&quot;122&quot; /&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;lYdV&quot;&gt;We see that “rmse2” is marginally less than “rmse1” and hence the second model is marginally better than the first model.&lt;/p&gt;
  &lt;h3 id=&quot;aMYZ&quot;&gt;&lt;strong&gt;Classification:&lt;/strong&gt;&lt;/h3&gt;
  &lt;p id=&quot;DMJQ&quot;&gt;We’ll be working with the “car_purchase” data-set to implement &lt;em&gt;recursive partitioning &lt;/em&gt;which is a classification algorithm.&lt;/p&gt;
  &lt;figure id=&quot;2K4G&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/uploads/2018/03/car-1.png&quot; width=&quot;348&quot; /&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;4e1E&quot;&gt;Let’s split the data into “train” and “test” sets using “sample.split()” function from “caTools” package.&lt;/p&gt;
  &lt;pre id=&quot;per9&quot;&gt;library(caTools)&lt;/pre&gt;
  &lt;p id=&quot;2egQ&quot;&gt;65% of the observations from ‘Purchased’ column will be assigned “TRUE” labels and the rest will be assigned “FALSE” labels.&lt;/p&gt;
  &lt;pre id=&quot;eJUK&quot;&gt;sample.split(car_purchase$Purchased,SplitRatio = 0.65)-&amp;gt;split_values&lt;/pre&gt;
  &lt;p id=&quot;atuR&quot;&gt;All those observations which have “TRUE” label will be stored into ‘train’ data and those observations having “FALSE” label will be assigned to ‘test’ data.&lt;/p&gt;
  &lt;pre id=&quot;vZ4X&quot;&gt;subset(car_purchase,split_values==T)-&amp;gt;train_data&lt;/pre&gt;
  &lt;pre id=&quot;lQDg&quot;&gt;subset(car_purchase,split_values==F)-&amp;gt;test_data&lt;/pre&gt;
  &lt;p id=&quot;PbHt&quot;&gt;Time to build the Recursive Partitioning algorithm:&lt;/p&gt;
  &lt;p id=&quot;qTOq&quot;&gt;We’ll start off by loading the ‘rpart’ package:&lt;/p&gt;
  &lt;pre id=&quot;tUh5&quot;&gt;library(rpart)&lt;/pre&gt;
  &lt;p id=&quot;kmDD&quot;&gt;“Purchased” column will be the dependent variable and all other columns are the independent variables i.e. we are determining whether the person has bought the car or not with respect to all other columns. The model is built on the “train_data” and the result is stored in “mod1”.&lt;/p&gt;
  &lt;pre id=&quot;WrZk&quot;&gt;rpart(Purchased~.,data = train_data)-&amp;gt;mod1&lt;/pre&gt;
  &lt;p id=&quot;XYbz&quot;&gt;Let’s plot the result:&lt;/p&gt;
  &lt;pre id=&quot;okfo&quot;&gt;plot(mod1,margin = 0.1) text(mod1,pretty = T,cex=0.8)&lt;/pre&gt;
  &lt;p id=&quot;2fMz&quot;&gt;Now, let’s go ahead and predict the results on “test_data”. We are giving the built rpart model “mod1” as the first argument, the test set “test_data” as the second argument and prediction type as “class” for the third argument. The result is stored in ‘result1’ object.&lt;/p&gt;
  &lt;pre id=&quot;T7jh&quot;&gt;predict(mod1,test_data,type = &amp;quot;class&amp;quot;)-&amp;gt;result1&lt;/pre&gt;
  &lt;p id=&quot;WGKn&quot;&gt;Let’s evaluate the accuracy of the model using “confusionMatrix()” function from caret package.&lt;/p&gt;
  &lt;pre id=&quot;q8eV&quot;&gt;library(caret) confusionMatrix(table(test_data$Purchased,result1))&lt;/pre&gt;
  &lt;p id=&quot;7Pos&quot;&gt;The confusion matrix tells us that out of the 90 observations where the person did not buy the car, 79 observations have been rightly classified as “No” and 11 have been wrongly classified as “YES”. Similarly, out of the 50 observations where the person actually bought the car, 47 have been rightly classified as “YES” and 3 have been wrongly classified as “NO”.&lt;/p&gt;
  &lt;p id=&quot;zrps&quot;&gt;We can find the accuracy of the model by dividing the correct predictions with total predictions i.e. (79+47)/(79+47+11+3).&lt;/p&gt;
  &lt;h3 id=&quot;pjZ2&quot;&gt;&lt;strong&gt;K-Means Clustering:&lt;/strong&gt;&lt;/h3&gt;
  &lt;p id=&quot;Ee8R&quot;&gt;We’ll work with “iris” data-set to implement k-means clustering:&lt;/p&gt;
  &lt;figure id=&quot;K68z&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/uploads/2018/03/iris.png&quot; width=&quot;480&quot; /&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;624l&quot;&gt;Let’s remove the “Species” column and create a new data-set which comprises only the first four columns from the ‘iris’ data-set.&lt;/p&gt;
  &lt;pre id=&quot;S2lt&quot;&gt;iris[1:4]-&amp;gt;iris_k&lt;/pre&gt;
  &lt;p id=&quot;VYU7&quot;&gt;Let us take the number of clusters to be 3. “Kmeans()” function takes the input data and the number of clusters in which the data is to be clustered. The syntax is : kmeans( data, k) where k is the number of cluster centers.&lt;/p&gt;
  &lt;pre id=&quot;fihh&quot;&gt;kmeans(iris_k,3)-&amp;gt;k1&lt;/pre&gt;
  &lt;p id=&quot;FLcr&quot;&gt;Analyzing the clustering:&lt;/p&gt;
  &lt;pre id=&quot;jcqk&quot;&gt;str(k1)&lt;/pre&gt;
  &lt;figure id=&quot;lom3&quot; class=&quot;m_custom&quot;&gt;
    &lt;img src=&quot;https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/uploads/2018/03/Picture15.png&quot; width=&quot;664&quot; /&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;TAzE&quot;&gt;The str() function gives the structure of the kmeans which includes various parameters like withinss, betweenss, etc, analyzing which you can find out the performance of kmeans.&lt;/p&gt;
  &lt;p id=&quot;go60&quot;&gt;betweenss : Between sum of squares i.e. Intracluster similarity&lt;/p&gt;
  &lt;p id=&quot;riGv&quot;&gt;withinss : Within sum of square i.e. Intercluster similarity&lt;/p&gt;
  &lt;p id=&quot;SRfB&quot;&gt;totwithinss : Sum of all the withinss of all the clusters i.e.Total intra-cluster similarity&lt;/p&gt;
  &lt;p id=&quot;PZ1R&quot;&gt;A good clustering will have a lower value of “tot.withinss” and higher value of “betweenss” which depends on the number of clusters ‘k’ chosen initially.&lt;/p&gt;
  &lt;p id=&quot;sFlO&quot;&gt;The time is ripe to become an expert in Machine Learning to take advantage of new opportunities that come your way. This brings us to the end of this “&lt;em&gt;&lt;strong&gt;&lt;a href=&quot;https://codingvidya.com/machine-learning/&quot; target=&quot;_blank&quot;&gt;Machine Learning&lt;/a&gt;&lt;/strong&gt;&lt;/em&gt;” blog. I hope this blog was informative fruitful.&lt;/p&gt;

</content></entry><entry><id>realfacts:S5qOLoKPoNN</id><link rel="alternate" type="text/html" href="https://teletype.in/@realfacts/S5qOLoKPoNN?utm_source=teletype&amp;utm_medium=feed_atom&amp;utm_campaign=realfacts"></link><title>How to Learn Python for Data Science In 5 Steps</title><published>2021-09-19T05:21:03.168Z</published><updated>2021-09-19T05:21:03.168Z</updated><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img1.teletype.in/files/07/b4/07b492de-bdd9-48b7-87c3-dec7c312ebca.png"></media:thumbnail><summary type="html">&lt;img src=&quot;https://img3.teletype.in/files/e7/5c/e75c6adf-c4f8-4f21-b906-118b7769766c.png&quot;&gt;Before we explore how to learn Python for data science, we should briefly answer why you should learn Python in the first place.</summary><content type="html">
  &lt;h2 id=&quot;FUaZ&quot;&gt;Why Learn Python For Data Science?&lt;/h2&gt;
  &lt;p id=&quot;FGW7&quot;&gt;Before we explore how to learn Python for data science, we should briefly answer why you should learn Python in the first place.&lt;/p&gt;
  &lt;p id=&quot;uGjr&quot;&gt;In short, understanding Python is one of the valuable skills needed for a data science career.&lt;/p&gt;
  &lt;p id=&quot;96dq&quot;&gt;Though it hasn’t always been, Python is the programming language of choice for data science. &lt;/p&gt;
  &lt;figure id=&quot;hcnN&quot; class=&quot;m_column&quot;&gt;
    &lt;img src=&quot;https://img3.teletype.in/files/e7/5c/e75c6adf-c4f8-4f21-b906-118b7769766c.png&quot; width=&quot;815&quot; /&gt;
  &lt;/figure&gt;
  &lt;p id=&quot;YsyR&quot;&gt;Data science experts expect this trend to continue with increasing development in the Python ecosystem. And while your journey to learn Python programming may be just beginning, it’s nice to know that employment opportunities are abundant (and growing) as well.&lt;/p&gt;
  &lt;p id=&quot;tzI0&quot;&gt;According to Indeed, the average salary for a Data Scientist is $121,583.&lt;/p&gt;
  &lt;p id=&quot;IqLU&quot;&gt;The good news? That number is only expected to increase, as demand for data scientists is expected to keep growing. In 2021 - 2022, there are &lt;strong&gt;&lt;em&gt;three times&lt;/em&gt;&lt;/strong&gt; as many job postings in data science as job searches for data science, according to Quanthub. That means the demand for data scientitsts is vastly outstripping the supply.&lt;/p&gt;
  &lt;p id=&quot;Ree7&quot;&gt;So, the future is bright for data science, and Python is just one piece of the proverbial pie. Fortunately, learning &lt;strong&gt;&lt;a href=&quot;https://codingvidya.com/udacity-data-science-nanodegree-review/&quot; target=&quot;_blank&quot;&gt;Udacity Data Science Nanodegree&lt;/a&gt;&lt;/strong&gt;, Python and other programming fundamentals is as attainable as ever. We’ll show you how in five simple steps.&lt;/p&gt;
  &lt;p id=&quot;ZRgB&quot;&gt;But remember – just because the steps are simple doesn’t mean you won’t have to put in the work. If you apply yourself and dedicate meaningful time to learning Python, you have the potential to not only pick up a new skill, but potentially bring your career to a new level.&lt;/p&gt;
  &lt;h2 id=&quot;ub7r&quot;&gt;How to Learn Python for Data Science&lt;/h2&gt;
  &lt;h4 id=&quot;f8CZ&quot;&gt;Click to View Our How to Learn Python Infographic&lt;/h4&gt;
  &lt;p id=&quot;MycR&quot;&gt;First, you’ll want to find the right course to help you learn Python programming. Dataquest’s courses are specifically designed for you to learn Python for data science at your own pace, challenging you to write real code and use real data in our interactive, in-browser interface.&lt;/p&gt;
  &lt;p id=&quot;twvq&quot;&gt;In addition to learning Python in a course setting, your journey to becoming a data scientist should also include soft skills. Plus, there are some complimentary technical skills we recommend you learn along the way.&lt;/p&gt;
  &lt;h3 id=&quot;NvTf&quot;&gt;&lt;strong&gt;Step 1: Learn Python Fundamentals&lt;/strong&gt;&lt;/h3&gt;
  &lt;p id=&quot;xL7Y&quot;&gt;Everyone starts somewhere. This first step is where you’ll learn Python programming basics. You’ll also want an introduction to data science.&lt;/p&gt;
  &lt;p id=&quot;ywLj&quot;&gt;One of the important tools you should start using early in your journey is &lt;strong&gt;&lt;a href=&quot;https://codingvidya.com/best-python-books/&quot; target=&quot;_blank&quot;&gt;Best Python Programming Books&lt;/a&gt;&lt;/strong&gt;, which comes prepackaged with Python libraries to help you learn these two things.&lt;/p&gt;
  &lt;p id=&quot;5NiJ&quot;&gt;&lt;strong&gt;Kickstart your learning by&lt;/strong&gt;: Joining a community&lt;/p&gt;
  &lt;p id=&quot;tiS2&quot;&gt;By joining a community, you’ll put yourself around like-minded people and increase your opportunities for employment. According to the Society for Human Resource Management, employee referrals account for 30% of all hires.&lt;/p&gt;
  &lt;p id=&quot;1auC&quot;&gt;&lt;strong&gt;Related skills&lt;/strong&gt;: Try the Command Line Interface&lt;/p&gt;
  &lt;p id=&quot;Ty5Q&quot;&gt;The Command Line Interface (CLI) lets you run scripts more quickly, allowing you to test programs faster and work with more data.&lt;/p&gt;
  &lt;h3 id=&quot;pX1i&quot;&gt;&lt;strong&gt;Step 2: Practice Mini Python Projects&lt;/strong&gt;&lt;/h3&gt;
  &lt;p id=&quot;YsDd&quot;&gt;We truly believe in hands-on learning. You may be surprised by how soon you’ll be ready to build small Python projects. We&amp;#x27;ve already put together a great guide to Python projects for beginners, which includes ideas like:&lt;/p&gt;
  &lt;ul id=&quot;BLZI&quot;&gt;
    &lt;li id=&quot;pe1Y&quot;&gt;Tracking and Analyzing Your Personal Amazon.com Spending Habits — A fun project that&amp;#x27;ll help you practice Python and pandas basics while also giving you some real insight into your personal finance.&lt;/li&gt;
    &lt;li id=&quot;cU8u&quot;&gt;Analyze Data from a Survey — Find public survey data or use survey data from your own work in this beginner project that&amp;#x27;ll teach you to drill down into answers to mine insights.&lt;/li&gt;
    &lt;li id=&quot;oNCE&quot;&gt;Try one of our Guided Projects — Interactive Python projects for every skill level that use real data and offer guidance while still challenging you to apply your skills in new ways.&lt;/li&gt;
  &lt;/ul&gt;
  &lt;p id=&quot;BcYh&quot;&gt;But that&amp;#x27;s just the tip of the iceberg, really. You can try programming things like calculators for an online game, or a program that fetches the weather from Google in your city. You can also build simple games and apps to help you familiarize yourself with working with Python.&lt;/p&gt;
  &lt;p id=&quot;Zqq8&quot;&gt;Building mini projects like these will help you learn Python. programming projects like these are standard for all languages, and a great way to solidify your understanding of the basics.&lt;/p&gt;
  &lt;p id=&quot;n03a&quot;&gt;You should start to build your experience with APIs and begin web scraping. Beyond helping you learn Python programming, web scraping will be useful for you in gathering data later.&lt;/p&gt;
  &lt;p id=&quot;Zg0W&quot;&gt;&lt;strong&gt;Kickstart your learning by&lt;/strong&gt;: Reading&lt;/p&gt;
  &lt;p id=&quot;z81i&quot;&gt;Enhance your coursework and find answers to the Python programming challenges you encounter. Read guidebooks, blog posts, and even other people’s open source code to learn Python and data science best practices – and get new ideas.&lt;/p&gt;
  &lt;p id=&quot;v4TI&quot;&gt;&lt;em&gt;Automate The Boring Stuff With Python&lt;/em&gt; by Al Sweigart is an excellent and entertaining resource. But we&amp;#x27;ve put together an entire list of data science ebooks that are totally free for you to check out, too. Highlights include:&lt;/p&gt;
  &lt;ul id=&quot;Mlu1&quot;&gt;
    &lt;li id=&quot;42a2&quot;&gt;The Data Science Handbook — A great collection of interviews with working data scientists that&amp;#x27;ll give you a better idea of what real data science work is like and how you can succeed in the field.&lt;/li&gt;
    &lt;li id=&quot;BA2B&quot;&gt;&lt;a href=&quot;https://codingvidya.com/python-libraries-for-machine-learning/&quot; target=&quot;_blank&quot;&gt;Python Libraries for machine Learning&lt;/a&gt;— A helfpul guide that&amp;#x27;s also available in convenient, so you can dive in and run all the sample code for yourself.&lt;/li&gt;
    &lt;li id=&quot;1NHW&quot;&gt;Elements of Statistical Learning — A massive and recently-updated statisics textbook that can serve as a great reference as you&amp;#x27;re learning Python to make sure your work is statistically valid.&lt;/li&gt;
  &lt;/ul&gt;
  &lt;h3 id=&quot;JR95&quot;&gt;&lt;strong&gt;Step 3: Learn Python Data Science Libraries&lt;/strong&gt;&lt;/h3&gt;
  &lt;p id=&quot;OZJO&quot;&gt;Unlike some other programming languages, in Python, there is generally a best way of doing something. The three best and most important Python libraries for data science are NumPy, Pandas, and Matplotlib.&lt;/p&gt;
  &lt;p id=&quot;TQ1K&quot;&gt;We&amp;#x27;ve put together a helpful guide to the 15 most important Python libraries for data science, but here are a few that are really critical for any data work in Python:&lt;/p&gt;
  &lt;ul id=&quot;5e0a&quot;&gt;
    &lt;li id=&quot;ePxH&quot;&gt;NumPy — A library that makes a variety of mathematical and statistical operations easier; it is also the basis for many features of the pandas library.&lt;/li&gt;
    &lt;li id=&quot;XjZT&quot;&gt;pandas — A Python library created specifically to facilitate working with data, this is the bread and butter of a lot of Python data science work.&lt;/li&gt;
    &lt;li id=&quot;x91q&quot;&gt;Matplotlib — A visualization library that makes it quick and easy to generate charts from your data.&lt;/li&gt;
    &lt;li id=&quot;8hU4&quot;&gt;scikit-learn — The most popular library for machine learning work in Python.&lt;/li&gt;
  &lt;/ul&gt;
  &lt;p id=&quot;w30H&quot;&gt;NumPy and Pandas are great for exploring and playing with data. Matplotlib is a data visualization library that makes graphs like you’d find in Excel or Google Sheets.&lt;/p&gt;
  &lt;p id=&quot;SUPT&quot;&gt;&lt;strong&gt;Kickstart your learning by&lt;/strong&gt;: Asking questions&lt;/p&gt;
  &lt;p id=&quot;9zg7&quot;&gt;You don’t know what you don’t know!&lt;/p&gt;
  &lt;p id=&quot;39mq&quot;&gt;Python has a rich community of experts who are eager to help you learn Python. Resources like &lt;strong&gt;&lt;a href=&quot;https://codingvidya.com/best-python-books/&quot; target=&quot;_blank&quot;&gt;Best Book to Learn Python&lt;/a&gt;&lt;/strong&gt;  are full of people excited to share their knowledge and help you learn Python programming. We also have an FAQ for each lesson to help with questions you encounter throughout your programming courses with &lt;strong&gt;&lt;a href=&quot;https://codingvidya.com/udacity-data-science-nanodegree-review/&quot; target=&quot;_blank&quot;&gt;udacity data science nanodegree review&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
  &lt;p id=&quot;VMWE&quot;&gt;&lt;strong&gt;Related skills&lt;/strong&gt;: Use Git for version control&lt;/p&gt;
  &lt;p id=&quot;RtjH&quot;&gt;Git is a popular tool that helps you keep track of changes made to your code, which makes it much easier to correct mistakes, experiment, and collaborate with others.&lt;/p&gt;
  &lt;h3 id=&quot;zoV9&quot;&gt;&lt;strong&gt;Step 4: Build a Data Science Portfolio as you Learn Python&lt;/strong&gt;&lt;/h3&gt;
  &lt;p id=&quot;2nhx&quot;&gt;For aspiring data scientists, a portfolio is a must.&lt;/p&gt;
  &lt;p id=&quot;amFH&quot;&gt;These projects should include work with several different datasets and should leave readers with interesting insights that you’ve gleaned. Some types of projects to consider:&lt;/p&gt;
  &lt;ul id=&quot;HLOi&quot;&gt;
    &lt;li id=&quot;Sssl&quot;&gt;Data Cleaning Project — Any project that involves dirty or &amp;quot;unstructured&amp;quot; data that you clean up and analyze will impress potential employers, since most real-world data is going to require cleaning.&lt;/li&gt;
    &lt;li id=&quot;SiR0&quot;&gt;Data Visualization Project — Making attractive, easy-to-read visualizations is both a programming and a design challenge, but if you can do it right, your analysis will be considerably more impactful. Having great-looking charts in a project will make your portfolio stand out.&lt;/li&gt;
    &lt;li id=&quot;cbXx&quot;&gt;Machine Learning Project — If you aspire to work as a data scientist, you definitely will need a project that shows off your ML chops (and you may want a few different machine learning projects, with each focused on your use of a different popular algorithm).&lt;/li&gt;
  &lt;/ul&gt;
  &lt;p id=&quot;z3qa&quot;&gt;Your analysis should be presented clearly and visually;  so that technical folks can read your code, but non-technical people can also follow along with your charts and written explanations.&lt;/p&gt;
  &lt;p id=&quot;zG1K&quot;&gt;Your portfolio doesn’t necessarily need a particular theme. Find datasets that interest you, then come up with a way to put them together. However, if you aspire to work at a particular company or industry, showcasing projects relevant to that industry in your portfolio is a good idea.&lt;/p&gt;
  &lt;p id=&quot;Ocgq&quot;&gt;Displaying projects like these gives fellow &lt;strong&gt;&lt;a href=&quot;https://codingvidya.com/udacity-data-science-nanodegree-review/&quot; target=&quot;_blank&quot;&gt;data scientists nanodegree&lt;/a&gt;&lt;/strong&gt; an opportunity to potentially collaborate with you, and shows future employers that you’ve truly taken the time to learn Python and other important programming skills.&lt;/p&gt;
  &lt;p id=&quot;uL0d&quot;&gt;One of the nice things about data science is that your portfolio doubles as a resume while highlighting the skills you’ve learned, like Python programming.&lt;/p&gt;
  &lt;p id=&quot;HMrD&quot;&gt;&lt;strong&gt;Kickstart your learning by&lt;/strong&gt;: Communicating, collaborating, and focusing on technical competence&lt;/p&gt;
  &lt;p id=&quot;uOCs&quot;&gt;During this time, you’ll want to make sure you’re cultivating those soft skills required to work with others, making sure you really understand the inner workings of the tools you’re using.&lt;/p&gt;
  &lt;p id=&quot;SbtA&quot;&gt;&lt;strong&gt;Related skills&lt;/strong&gt;: Learn beginner and intermediate statistics&lt;/p&gt;
  &lt;p id=&quot;4sX3&quot;&gt;While learning Python for data science, you’ll also want to get a solid background in statistics. Understanding statistics will give you the mindset you need to focus on the right things, so you’ll find valuable insights (and real solutions) rather than just executing code.&lt;/p&gt;
  &lt;h3 id=&quot;8SXA&quot;&gt;&lt;strong&gt;Step 5: Apply Advanced Data Science Techniques&lt;/strong&gt;&lt;/h3&gt;
  &lt;p id=&quot;YUX3&quot;&gt;Finally, aim to sharpen your skills. Your data science journey will be full of constant learning, but there are advanced courses you can complete to ensure you’ve covered all the bases.&lt;/p&gt;
  &lt;p id=&quot;AQCB&quot;&gt;You’ll want to be comfortable with regression, classification, and k-means clustering models. You can also step into machine learning – bootstrapping models and creating neural networks using scikit-learn.&lt;/p&gt;
  &lt;p id=&quot;hbHJ&quot;&gt;At this point, programming projects can include creating models using live data feeds. Machine learning models of this kind adjust their predictions over time.&lt;/p&gt;
  &lt;p id=&quot;67FE&quot;&gt;&lt;strong&gt;Remember to&lt;/strong&gt;: Keep learning!&lt;/p&gt;
  &lt;p id=&quot;3b7l&quot;&gt;Data science is an ever-growing field that spans numerous industries.&lt;/p&gt;
  &lt;p id=&quot;vT11&quot;&gt;At the rate that demand is increasing, there are exponential opportunities to learn. Continue reading, collaborating, and conversing with others, and you’re sure to maintain interest and a competitive edge over time.&lt;/p&gt;
  &lt;h2 id=&quot;RisD&quot;&gt;How Long Will It Take To Learn Python?&lt;/h2&gt;
  &lt;p id=&quot;NUvM&quot;&gt;After reading these steps, the most common question we have people ask us is: “How long does all this take?”&lt;/p&gt;
  &lt;p id=&quot;f4BS&quot;&gt;There are a lot of estimates for how long takes to learn Python. For data science specifically, estimates a range from three months to a year of consistent practice.&lt;/p&gt;
  &lt;p id=&quot;VoRN&quot;&gt;We’ve watched people move through our courses at lightning speed and others who have taken it much slower.&lt;/p&gt;
  &lt;p id=&quot;NZdX&quot;&gt;Really, it all depends on your desired timeline, free time that you can dedicate to learn Python programming and the pace at which you learn.&lt;/p&gt;
  &lt;p id=&quot;yVSL&quot;&gt;&lt;strong&gt;&lt;a href=&quot;https://codingvidya.com/udacity-data-science-nanodegree-review/&quot; target=&quot;_blank&quot;&gt;udacity data science review&lt;/a&gt;&lt;/strong&gt; courses are created for you to go at your own speed. Each path is full of lessons, hands-on learning and opportunities to ask questions so that you get can an in-depth mastery of data science fundamentals.&lt;/p&gt;
  &lt;p id=&quot;hOZW&quot;&gt;Get started for free. Learn Python with our Data Scientist path and start mastering a new skill today!&lt;/p&gt;
  &lt;h2 id=&quot;Adse&quot;&gt;Where Can I Learn Python for Data Science?&lt;/h2&gt;
  &lt;p id=&quot;HphJ&quot;&gt;There are tons of Python learning resources out there, but if you&amp;#x27;re looking to learn it for data science, it&amp;#x27;s best to choose somewhere that teaches about data science specifically.&lt;/p&gt;
  &lt;p id=&quot;3h4n&quot;&gt;This is because Python is also used in a variety of other programming disciplines from game development to mobile apps. Generic &amp;quot;learn Python&amp;quot; resources try to teach a bit of everything, but this means you&amp;#x27;ll be learning quite a few things that aren&amp;#x27;t actually relevant to data science work.&lt;/p&gt;
  &lt;p id=&quot;Ku7k&quot;&gt;Moreover, working on something that doesn&amp;#x27;t feel connected to your goals can feel really demotivating. If you want to be doing data analysis and instead you&amp;#x27;re struggling through a course that&amp;#x27;s teaching you to build a game with Python, it&amp;#x27;s going to be easy to get frustrated and quit.&lt;/p&gt;
  &lt;p id=&quot;teS8&quot;&gt;There are lots of &lt;strong&gt;&lt;a href=&quot;https://codingvidya.com/best-python-books/&quot; target=&quot;_blank&quot;&gt;best python book for beginners&lt;/a&gt;&lt;/strong&gt; out there. If you don&amp;#x27;t want to pay to learn Python, these can be a good option — and the link in the previous sentence includes dozens, separated out by difficulty level and focus area.&lt;/p&gt;
  &lt;p id=&quot;rdNy&quot;&gt;If you&amp;#x27;re serious about it, though, it may be best to find a platform that&amp;#x27;ll teach you interactively, with a curriculum that&amp;#x27;s been constructed to guide you through your data science learning journey.&lt;/p&gt;
  &lt;h2 id=&quot;MS4V&quot;&gt;Is Python Necessary in the Data Science Field?&lt;/h2&gt;
  &lt;p id=&quot;jmuO&quot;&gt;It&amp;#x27;s possible to work as a data scientist using either Python or R. Each language has its strengths and weaknesses, and both are widely-used in the industry. Python is more popular overall, but R dominates in some industries (particularly in academia and research).&lt;/p&gt;
  &lt;p id=&quot;8ILW&quot;&gt;To do data science work, you&amp;#x27;ll definitely need to learn at least one of these two languages. It doesn&amp;#x27;t have to be Python, but it does have to be one of either Python or R.&lt;/p&gt;
  &lt;p id=&quot;dKeV&quot;&gt;(Of course, you&amp;#x27;ll also have to learn some SQL no matter which of Python or R you pick to be your primary programming language).&lt;/p&gt;
  &lt;h2 id=&quot;gmTe&quot;&gt;Is Python Better than R for Data Science?&lt;/h2&gt;
  &lt;p id=&quot;OUPt&quot;&gt;This is a constant topic of discussion in data science, but the true answer is that it depends on what you&amp;#x27;re looking for, and what you like.&lt;/p&gt;
  &lt;p id=&quot;00JI&quot;&gt;R was built with statistics and mathematics in mind, and there are amazing packages that make it easy to use for data science. It also has a very supporting online community.&lt;/p&gt;
  &lt;p id=&quot;k75F&quot;&gt;Python is a much better language for all-around work, meaning that your Python skills would be more transferrable to other disciplines. It&amp;#x27;s also slightly more popular, and some would argue that it&amp;#x27;s the easier of the two to learn (although plenty of R folks would disagree).&lt;/p&gt;
  &lt;p id=&quot;K7GJ&quot;&gt;Rather than reading opinions, check out &lt;strong&gt;&lt;a href=&quot;https://codingvidya.com/best-r-books/&quot; target=&quot;_blank&quot;&gt;best book for r programming beginners&lt;/a&gt;&lt;/strong&gt;, and see which one looks more approachable to you.&lt;/p&gt;
  &lt;h2 id=&quot;GBxS&quot;&gt;How is Python Used for Data Science?&lt;/h2&gt;
  &lt;p id=&quot;0JkW&quot;&gt;Programming languages like Python are used at every step in the data science process. For example, a data science project workflow might look something like this:&lt;/p&gt;
  &lt;ol id=&quot;I88d&quot;&gt;
    &lt;li id=&quot;N2i5&quot;&gt;1Using Python and SQL, you write a query to pull the data you need from your company database.&lt;/li&gt;
    &lt;li id=&quot;fUw6&quot;&gt;2Using Python and the pandas library, you clean and sort the data into a dataframe (table) that&amp;#x27;s ready for analysis.&lt;/li&gt;
    &lt;li id=&quot;Ye03&quot;&gt;3Using Python and the pandas and matplotlib libraries, you begin analyzing, exploring, and visualizing the data.&lt;/li&gt;
    &lt;li id=&quot;XhAG&quot;&gt;4After learning more about the data through your exploration, you use Python and the scikit-learn library to build a predictive model that forecasts future outcomes for your company based on the data you pulled.&lt;/li&gt;
    &lt;li id=&quot;No41&quot;&gt;5You arrange your final analysis and your model results into an appropriate format for communicating with your coworkers.&lt;/li&gt;
  &lt;/ol&gt;
  &lt;p id=&quot;AD5a&quot;&gt;Python is used at almost every step along the way!&lt;/p&gt;

</content></entry><entry><id>realfacts:awIMZ9BpE3z</id><link rel="alternate" type="text/html" href="https://teletype.in/@realfacts/awIMZ9BpE3z?utm_source=teletype&amp;utm_medium=feed_atom&amp;utm_campaign=realfacts"></link><title>Machin Learning interview questions asked in Top Companies</title><published>2021-09-16T10:00:03.950Z</published><updated>2021-09-16T10:06:17.031Z</updated><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img1.teletype.in/files/81/85/8185d309-8783-4389-a3c6-76f2e5864405.png"></media:thumbnail><summary type="html">&lt;img src=&quot;https://img3.teletype.in/files/ac/e9/ace97e0a-d82f-4c0e-ad17-d37ab1e456b0.jpeg&quot;&gt;This page will guide you to brush up on the skills of machine learning to crack the interview.</summary><content type="html">
  &lt;p id=&quot;1eCW&quot;&gt;This page will guide you to brush up on the skills of machine learning to crack the interview.&lt;/p&gt;
  &lt;p id=&quot;Av3h&quot;&gt;Here, our focus will be on real-world scenario ML interview questions asked in Microsoft, Amazon, etc., And how to answer them.&lt;/p&gt;
  &lt;p id=&quot;IQ1t&quot;&gt;Let’s get started!&lt;/p&gt;
  &lt;p id=&quot;q6TV&quot;&gt;Firstly, &lt;a href=&quot;https://codingvidya.com/best-machine-learning-books/&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Machine Learning&lt;/strong&gt; &lt;strong&gt;Books&lt;/strong&gt;&lt;/a&gt; refers to the process of training a computer program to build a statistical model based on data. The goal of machine learning (ML) is to turn data and identify the key patterns out of data or to get key insights.&lt;/p&gt;
  &lt;p id=&quot;zIqd&quot;&gt;For example, if we have a historical dataset of actual sales figures, we can train machine learning models to predict sales for the coming future.&lt;/p&gt;
  &lt;figure id=&quot;vEeA&quot; class=&quot;m_column&quot;&gt;
    &lt;img src=&quot;https://img3.teletype.in/files/ac/e9/ace97e0a-d82f-4c0e-ad17-d37ab1e456b0.jpeg&quot; width=&quot;815&quot; /&gt;
  &lt;/figure&gt;
  &lt;h2 id=&quot;dioL&quot;&gt;Why is the Machine Learning trend emerging so fast?&lt;/h2&gt;
  &lt;p id=&quot;tUJ6&quot;&gt;Machine Learning solves Real-World problems. Unlike the hard coding rule to solve the problem, machine learning algorithms learn from the data.&lt;/p&gt;
  &lt;p id=&quot;iU5r&quot;&gt;The learnings can later be used to predict the feature. It is paying off for early adopters.&lt;/p&gt;
  &lt;p id=&quot;yUtp&quot;&gt;A full 82% of enterprises adopting machine learning and Artificial Intelligence (AI) have gained a significant financial advantage from their investments.&lt;/p&gt;
  &lt;p id=&quot;fktC&quot;&gt;According to Deloitte, companies have an impressive median ROI of 17%.&lt;/p&gt;
  &lt;section&gt;
    &lt;h3 id=&quot;9KBl&quot;&gt;1. Why was Machine Learning Introduced?&lt;/h3&gt;
    &lt;p id=&quot;F1cc&quot;&gt;The simplest answer is to make our lives easier. In the early days of “intelligent” applications, many systems used hardcoded rules of “if” and “else” decisions to process data or adjust the user input. Think of a spam filter whose job is to move the appropriate incoming email messages to a spam folder.&lt;/p&gt;
    &lt;p id=&quot;b2ig&quot;&gt;But with the machine learning algorithms, we are given ample information for the data to learn and identify the patterns from the data.&lt;/p&gt;
    &lt;p id=&quot;QVTf&quot;&gt;Unlike the normal problems we don’t need to write the new rules for each problem in machine learning, we just need to use the same workflow but with a different dataset.&lt;/p&gt;
    &lt;p id=&quot;utWK&quot;&gt;Let’s talk about Alen Turing, in his 1950 paper, “Computing Machinery and Intelligence”, Alen asked, “Can machines think?”&lt;/p&gt;
    &lt;p id=&quot;iI0t&quot;&gt;Full paper here &lt;strong&gt;&lt;a href=&quot;https://codingvidya.com/best-machine-learning-books/&quot; target=&quot;_blank&quot;&gt;Best Machine Learning Books&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
    &lt;p id=&quot;YQTr&quot;&gt;The paper describes the “Imitation Game”, which includes three participants -&lt;/p&gt;
    &lt;ul id=&quot;jaIK&quot;&gt;
      &lt;li id=&quot;Ic7v&quot;&gt;Human acting as a judge,&lt;/li&gt;
      &lt;li id=&quot;JgfE&quot;&gt;Another human, and&lt;/li&gt;
      &lt;li id=&quot;jzD2&quot;&gt;A computer is an attempt to convince the judge that it is human.&lt;/li&gt;
    &lt;/ul&gt;
    &lt;p id=&quot;6jCL&quot;&gt;The judge asks the other two participants to talk. While they respond the judge needs to decide which response came from the computer. If the judge could not tell the difference the computer won the game.&lt;/p&gt;
    &lt;p id=&quot;pDR7&quot;&gt;The test continues today as an annual competition in artificial intelligence. The aim is simple enough: convince the judge that they are chatting to a human instead of a computer chatbot program.&lt;/p&gt;
  &lt;/section&gt;
  &lt;section&gt;
    &lt;h3 id=&quot;sWAl&quot;&gt;2. What are Different Types of Machine Learning algorithms?&lt;/h3&gt;
    &lt;p id=&quot;vt0U&quot;&gt;There are various types of machine learning algorithms. Here is the list of them in a broad category based on:&lt;/p&gt;
    &lt;ul id=&quot;OvLF&quot;&gt;
      &lt;li id=&quot;wJir&quot;&gt;Whether they are trained with human supervision (Supervised, unsupervised, reinforcement learning)&lt;/li&gt;
      &lt;li id=&quot;n5Tr&quot;&gt;The criteria in the below diagram are not exclusive, we can combine them any way we like.&lt;/li&gt;
    &lt;/ul&gt;
    &lt;figure id=&quot;pPOi&quot; class=&quot;m_original&quot;&gt;
      &lt;img src=&quot;https://img1.teletype.in/files/4b/0f/4b0fc661-eb4c-4fef-8f87-c34092696443.png&quot; width=&quot;3733&quot; /&gt;
    &lt;/figure&gt;
  &lt;/section&gt;
  &lt;section&gt;
    &lt;h3 id=&quot;ettC&quot;&gt;3. What is Supervised Learning?&lt;/h3&gt;
    &lt;p id=&quot;LpJ3&quot;&gt;Supervised learning is a machine learning algorithm of inferring a function from labeled training data. The training data consists of a set of training examples.&lt;/p&gt;
    &lt;p id=&quot;mKOE&quot;&gt;&lt;strong&gt;Example: 01&lt;/strong&gt;&lt;/p&gt;
    &lt;p id=&quot;aXG3&quot;&gt;Knowing the height and weight identifying the gender of the person. Below are the popular supervised learning algorithms.&lt;/p&gt;
    &lt;ul id=&quot;WcIh&quot;&gt;
      &lt;li id=&quot;AGhm&quot;&gt;Support Vector Machines&lt;/li&gt;
      &lt;li id=&quot;opZy&quot;&gt;Regression&lt;/li&gt;
      &lt;li id=&quot;CtBj&quot;&gt;Naive Bayes&lt;/li&gt;
      &lt;li id=&quot;FLgp&quot;&gt;Decision Trees&lt;/li&gt;
      &lt;li id=&quot;uTbG&quot;&gt;K-nearest Neighbour Algorithm and Neural Networks.&lt;/li&gt;
    &lt;/ul&gt;
    &lt;p id=&quot;PoIf&quot;&gt;&lt;strong&gt;Example: 02&lt;/strong&gt;&lt;/p&gt;
    &lt;p id=&quot;ktJ7&quot;&gt;If you build a T-shirt classifier, the labels will be “this is an S, this is an M and this is L”, based on showing the classifier examples of S, M, and L.&lt;/p&gt;
  &lt;/section&gt;
  &lt;section&gt;
    &lt;h3 id=&quot;v3f3&quot;&gt;4. What is Unsupervised Learning?&lt;/h3&gt;
    &lt;p id=&quot;vPCC&quot;&gt;Unsupervised learning is also a type of machine learning algorithm used to find patterns on the set of data given. In this, we don’t have any dependent variable or label to predict. Unsupervised Learning Algorithms:&lt;/p&gt;
    &lt;ul id=&quot;haPI&quot;&gt;
      &lt;li id=&quot;J5hi&quot;&gt;Clustering,&lt;/li&gt;
      &lt;li id=&quot;uf4U&quot;&gt;Anomaly Detection,&lt;/li&gt;
      &lt;li id=&quot;PYUH&quot;&gt;Neural Networks and Latent Variable Models.&lt;/li&gt;
    &lt;/ul&gt;
    &lt;p id=&quot;N1bC&quot;&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;/p&gt;
    &lt;p id=&quot;Oi19&quot;&gt;In the same example, a T-shirt clustering will categorize as “collar style and V neck style”, “crew neck style” and “sleeve types”.&lt;/p&gt;
  &lt;/section&gt;
  &lt;section&gt;
    &lt;h3 id=&quot;butT&quot;&gt;5. What is ‘Naive’ in a Naive Bayes?&lt;/h3&gt;
    &lt;p id=&quot;qHw5&quot;&gt;The Naive Bayes method is a supervised learning algorithm, it is naive since it makes assumptions by applying Bayes’ theorem that all attributes are independent of each other.&lt;/p&gt;
    &lt;p id=&quot;ueu2&quot;&gt;Bayes’ theorem states the following relationship, given class variable y and dependent vector x1 through xn:&lt;/p&gt;
    &lt;p id=&quot;Q9z5&quot;&gt;P(yi | x1,..., xn) =P(yi)P(x1,..., xn | yi)(P(x1,..., xn)&lt;/p&gt;
    &lt;p id=&quot;nJgs&quot;&gt;Using the naive conditional independence assumption that each xiis independent: for all I this relationship is simplified to:&lt;/p&gt;
    &lt;p id=&quot;oNZ2&quot;&gt;P(xi | yi, x1, ..., xi-1, xi+1, ...., xn) = P(xi | yi)&lt;/p&gt;
    &lt;p id=&quot;J3Gy&quot;&gt;Since, P(x1,..., xn) is a constant given the input, we can use the following classification rule:&lt;/p&gt;
    &lt;p id=&quot;iDaf&quot;&gt;P(yi | x1, ..., xn) = P(y) ni=1P(xi | yi)P(x1,...,xn) and we can also use Maximum A Posteriori (MAP) estimation to estimate P(yi)and P(yi | xi) the former is then the relative frequency of class yin the training set.&lt;/p&gt;
    &lt;p id=&quot;qyfL&quot;&gt;P(yi | x1,..., xn) P(yi) ni=1P(xi | yi)&lt;/p&gt;
    &lt;p id=&quot;nGha&quot;&gt;y = arg max P(yi)ni=1P(xi | yi)&lt;/p&gt;
    &lt;p id=&quot;LFRa&quot;&gt;The different naive Bayes classifiers mainly differ by the assumptions they make regarding the distribution of P(yi | xi): can be Bernoulli, binomial, Gaussian, and so on.&lt;/p&gt;
  &lt;/section&gt;
  &lt;section&gt;
    &lt;h3 id=&quot;qPZ3&quot;&gt;6. What is PCA? When do you use it?&lt;/h3&gt;
    &lt;p id=&quot;eBRg&quot;&gt;Principal component analysis (PCA) is most commonly used for dimension reduction.&lt;/p&gt;
    &lt;p id=&quot;9Lo5&quot;&gt;In this case, PCA measures the variation in each variable (or column in the table). If there is little variation, it throws the variable out, as illustrated in the figure below:&lt;/p&gt;
    &lt;figure id=&quot;Rgiz&quot; class=&quot;m_original&quot;&gt;
      &lt;img src=&quot;https://s3.ap-south-1.amazonaws.com/myinterviewtrainer-domestic/public_assets/assets/000/000/091/original/Principal_component_analysis_%28PCA%29.png?1614945016&quot; width=&quot;4126&quot; /&gt;
      &lt;figcaption&gt;Principal component analysis (PCA)&lt;/figcaption&gt;
    &lt;/figure&gt;
    &lt;p id=&quot;zbOw&quot;&gt;Thus making the dataset easier to visualize. PCA is used in finance, neuroscience, and pharmacology.&lt;/p&gt;
    &lt;p id=&quot;CLde&quot;&gt;It is very useful as a preprocessing step, especially when there are linear correlations between features.&lt;/p&gt;
  &lt;/section&gt;
  &lt;section&gt;
    &lt;h3 id=&quot;UzSn&quot;&gt;7. Explain SVM Algorithm in Detail&lt;/h3&gt;
    &lt;p id=&quot;I01g&quot;&gt;A Support Vector Machine (SVM) is a very powerful and versatile supervised machine learning model, capable of performing linear or non-linear classification, regression, and even outlier detection.&lt;/p&gt;
    &lt;p id=&quot;fVtT&quot;&gt;Suppose we have given some data points that each belong to one of two classes, and the goal is to separate two classes based on a set of examples.&lt;/p&gt;
    &lt;p id=&quot;yTDP&quot;&gt;In SVM, a data point is viewed as a p-dimensional vector (a list of p numbers), and we wanted to know whether we can separate such points with a (p-1)-dimensional hyperplane. This is called a linear classifier.&lt;/p&gt;
    &lt;p id=&quot;grwc&quot;&gt;There are many hyperplanes that classify the data. To choose the best hyperplane that represents the largest separation or margin between the two classes. &lt;br /&gt;If such a hyperplane exists, it is known as a maximum-margin hyperplane and the linear classifier it defines is known as a maximum margin classifier. The best hyperplane that divides the data in H3&lt;/p&gt;
    &lt;p id=&quot;JnPj&quot;&gt;We have data (x1, y1), ..., (xn, yn), and different features (xii, ..., xip), and yiis either 1 or -1.&lt;/p&gt;
    &lt;p id=&quot;I5KU&quot;&gt;The equation of the hyperplane H3 is the set of points satisfying:&lt;/p&gt;
    &lt;p id=&quot;WD9y&quot;&gt;w. x-b = 0&lt;/p&gt;
    &lt;p id=&quot;Y5hm&quot;&gt;Where w is the normal vector of the hyperplane. The parameter b||w||determines the offset of the hyperplane from the original along the normal vector w&lt;/p&gt;
    &lt;p id=&quot;OSoj&quot;&gt;So for each i, either xiis in the hyperplane of 1 or -1. Basically, xisatisfies:&lt;/p&gt;
    &lt;p id=&quot;HSFF&quot;&gt;w . xi - b 1 or w. xi - b -1&lt;/p&gt;
    &lt;figure id=&quot;eYWE&quot; class=&quot;m_original&quot;&gt;
      &lt;img src=&quot;https://img4.teletype.in/files/3c/ce/3cce18b6-62e6-45dd-9300-9e91ac25435b.png&quot; width=&quot;3087&quot; /&gt;
    &lt;/figure&gt;
  &lt;/section&gt;
  &lt;section&gt;
    &lt;h3 id=&quot;O3Ng&quot;&gt;8. What are Support Vectors in SVM?&lt;/h3&gt;
    &lt;p id=&quot;RUkp&quot;&gt;A Support Vector Machine (SVM) is an algorithm that tries to fit a line (or plane or hyperplane) between the different classes that maximizes the distance from the line to the points of the classes.&lt;/p&gt;
    &lt;p id=&quot;H6iF&quot;&gt;To get in-depth knowledge on&lt;strong&gt; ML lets try &lt;a href=&quot;https://codingvidya.com/machine-learning/&quot; target=&quot;_blank&quot;&gt;Machine Learning&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
    &lt;p id=&quot;ss2X&quot;&gt;In this way, it tries to find a robust separation between the classes. The Support Vectors are the points of the edge of the dividing hyperplane as in the below figure.&lt;/p&gt;
    &lt;figure id=&quot;qttJ&quot; class=&quot;m_original&quot;&gt;
      &lt;img src=&quot;https://img2.teletype.in/files/d5/4e/d54e8f9b-ddb1-4c4b-a179-3608699e2e6f.png&quot; width=&quot;3248&quot; /&gt;
    &lt;/figure&gt;
  &lt;/section&gt;
  &lt;section&gt;
    &lt;h3 id=&quot;C1uw&quot;&gt;9. What are Different Kernels in SVM?&lt;/h3&gt;
    &lt;p id=&quot;5D3o&quot;&gt;There are six types of kernels in SVM:&lt;/p&gt;
    &lt;ul id=&quot;Emvl&quot;&gt;
      &lt;li id=&quot;6Ubn&quot;&gt;Linear kernel - used when data is linearly separable.&lt;/li&gt;
      &lt;li id=&quot;TyCd&quot;&gt;Polynomial kernel - When you have discrete data that has no natural notion of smoothness.&lt;/li&gt;
      &lt;li id=&quot;Bw6B&quot;&gt;Radial basis kernel - Create a decision boundary able to do a much better job of separating two classes than the linear kernel.&lt;/li&gt;
      &lt;li id=&quot;dJSj&quot;&gt;Sigmoid kernel - used as an activation function for neural networks.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/section&gt;
  &lt;section&gt;
    &lt;h3 id=&quot;aCaS&quot;&gt;10. What is Cross-Validation?&lt;/h3&gt;
    &lt;p id=&quot;7UzX&quot;&gt;Cross-validation is a method of splitting all your data into three parts: training, testing, and validation data. Data is split into k subsets, and the model has trained on k-1of those datasets.&lt;/p&gt;
    &lt;p id=&quot;iCwC&quot;&gt;The last subset is held for testing. This is done for each of the subsets. This is k-fold cross-validation. Finally, the scores from all the k-folds are averaged to produce the final score.&lt;/p&gt;
    &lt;figure id=&quot;AUJl&quot; class=&quot;m_original&quot;&gt;
      &lt;img src=&quot;https://img3.teletype.in/files/a2/f4/a2f4c548-e696-4060-bb3e-155d735e7de9.png&quot; width=&quot;2517&quot; /&gt;
    &lt;/figure&gt;
  &lt;/section&gt;

</content></entry></feed>