Machine Learning from Scratch?

Machine Learning from Scratch?

Before you start with machine learning from scratch there is a piece of advice I would like to give my readers. The field of machine learning(ML) is a field that needs dedication and a correct mindset. We are dealing with data, which is a core of any machine learning algorithm. If you are able to understand what you need from the data then your half work is done. To help you I will walk you through a problem that has been added to Kaggle as a competition. In this way, you will learn Kaggle and learn how to write your first machine learning code.

Objectives

  • Teach you machine learning
  • Get you familiar with the Kaggle platform, so that you are able to take part in competitions.

Let’ start with the basic definition of machine learning. It is the ability to improve behavior based on experience. Machine Learning explores algorithms that learn from data, build models from data.

Now a question arises, “What is a model?”

According to Microsoft,

A machine learning model is a file that has been trained to recognize certain types of patterns. You train a model over a set of data, providing it an algorithm that it can use to reason over and learn from those data.

According to AWS

The term ML model refers to the model artifact that is created by the training process.

To my understanding ML model is a mathematical equation, with computation capabilities that if trained with data , learns patterns in data, store intermediate information so as to predict or classify whenever we give unseen data to it.

I had used many terms like mathematical equation, computation capabilities, training, learning patterns, classification, and prediction. I will be explaining all these terms while explaining the process. So now let us learn machine learning from scratch.

The Process

  1. Data understanding, Data Preprocessing
  2. Model Building
  3. Training
  4. Model Selection
  5. Predictions

All the above steps are the basic steps involved in machine learning. We will take one case study and solve it using machine learning. In the process we will follow all the steps mentioned in the paragraph above.

Case Study: Titanic

Here we will start with the problem Titanic – Machine Learning from Disaster. We have to Predict survival on the Titanic and get familiar with ML basics. This is a Kaggle competition. This way I will guide you on how to start with the Kaggle competition and learn by doing.

I will give you my understanding of the problem. I would suggest you first take a look at the Titanic- Machine Learning from Disaster page and go through the description of the problem. To get started with the problem you can follow this tutorial.

First you need to Join the competition from the competition page. To do this click Join Competition button. After that then click on I Understand and Accept.

Machine Learning from Scratch

Now let us move a step at a time and understand the entire process. I’ll start with the data understanding and data preprocessing step.

Data Understanding and Data Preprocessing

For the Titanic problem, we have to first understand the data in the data set. The problem we have to solve here is in this challenge, “What sorts of people were more likely to survive?” using passenger data (ie name, age, gender, socio-economic class, etc).

A dataset is a collection of data.

To study data you need to click on data tab.

Machine Learning from Scratch
Data Tab of Problem window in Kaggle

When you scroll down, you will find three files namely train.csv, test.csv, and gender_submission.csv. Download the data and open the CSV file. You will find different columns. Let us understand closely each column in each file.

train.csv

VariableDefinitionKey
PassengerIdUnique ID of each passenger1 – 891
Survivedwhether survived or not0: could not survive and 1: survived
PclassTicket Class1 = Ist Class, 2 = IInd Class, 3 = IIIrd Class
NameName of Passenger
sexGender of Passengermale, female
AgeAge of the Passenger
SibSpNumber of siblings/ spouses on the ship
ParchNumber of parents/children on the ship
ticketTicket number
farePassenger fare
cabinCabin number
embarkedPort from where passengers boarded the shipC = Cherbourg, Q = Queenstown, S = Southampton
Data Dictionary: train.csv

Let us closely watch dataset train.csv and ask some questions from it.

  1. Is there a correlation between survived and the sex of the passenger?
  2. Is there a correlation between survived and age of passenger?
  3. Is there a correlation between survived and Siblings or spouses on the ship?
  4. Is there a correlation between survived and the number of parents/children on the ship?
  5. Is there a correlation between survived and fare paid by the passenger?
  6. Is there a correlation between survived and embarked?

My hypothesis related to each feature is described below. The validity of the hypothesis will be found after the predictions made by the algorithm.

A hypothesis is an educated guess about something in the world around you. It should be testable, either by experiment or observation. -Statisticshowto.com

  1. From this question, we will try to find the relationship between the survival rate of men and women. Women have a better survival rate than men.
  2. Younger passenger has better survival rate than children and older passengers.
  3. If a person is well off and has siblings or spouses then they have a better chance of survival.
  4. If a person is well off and has parents or children then they have a better chance of survival.
  5. I think the fare is directly related to class, therefore we can do away with this feature.
  6. I think this question can be used to find the survival relationship with embarked.

Now since we have placed our hypothesis, we need to test our hypothesis for its validity in my next article.

References:

Leave a Reply

Your email address will not be published. Required fields are marked *

Creative Commons License
Except where otherwise noted, Open Source Open Mind by Gaurav Parashar is licensed under a Creative Commons Attribution 4.0 International License.