Let’s Learn ML

A gentle introduction to ml and writing one's own classifiers using python.

Dear reader,

At the very beginning of mankind, we predicted whether or not the food was edible or not. How ? let me tell you when a substance was being eaten by an animal mainly dears, and goats if the animal died the people got to know that, okay so this is not edible they just plucked it out from the place and threw them away in the barren piece of land somewhat like the dumping grounds we have today and if the animal survived they all became happy and celebrated that day and they collected that fruit or vegetable or leave as much as they could.

Now in this few last century machines also have started classification and analysis. it is so fascinating to see machines predict things. we don't also know but in our daily life, we are using machine learning and artificial intelligence to perform tasks for us. checking the weather, robotic hands doing work in a factory, computers doing billions and billions of instructions in a minute ever wonder how these things are done.

In this tutorial, I would be using python to code our own classifier from scratch and learn very basic machine learning.

Our brain is very good at emotions and processing and doing work properly in a step by step manner. but computers excel from us because they can do extreme calculations. Machine learning gives machines a brain with intelligence about a particular task and artificial intelligence automates all the tedious and long works for us and makes the lives of people easier. In this blog, I will cover a very basic 2 part of Machine Learning Regression and classification. it is enough to get started. Eg- Project HAESolve is a project that helps people around the globe with machine learning and artificial intelligence.

Our first simple problem

you are given a task to find the price of land given sq. miles.

you have got a piece of simple data with sq. miles and price and now you have to find the price of the land given the square miles

python provides 3 fantastic libraries namely NumPy, pandas, Scikit-Learn

NumPy helps with algebra, pandas help with reading data, and editing and formatting, and Scikit-Learn helps in making predictive models and machines.

So, let’s start some coding for the problem.

And voila solved the first problem feeling proud of yourself to wait there is more to cover and solve. feeling the breeze through your hair and power in hand I know and it will be more fun while you solve the first exercise that you will get at the end of the blog.

The great flower mystery

You are a programmer appointed to do a task.

There is a great mystery an owner of a garden has to give 2 drops of medicine on A flower but there are 6 flowers in the garden where there are B flowers also now you have to classify A and B flowers to help that person.

data for us

let’s go…

And, congo! you are done solving your task as a programmer. Feeling very happy right. I know now fasten your seat belts and get ready for the race to begin:-

Get, Set, Go ……

The best part of the blog our own regression and classification models.

Our simple yet powerful regression model at first I will write the code then I will explain it.

let’s code

Now let’s understand it thoroughly inside our brain the processing happens in the following way.

Our brain takes the input and multiplies it with a weight, now weight for the neuron is like the amount of processing needed, and bias is added to the data.

So we at first start with a random set of weight and a random bias and then keep changing them this procedure is called gradient descent. here is a visualization of step by step gradient descent.

There are many ways to calculate gradient descent. and gradient descent is often called the optimization process as it optimizes your results and by adjusting the weights and bias.

Now we can program linear regression and do some great stuff, play around with the code soon I will be adding my NumPy and pandas series blogs on medium.

Logistic Regression sounds logit

Here also I will write code first and then explain why?

code:-

here in the above picture logit score means our x X weights + bias. we just follow our steps followed in linear regression only add a small part that is an activation function or the function which helps in converting the logit scores into a probabilistic map or the probability of the object falling into the following category and here the optimization is a cross-entropy loss. Rest everything is the same for logistic regression.

So, I can see that beam. You just finished learning the basics of machine learning.

Now time for some exercise:-

data for exercise 1 (copy the following data and save it as data.csv and complete the program yourself):-

data for exercise 2 (copy the following variable and complete the exercise):-

Please do share your result with me at goswamidivyosmi@gmail.com.

Thank you.

Written by

Divyosmi Goswami: A digital nomad's journal wandering through the physical and cyber city discovering himself.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store