Hi, there 👋
<center></center>
<div class="text-justify">
<i>
Whether you are a programmer or not, if you have been using the internet for a while you may have know or have already realized that the <code><b>future is of Artificial Intelligence</b></code>. AI has already started being an integral part of human society. From the smartphones, we use to watch AI recommended youtube videos to the car we drive to our offices most of the things(gadget) surrounding us is probably using AI. So me being a programmer, I thought why not make a small tutorial you guys can try that use AI or <code><b>more specifically Machine Learning</b></code> as far as this article is concerned. Before I begin this tutorial I would like to remind you that for this tutorial, you need to have <code><b>basic knowledge of python programming language</b></code> and I assure you will be very surprised to see how easy it is <code><b>to build a basic machine learning program in python</b></code>. So what are we waiting for let's get started my friends, shall we? 😉
# <center><code><b>🔹*Software Requirements*🔹</b></code></center>
🔹 <code><b>[Python 3](https://www.python.org/downloads/)</b></code>
🔹 [PIP](https://bootstrap.pypa.io/get-pip.py) <code><b>python get-pip.py</b></code>
# <center><code><b>🔹*Our Data*🔹</b></code></center>
<br>
For this tutorial <code><b>we will need to get user's follower list</b></code> which we can either get <code><b>directly from the steem blockchain</b></code> by preparing some separate code but, I don't want to get into the details of querying the steem blockchain with python as that will be a whole new tutorial itself, so <code><b>we will directly pick the data from this [site](https://steem.makerwannabe.com/) </b></code> with a little bit of webscraping.
This [site](https://steem.makerwannabe.com/) doesn't return data prior to 1<sup>st</sup> Jan 2018 but that should be much of a problem most of the time and we will start numbering days from 1<sup>st</sup> Jan 2018. That is to say as 1<sup>st</sup> Jan will be Day 1, 2<sup>nd</sup> Jan will be Day 2 and so on.. First of all we will see how our data looks on graph. In order to do so we will do a scatter plot of our data points and for that <code><b>we need the Matplotlib library</b></code> which you can install by executing the below line on your cmd/terminal.
<center><code><b>pip install matplotlib</b></code></center>
<center><code><b>🔹Code to plot the data as scatter plot🔹</b></code></center>
~~~~
#importing matplotlib library
import matplotlib.pyplot as plot
days_arr = [[5], [10], [15], [20], [25], [30], [35], [40], [45], [50], [55], [60], [65], [70], [75], [80], [85], [90], [95], [100], [105], [110], [115], [120], [125], [130], [135], [140], [145], [150], [155], [160], [165], [170], [175], [180], [185], [190], [195], [200], [205], [210], [215], [220], [225], [230], [235], [240], [245], [250]]
# followers array is an array of the cumulative sum of followers
followers = [286, 416, 709, 952, 1231, 1554, 1777, 2024, 2299, 2463, 2644, 2803, 2986, 3099, 3312, 3410, 3577, 3736, 3854, 4020, 4118, 4258, 4392, 4474, 4580, 4699, 4824, 5018, 5243, 5351, 5558, 5744, 5815, 5872, 6006, 6088, 6244, 6379, 6469, 6559, 6656, 6753, 6830, 6896, 6959, 7056, 7124, 7150, 7208, 7372]
plot.scatter(days, followers, color='red', s=3, alpha=1.0)
# X-axis label
plot.xlabel('Day')
# Y-axis label
plot.ylabel('Steemit Followers')
~~~~
<center><code><b>🔹Output🔹</b></code></center>
<center></center>
# <center><code><b>🔹*Algorithm*🔹</b></code></center>
<br>
🔹 <code><b>[Linear Regression](https://www.python.org/downloads/)</b></code> - Since we can visualize form the scatter plot above that the <code><b>data is somewhat linear</b></code>, so we <code><b>for the sake of this tutorial we will use Linear Regression algorithm</b></code> to find a line that passes through some of the points on the plot such that the <code><b>loss function is minimum</b></code> or to say line that best fits all the data points such that error is minimum.
<center></center>
To apply the algorithm to our data we will use a popular <code><b>machine learning python library called Scikit Learn</b></code>. To install the library copy the below command onto your cmd 💻 and hit enter.
<center><code><b>pip install scikit-learn</b></code></center>
<center><code><b>🔹Final code to find the line of best fit🔹</b></code></center>
~~~~
#importing the linear model from scikit learn
from sklearn import linear_model
#importing matplotlib library
import matplotlib.pyplot as plot
import numpy as np
days = [[5], [10], [15], [20], [25], [30], [35], [40], [45], [50], [55], [60], [65], [70], [75], [80], [85], [90], [95], [100], [105], [110], [115], [120], [125], [130], [135], [140], [145], [150], [155], [160], [165], [170], [175], [180], [185], [190], [195], [200], [205], [210], [215], [220], [225], [230], [235], [240], [245], [250]]
followers = [286, 416, 709, 952, 1231, 1554, 1777, 2024, 2299, 2463, 2644, 2803, 2986, 3099, 3312, 3410, 3577, 3736, 3854, 4020, 4118, 4258, 4392, 4474, 4580, 4699, 4824, 5018, 5243, 5351, 5558, 5744, 5815, 5872, 6006, 6088, 6244, 6379, 6469, 6559, 6656, 6753, 6830, 6896, 6959, 7056, 7124, 7150, 7208, 7372]
plot.scatter(days, followers, color='red', s=3, alpha=1.0)
plot.xlabel('Day')
plot.ylabel('Steemit Followers')
linear_regression_classifier = linear_model.LinearRegression()
# fit a line such that error is minimum
linear_regression_classifier = linear_regression_classifier.fit(days, followers)
# predict the no. of followers on Day 23, Day 301 and Day 323
model_prediction = linear_regression_classifier.predict([[23], [301], [323]])
#plot the line of best fit
plot.plot([[23], [301], [323]], model_prediction, color='black', linewidth=1)
# print the predicted result on terminal
print(np.floor(model_prediction))
#Output the plot
plot.show()
~~~~
<center><code><b>🔹Output🔹</b></code></center>
<code>💻Terminal output</code> - <code><b> [ 1261. 9357. 9974.] </b></code>which is nothing but predicted no. of followers on <code><b>Day 23</b></code>, <code><b>Day 301</b></code> and <code><b>Day 323</b></code> respectively.
<center></center>
<code><b>⚠️Note</b></code> - This algorithm performs best only for linear data, if your data seems to be non-linear than it won't perform good. In that case, we have to implement other algorithms.
<center>✌️ <code><b>FOLLOW</b></code>, <code><b>UPVOTE</b></code> or <code><b>RESTEEM</b></code> maybe if you like.</center>
<center>✍️ <code><b>+VE</b></code> comments are welcome ❤️</center>
</i></div>
<center></center>