Machine learning in python ..

Python is predominantly used for Artificial Intelligence ...
Data science combines the scientific method, math and statistics, specialized programming, advanced analytics, AI, and even storytelling to uncover and explain the business insights buried in data.
And Machine learning is one of the types of Data Science ..

Here we are going to look how to create a very basic Machine Learning Model that predicts the human population in the upcoming years ..

In your terminal ...

pip install numpy
pip install pandas
pip install matplotlib
pip install scikit-learn
 
The code ..

# importing the modules
import pandas as pd            
import matplotlib.pyplot as plt
# reading the excel file of population.xlsx
data=pd.read_excel('population.xlsx')    
print(data)
x=data.year
y=data.population
plt.plot(x,y)
plt.show()


The excel file looks like this ...

Year Population
1950 2,53,64,31,149
1955 2,77,30,19,936
1960 3,03,49,49,748
1965 3,33,95,83,597
1970 3,70,04,37,046
1975 4,07,94,80,606
1980 4,45,80,03,514
1985 4,87,09,21,740
1990 5,32,72,31,061
1995 5,74,42,12,979
2000 6,14,34,93,823
2005 6,54,19,07,027
2010 6,95,68,23,603
2015 7,37,97,97,139
2020 7,79,47,98,739

And the output looks like this ...

    Year  Population
0   1950  2536431149
1   1955  2773019936
2   1960  3034949748
3   1965  3339583597
4   1970  3700437046
5   1975  4079480606
6   1980  4458003514
7   1985  4870921740
8   1990  5327231061
9   1995  5744212979
10  2000  6143493823
11  2005  6541907027
12  2010  6956823603
13  2015  7379797139
14  2020  7794798739















And the machine learning model looks like this ...

The code ...

# importing the modules
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
# reading the data
data=pd.read_excel('population.xlsx')
# setting up the mode 
model=LinearRegression()
# the year which we are going to predict
year=2030
# fitting the model to data structure .
model.fit(data[['Year']],data[['Population']])
# predicting the population in the year
prediction=model.predict([[  year  ]])  
# converting that to an integer
prediction_population=int(prediction)
# printing ..
print(f'population prediction in {year} is {prediction_population}')

And the output ...

population prediction in 2030 is 8462888938  

A very interesting thing to note that our prediction predicts that there are going to be 8.46 billion people on Earth ...
And the United Nation predicts there are going to be 8.5 billion ..

(https://www.un.org/sustainabledevelopment/blog/2015/07/un-projects-world-population-to-reach-8-5-billion-by-2030-driven-by-growth-in-developing-countries/#:~:text=The%20world%E2%80%99s%20population%20is%20projected%20to%20reach%208.5,to%20a%20new%20United%20Nations%20report%20released%20today.)

So yeah we predicted it correct to some extent ...

A note ....

The model doesn't take into account any other extra influences ....
.. like Earthquake ,wars ,Nuclear wars ,pandemic ,COVID ,Meteor strike ,flood and other catastrophic events ..

NO ONE COULD ACTUALLY PREDICT THOSE THINGS ...

Comments

Popular posts from this blog

News application in Python ..

PAINT PROGRAM IN PYTHON ..

2048 game in Python ..