Olympic Medal Prediction Using Machine Learning

Hello, how una dey? This project na for people wey wan just start Machine Learning (ML) but dem no no where to start.

This project na all about predicting how many medals a particular country will win based on the data we get for ground. But for any Machine Learning Project wey you wan undertake like Undertaker wey dey fight wrestling, you must follow 7-steps which we go mention right-away. Oya, carry your bodi….follow me!

7-Steps To Use To Sama Any ML Project

  1. Form an Hypothesis: An hypothesis na anything you fit prove or disapprove using data. The dataset set we go use for this Project na teams.csv and you fit download am hia.
  2. Find the data: As you know, concortion rice no fit complete if you no add maggi and if you be Yorùbá, if pepper no too much for the rice, your concortion project is incomplete. So therefore, you need dataset wey go contain important things like country name, how many medals dem don win before, if dem be arupo etc; to predict how many medal that country go win for another Olympic wey never even happen at all or wey don happen before just to help your curiousity…..Make we kontunu!
  3. Reshape the Data: Why you go reshape your dataset be say you go dey sure say everything wey you need inside dey there if not, as a beginner e fit cause small gbege. E go con be like say you dey chop food wey no get salt. So data reshaping dey very crucial like money wey you wan give Lagos bus conductor. You know say you no go fit owe Lagos conductor money? My dear….you nor fit…!
  4. Clean the Data: Most Machine Learning algorithms no go work on missing values. Any column or row for your teams.csv dataset wey get dash (-) or wey dey empty, na here you go comot everything patapata. Account balance wey even dey reflect zero naira beta pass the one wey no reflect anything. At least mind go dey at rest say the person dey see zero balance than wey everywhere blank….chai!
  5. Error Metric: After machine learning algorithm don work finish, na this guy go con check am if e do well abi e just dey whine you. The one wey we go use for this project na Mean Absolute Error. The formula dey below. No worry yourself if e dey look like greek, e no girikee anything, you go see how we go crush am like Netflix popcorn now…

Fig 1.

I dey come make I quickly go borrow one proverb from overseas….

The pikin wey no wan allow hin mama sleep, na hin be say e no wan make hin mind touch ground be that…. NA HULK HOGAN TALK AM IN 1806

6. Split the Dataset into Train/Test: Just like when you cook too much egusi and light dey wey your freezer tanda you no go wan deep your one wrap of fufu inside the newly cooked finger-licking soup (wait, you sabi cook?). You go comot the one wey you go chop (test data – 20%) and put the one wey remain for freezer (trained data – 80%). Make sure you cover am well sha….why? Your guess is as good as mine! Na the one wey you wan chop go tell you how sweet the egusi feel for mouth….which means na the test data you go use your machine learning (ML) algorithm on.

7. Train the Data: The ML algorithm wey we go use for this project na wetin dem dey call Linear Regression. Why we choose Linear Regression be say:

Linear regression analysis is used to predict the value of a variable based on the value of another variable. The variable you want to predict is called the dependent variable. The variable you are using to predict the other variable’s value is called the independent variable. Source (Wikipedia).

No forget say the fine taste of your egusi soup and the thickness depends on crayfish/shrimp, meat stock, dried fish and the vegetable leaves wey you sprinkle on top am. So also, the result of our Prediction according to Linear Regression Algorithm is dependent on some factors on like previous medals won, number of team, country name and year on our Dataset wey be teams.csv. 

Make we enter engine room make we do small coding so we go predict weather USA and co wey dey inside the dataset and dem don win plenty medals before weda dem go smell any medal for another Olympic or anyone wey go happen for future or na clap dem go clap for dem as dem dey go house. If we predict am and we dey certain, e mean say something wey better pass bet9ja dey wey person fit put body!

PART 2 – OLYMPIC MEDAL PREDICTION USING MACHINE LEARNING (CODING)

  1. Step 1 (Form an Hypothesis): We wan predict how many medal a particular country go win for the Olympic wey don happen or wey never happen at all.
  2. Step 2 (Find the Data):  Let’s say we wan cook indomie, the certain ingredient wey we go need na water. No, you no need egg, shrimp, fresh pepper, onion, tomato, dried fish, fresh vegetables, onions….all those ones na like you dey stress yourself. Just put water for fire, as the water dey boil, and you put the indomie, the water go do wetin? Chuk the indomie, soften am, boil am well….indomie don ready be that. Yes or yes? So for our coding, we need something wey go help us chuk and boil our dataset (teams.csv), and the best thing to use na Python but Python con get too many “layers” AKA Libraries, so we go use the one wey go behave like water for our indomie. Wetin be hin name? Hin name na PANDAS. As you take pour water inside pot, you go need stove/gas/coal Pot plus the water no just appear inside your pot nau, na you carry water put for pot, na so we go take go call our pandas and how you go call am? First, you go need code editors like Jupyter Notebook  or Google Colab (Gas/Stove/Coal Pot) and then add your teams.csv file inside then import your Pandas (put water for pot):

Fig 2.

import pandas as pd

This code means say you dey call Pandas make e con help you chuck eye for your dataset (teams.csv). You con tell am say, I no go dey fit type pandas pandas pandas all the time o, once you see pd, dey run dey come like dog wey see bone!

teams = pd.read_csv(“teams.csv”)

This code means say you dey tell pd (pandas) make e read the csv data wey you wan give am but you nickname am as teams wey dey by the left. So anytime wey you type teams like this, make the excel sheet just open yakata. Hence, code number 3. You understand or you no understand?

Task: Open the teams.csv in Microsoft Excel, you’ll see it has 2144 rows and 11 columns.

NEXT…..

Fig 3.

3. Step 3 (Reshape the Data): E be like say the 11 columns too much for wetin we wan do, make we just focus on the most important columns like “team”, “country”, “year”, “athletes”, “age”, “prev_medals”, “medals” make we comot height, weight, event columns from our dataset abeg.

So as your income dey boil, you no listen to my advice nau, you go put egg bah? As the egg don boil, you go need comot am to remove the shell. You go need spoon to comot am nau, abi your fingers are made from Germany? Chai! Same thing for this dataset o, we go need formula wey go help us comot the columns….na the formula be:

teams = teams[[“team”, “country”, “year”, “athletes”, “age”, “prev_medals”, “medals”]]

E mean say you dey tell Jupiter Notebook or Google Colab say na the only columns wey you mention above you wan see for your teams.csv column.

If you type the code:

teams

You set go see say all other columns wey dey do the dataset like doti don go. E mean say you don do part of Step 4 here (Clean the Data). “The whole smell for fish, E don die comot)!🐟😍

Yorubas say if person dey cry, make den dey see road oooo, so therefore, make we even check the correlation or link between the medal column wey be the koko column and other columns in our new dataset. This go help us know if the predictions go dey even possible. Na like say you wan cook beans with gas around 11PM, you no check if gas dey, as you pour the bean, na so gas finish, na to just wait for sun the next day to dry the water comot….E mean say you no check your corre wetin? CORRELATION. Na the formula be:

teams.corr()[“medals”]

The correlation answer go give between zero (0) to one (1) and as you can see for yourself in the screenshot above, athlete (0.840817) and prev_medal (0.920048) columns dey be like say dem dey high which means we fit use these two columns run tinz and tinz.

GRAPHICAL REPRESENTATION

Make we check our correlation for graph make e give us visual look. No be everytime coding, make we enjoy pictures small…. How we go take bring graph to this matter? E get one Python Layer AKA Library wey dem dey call SEABORN. Na hin dey help us plot graph. Make we try am, so “blood of fish no go stain our body….as we no get Omo.”

import seaborn as sns

You don already know meaning of import nau. NEXT, make we see something for graph:

sns.lmplot(x=’athletes’,y=’medals’,data=teams,fit_reg=True, ci=None)

This one mean say, seaborn o (sns), show me your lines/cursor (lmplot) such that x-axis go be athlete and y axis go be medals. The name of the dataset wey you go use na teams. Fit_reg=True means say make e give us nice Regression Line and ci=None mean say “no give us anything above the line o, ehn ehn. Just do jeje.”

See result in Fig 3 above.

Watch out for the continuation. Please smash the like button on this post and don’t forget to share on all your social media ❤

Video and Project Credit: DataQuest

Visited 121 times, 1 visit(s) today

Leave A Comment

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