Hi everyone!!
Recently, Microsoft Student Partner Community launched an exclusive contest for Microsoft Students Partners of India. As per that contest, we are supposed to write a blog on topic Machine Learning or Artificial Intelligence. So as a part of the “MSP Developer Stories” initiative, here is my small contribution to the contest.
I am a newbie at Data Science and Machine Learning thing. I tried to learn Machine Learning an year ago or so, but the things didn’t work out great for me then. This is because I couldn’t find any good resources to learn. The code available on the internet is too complex to be digested by beginners.
I had to participate in this contest, so I decided to work again. I learned the basics of Machine Learning and Data Science from Learning Paths of Microsoft Learn and the results are unexpectedly great this time. I strongly recommend Microsoft Learning Paths for beginners from now on as I had an amazing experience.
In this blog, I will be sharing my first ever project on Machine Learning build from scratch.
Introduction to Machine Learning:
Some people consider Machine Learning as a subset of Artificial Intelligence. The Internet is flooded with such kinds of definitions. But I feel that Machine Learning is a bridge between Data Analysis and Artificial Intelligence. It is a tool used to perform Data Analytics for building models to serve the progressions of Artificial Intelligence.
So, let's break our project into 3 modules:
1. Analysis of the data
2. Building a Machine Learning model
3. Implementing Artificial Intelligence for predictions
Corona Virus is the hot topic of this time. So I have decided to choose COVID-19 as the topic of my project. So, let’s begin…
Application of Data Science on the Analysis of COVID-19 patients of Italy:
Data is like the food provided to the AI to help it grow. The more the data provided, the better the AI model is expected to be. Can we improve the quality of the food? Data Science is used to clean the data to remove its anomalies and imperfections, thus improving the quality of data to be served to the model.
In the first part of our project, we will be visualizing the data by using some statistical tools provided by various libraries of python. We will use azure notebooks as the IDE. We will also be cleaning the data if any anomalies are found.
Making the environment ready:
1. Go to https://notebooks.azure.com/. Sign in to your Microsoft account.
Students can have a free account worth $100. Check more details here: https://azure.microsoft.com/en-in/free/students/
We will be creating a Jupyter Notebook hosted on Azure.
2. Click on My Projects.
![](https://static.wixstatic.com/media/94f9ed_35eb946b14b647e6a7e6d1974b488abf~mv2.png/v1/fill/w_752,h_164,al_c,q_85,enc_auto/94f9ed_35eb946b14b647e6a7e6d1974b488abf~mv2.png)
3. Click on +New Project.
![](https://static.wixstatic.com/media/94f9ed_d339fec8f6d14f53a8b06a9ceeb6dff1~mv2.png/v1/fill/w_980,h_167,al_c,q_85,usm_0.66_1.00_0.01,enc_auto/94f9ed_d339fec8f6d14f53a8b06a9ceeb6dff1~mv2.png)
4. Write a catchy project name like COVID-19 Analysis or My First ML Project. Click on create.
![](https://static.wixstatic.com/media/94f9ed_a58a3918d2564a26af19bbb5cbbe2e94~mv2.png/v1/fill/w_877,h_679,al_c,q_90,enc_auto/94f9ed_a58a3918d2564a26af19bbb5cbbe2e94~mv2.png)
5. The project directory will open. Click on +New and the select Notebook.
![](https://static.wixstatic.com/media/94f9ed_33a3da237eff415294296e037eaeee86~mv2.png/v1/fill/w_858,h_290,al_c,q_85,enc_auto/94f9ed_33a3da237eff415294296e037eaeee86~mv2.png)
6. Write a name for your notebook and select Python 3.6. An extension “.ipynb” will be added automatically after the name of your notebook, which suggests that this document is an interactive python notebook. Click on the New button to create a new notebook.
![](https://static.wixstatic.com/media/94f9ed_c7c79c4527744b3faae866a236b346bc~mv2.png/v1/fill/w_859,h_668,al_c,q_90,enc_auto/94f9ed_c7c79c4527744b3faae866a236b346bc~mv2.png)
7. Now let’s download a dataset from Kaggle. Here is the direct link of the dataset:
Download and extract the zip file in your local machine.
8. In Azure Notebook created above, click on File-> Upload. Select the national_data.csv file.
9. Make sure you select /project before clicking on Start Upload.
![](https://static.wixstatic.com/media/94f9ed_65fb71379c574b2abf1d64d2d7d070da~mv2.png/v1/fill/w_856,h_325,al_c,q_85,enc_auto/94f9ed_65fb71379c574b2abf1d64d2d7d070da~mv2.png)
Let the Code begin:
Note: The italicized lines at the center of each step can be copy-pasted directly into Jupyter notebook for convenience purposes. Though I strongly suggest writing code on your own.
1. We will first import the pandas library. It is an open-source library written in python and is very helpful for data analytics.
import pandas as pd
Click Shift+Enter to execute the cell selected. You will not see any output. Just a library will be included.
2. Now create a DataFrame by reading the imported csv file. Execute the cell but no visible output will be produced.
df=pd.read_csv('national_data.csv')
3. Let’s see how our data looks like. head() function shows the top 5 rows of our data.
df.head()
After executing, make sure output looks the same.
![](https://static.wixstatic.com/media/94f9ed_2902b1ce98a34f24916caecdcd0ce1d0~mv2.png/v1/fill/w_980,h_367,al_c,q_85,usm_0.66_1.00_0.01,enc_auto/94f9ed_2902b1ce98a34f24916caecdcd0ce1d0~mv2.png)
4. OOPS!! Column headings are in Italian language. In a new cell, I selected the input to be of markdown format. I googled the meaning of all these headings and noted them in markdown cells for reference purposes.
data: Date of notification deceduti: Deceased people dimessi_guariti: Discharged, people healed isolamento_domiciliare: People in home isolation note_en: note English note_it: note Italian nuovi_positivi: Total amount of current positive cases ricoverati_con_sintomi: New amount of current positive cases stato: State of reference tamponi: tests/swabs terapia_intensiva: Hospitalized in intensive care totale_casi: Total amount of positive cases totale_ospedalizzati: Total hospitalized patients totale_positivi: total positive variazione_totale_positivi: total change positive
![](https://static.wixstatic.com/media/94f9ed_f9ceb00d35af41da910338044f21bfc0~mv2.png/v1/fill/w_634,h_159,al_c,q_85,enc_auto/94f9ed_f9ceb00d35af41da910338044f21bfc0~mv2.png)
![](https://static.wixstatic.com/media/94f9ed_fa0cf10f4be14f29b1897f3664a83088~mv2.png/v1/fill/w_864,h_761,al_c,q_90,enc_auto/94f9ed_fa0cf10f4be14f29b1897f3664a83088~mv2.png)
5. Why not rename the columns of the dataframe? Ok, let’s do this.
df.rename(columns={'data':'Date of notification','deceduti':'Deceased people','dimessi_guariti':'Discharged, people healed','isolamento_domiciliare':'People in home isolation','note_en':'note english','note_it':'note italian','nuovi_positivi':'Total amount of current positive cases','ricoverati_con_sintomi':'New amount of current positive cases','stato':'State of reference','tamponi':'tests/swabs','terapia_intensiva':'Hospitalized in intensive care','totale_casi':'Total amount of positive cases','totale_ospedalizzati':'Total hospitalised patients','totale_positivi':'total positive','variazione_totale_positivi':'total change positive'}, inplace=True)
6. Let’s see how our data looks now.
df.head()
![](https://static.wixstatic.com/media/94f9ed_067d2b3f05974dbdafab3a8346280932~mv2.png/v1/fill/w_980,h_407,al_c,q_90,usm_0.66_1.00_0.01,enc_auto/94f9ed_067d2b3f05974dbdafab3a8346280932~mv2.png)
Yeah, the data looks good now. Note that the rename function does not amend the original database. It just makes amendments to the existing dataframe.
7. Let’s proceed towards data cleaning. Now check if any NULL value is present in any column of the data.
df.isnull().sum()
![](https://static.wixstatic.com/media/94f9ed_0fee5f6b636f48e98cac779c2bd17d30~mv2.png/v1/fill/w_545,h_429,al_c,q_85,enc_auto/94f9ed_0fee5f6b636f48e98cac779c2bd17d30~mv2.png)
8. Yes, 2 columns contain a lot of null values. So let’s drop these columns of the dataframe.
df=df.drop(['note english','note italian'],axis=1)
![](https://static.wixstatic.com/media/94f9ed_bf6ebd1b9cd548bebeabe96fa5f27cb2~mv2.png/v1/fill/w_549,h_47,al_c,q_85,enc_auto/94f9ed_bf6ebd1b9cd548bebeabe96fa5f27cb2~mv2.png)
9. Now, check if the columns have been dropped or not.
df.head()
![](https://static.wixstatic.com/media/94f9ed_9aa84d2e1a554385a5189b650d03315b~mv2.png/v1/fill/w_980,h_313,al_c,q_85,usm_0.66_1.00_0.01,enc_auto/94f9ed_9aa84d2e1a554385a5189b650d03315b~mv2.png)
10. Yes, the columns have been removed. But I am going to check once again if the data is really clean or not.
df.isnull().sum()
![](https://static.wixstatic.com/media/94f9ed_91cbf58d217e4da1b1051714352edb24~mv2.png/v1/fill/w_527,h_387,al_c,q_85,enc_auto/94f9ed_91cbf58d217e4da1b1051714352edb24~mv2.png)
11. None of the columns have any NULL value. Data is now ready to be processed and is usable for various calculations. Now we are going to visualize the data.
df.describe()
It gives an overall description of the data. This function is very useful as it builds our understanding of the data. We get to see what kind of data is present and what boundaries are needed to be taken care of.
![](https://static.wixstatic.com/media/94f9ed_506f74d571f841c1a483c59c06de6254~mv2.png/v1/fill/w_980,h_299,al_c,q_85,usm_0.66_1.00_0.01,enc_auto/94f9ed_506f74d571f841c1a483c59c06de6254~mv2.png)
12. Now we are going to plot a curve to see an increase in total corona positive cases in Italy over time. I made a small dataframe dfl which includes a copy of one column of our main dataframe.
dfl=df[['Total amount of positive cases']] dfl.plot(title='Increase in total positive corona cases found in Italy by the end of March-20')
![](https://static.wixstatic.com/media/94f9ed_ff4fbc34ba7c44ac9d9be62d0f98c025~mv2.png/v1/fill/w_980,h_419,al_c,q_90,usm_0.66_1.00_0.01,enc_auto/94f9ed_ff4fbc34ba7c44ac9d9be62d0f98c025~mv2.png)
13. Let’s plot a bar graph to visualize total corona positive cases found each day in Italy.
dfb=df[['Total amount of current positive cases']]
dfb.plot.bar(title="COVID+ cases each day")
![](https://static.wixstatic.com/media/94f9ed_02a9daf1fca0492f98f6d3cfe0f58e20~mv2.png/v1/fill/w_737,h_487,al_c,q_85,enc_auto/94f9ed_02a9daf1fca0492f98f6d3cfe0f58e20~mv2.png)
14. Now let’s visualize two pieces of information in a single figure. For instance, let’s compare the total people who died vs total people recovered from coronavirus in Italy over time.
df1=df[['Deceased people','Discharged, people healed']] df1.plot.area(title="People died VS People healed in Italy")
![](https://static.wixstatic.com/media/94f9ed_22492096f5d04ffc8c712235889c2c2c~mv2.png/v1/fill/w_774,h_496,al_c,q_90,enc_auto/94f9ed_22492096f5d04ffc8c712235889c2c2c~mv2.png)
I feel that it is enough visualization for blogging purpose. I am going to explore various other methods of visualization. You too try to have a deep understanding of data so that we can perform appropriate calculations in the next step of our project.
See you in the next blog. Until then have a good time.
Stay Healthy, Stay Safe!
コメント