Supervised Learning
What is Supervised Learning?
Supervised learning refers to the use of labeled datasets to train algorithms that classify data or predict outcomes accurately. Supervised learning needs an accurately labeled dataset which is exhausting. Nevertheless, it is a really powerful and popular method. In this method, the machine learning algorithms focus on the labeled data to train the data set. Supervised learning helps organizations solve a variety of real-world problems at scale, such as predicting the prices of houses or cars, and classifying spam in a separate folder from your inbox. Some methods used in supervised learning include neural networks, naïve Bayes, linear regression, logistic regression, random forest, support vector machine, and more. The ML algorithm could be given a small training dataset that is a part of the bigger one in order to achieve a basic idea of the problem, solution, and data points. The algorithm then finds relationships between the parameters given. At the end of the training, the algorithm has an idea of how the data works and the relationship between the input and the output.
Supervised learning is where you have input variables (x) and an output variable (Y) and you use an algorithm to learn the mapping function from the input to the output.
Before we pass to the example we have to decide which one of the algorithms will be used.
Linear or Logistic Regression
Linear Regression is a commonly used supervised ML algorithm that predicts continuous values. Linear Regression assumes that there is a linear relationship between dependent and independent variables. In simple words, it finds the best fitting line/plane that describes two or more variables. On the other hand, Logistic Regression is another supervised “Machine Learning” algorithm that helps fundamentally in classification.
One key difference between logistic and linear regression is the relationship between the variables. Linear regression occurs as a straight line and allows analysts to create charts and graphs that track the movement of linear relationships. However, since logistic regression examines the probability of an event rather than the linear structure of a variable relationship, it’s unnecessary to track logistic regression using linear structures. Basically, logistic regression can hold non-linearity between variables.
- Continuous variables represent infinite values.
- Discrete ordinal variables have a ranking order and end at some point.
- Discrete nominal variables also end at some point but have no ranking order.
Steps of Linear Regression
Step 1
As a first step, the dependent and independent values are divided under the names X and Y. But first of all “get_dummies” must be applied.
Step 2
In this step, the data must be split into “Train” and “Test”.
In machine learning, datasets are split into two subsets.
The training data is a subset of your dataset that you use to teach a machine learning model to recognize patterns or perform your criteria.
Once your machine learning model is built (with your training data), you need unseen data to test your model. This data is called testing data, and you can use it to evaluate the performance and progress of your algorithms’ training and adjust or optimize it for improved results.
Get Baris Gül’s stories in your inbox
Join Medium for free to get updates from this writer.
Testing data has two main criteria. It should:
- Represent the actual dataset.
- Be large enough to generate meaningful predictions.
Step 3
- The “LinearRegression” will be determined as “lr”. And the suitability of “Train” and “Test” subsets is evaluated with “Score”.
As seen the “Train” and “Test” sebsets were split well. In this part, the other themes won’t be covered. Otherwise, there are many implementations to make better results.
Step 4
- To evaluate the model there are some methods. These will be covered additionally in another article. But as an example, “mean_squared_error” will be implemented.
So far the model was covered generally. It is too basic for the beginning.
Steps of Logistic Regression
As the other supervised type was explained before, this will be also covered in the same way step by step.
Step 1
The Target is the “Survived column”. After the determination of “independent” and “dependent ” values, subsets are split.
Step 2
This step aims to fit the data with the “logistic regression” model.
Step 3
In this step, the model will be evaluated with evaluation metrics in logistic regression.
It might be said that overfitting exists here.
Step 4
In logistic regression, there is a parameter so-called “C”. It helps to regularize the data. Now, it will be tried.
Step 5
To see how well the model was executed, let’s take a look at confusion_matrix.
- 114 of them were predicted “T-T”
- 13 of them were predicted “T-F”
- 37 of them were predicted ”F-T”
- 59 of them were predicted “F-F”
Step 6
In this step, a data set will be entered into the model.
It is also a basic approach to logistic regression. So far the general explanation for both “logistic” and “linear” regressions was handled.









