create account

🔰Machine learning python tutorial - Predict the no. of steemit followers of a user using basic Linear Regression by pankajborah

View this thread on: hive.blogpeakd.comecency.com
· @pankajborah · (edited)
$1.81
🔰Machine learning python tutorial - Predict the no. of steemit followers of a user using basic Linear Regression
Hi, there 👋

<center>![pankaj_infogrphics.gif](https://cdn.steemitimages.com/DQmcVCBqZy3bhickqDKvy5Nzmw18x7ECAeZXdnPJuSx7GMU/pankaj_infogrphics.gif)</center>

<div class="text-justify">
<i>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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. 

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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>![Figure_2.png](https://cdn.steemitimages.com/DQmf372EB19RA7r8WqZqhBGYc39JyLrAvuFVRPkg2y6bkdF/Figure_2.png)</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>![math_pankaj.jpg](https://cdn.steemitimages.com/DQmStdZuKR5ZCPw7owS9X9BYCHx2bUZZsSZBX2K97HruK2o/math_pankaj.jpg)</center>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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>![final_output.png](https://cdn.steemitimages.com/DQmU7j6WaAmfrnzKUD9kkoGGkLbbAAK9LbUmn9XpFqAfEVP/final_output.png)</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>![resteem.gif](https://cdn.steemitimages.com/DQmRwsgA2fANyiaUQMLGvAuy7LsJ7oyhRC55Xkyb9pj3axV/resteem.gif)</center>
👍  , , , , , , , , , , , , ,
properties (23)
authorpankajborah
permlinkmachine-learning-python-tutorial-predict-the-no-of-steemit-followers-of-a-user-using-basic-linear-regression
categoryutopian-io
json_metadata{"tags":["utopian-io","machine-learning","python","programming","gsindia"],"image":["https://cdn.steemitimages.com/DQmcVCBqZy3bhickqDKvy5Nzmw18x7ECAeZXdnPJuSx7GMU/pankaj_infogrphics.gif","https://cdn.steemitimages.com/DQmf372EB19RA7r8WqZqhBGYc39JyLrAvuFVRPkg2y6bkdF/Figure_2.png","https://cdn.steemitimages.com/DQmStdZuKR5ZCPw7owS9X9BYCHx2bUZZsSZBX2K97HruK2o/math_pankaj.jpg","https://cdn.steemitimages.com/DQmU7j6WaAmfrnzKUD9kkoGGkLbbAAK9LbUmn9XpFqAfEVP/final_output.png","https://cdn.steemitimages.com/DQmRwsgA2fANyiaUQMLGvAuy7LsJ7oyhRC55Xkyb9pj3axV/resteem.gif"],"links":["https://www.python.org/downloads/","https://bootstrap.pypa.io/get-pip.py","https://steem.makerwannabe.com/"],"app":"steemit/0.1","format":"markdown"}
created2018-09-18 06:15:30
last_update2018-09-18 12:00:21
depth0
children3
last_payout2018-09-25 06:15:30
cashout_time1969-12-31 23:59:59
total_payout_value1.383 HBD
curator_payout_value0.431 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length7,790
author_reputation405,243,319,324
root_title"🔰Machine learning python tutorial - Predict the no. of steemit followers of a user using basic Linear Regression"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id71,554,527
net_rshares1,364,636,230,936
author_curate_reward""
vote details (14)
@crypto.piotr ·
Hi @pankajborah

Just accidently bumped into your profile just to realize that we seem to share a number of interests :)

In particular that we both share a similar passion towards cryptocurrencies and blockchain technology :)

Are you still around? your last post is like 1 month old.

I will follow you closely :) big fat upvote on the way! :)
Yours, Piotr
properties (22)
authorcrypto.piotr
permlinkre-pankajborah-machine-learning-python-tutorial-predict-the-no-of-steemit-followers-of-a-user-using-basic-linear-regression-20181028t072833794z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"users":["pankajborah"],"app":"steemit/0.1"}
created2018-10-28 07:28:27
last_update2018-10-28 07:28:27
depth1
children0
last_payout2018-11-04 07:28:27
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length358
author_reputation27,396,789,428,606
root_title"🔰Machine learning python tutorial - Predict the no. of steemit followers of a user using basic Linear Regression"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id74,196,778
net_rshares0
@thesimpson ·
Is that really machine learning? Just seemed like installing some python libraries and plotting a graph.... Interesting and useful none the less.
👍  
properties (23)
authorthesimpson
permlinkre-pankajborah-machine-learning-python-tutorial-predict-the-no-of-steemit-followers-of-a-user-using-basic-linear-regression-20180921t153712724z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-09-21 15:37:15
last_update2018-09-21 15:37:15
depth1
children1
last_payout2018-09-28 15:37:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length145
author_reputation6,326,307,749,037
root_title"🔰Machine learning python tutorial - Predict the no. of steemit followers of a user using basic Linear Regression"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id71,867,737
net_rshares661,490,780
author_curate_reward""
vote details (1)
@pankajborah · (edited)
I'm glad you liked it. Yes, it is in fact very basic machine learning algorithm( Linear Regression). It's not necessary to use any library at all, for learning purpose you we can just implement the whole mathematical algorithm(as shown above) all by ourself in python, but why reinvent the wheel, after all we will get the same result at the end.😉
properties (22)
authorpankajborah
permlinkre-thesimpson-re-pankajborah-machine-learning-python-tutorial-predict-the-no-of-steemit-followers-of-a-user-using-basic-linear-regression-20180921t154947294z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-09-21 15:49:57
last_update2018-09-21 15:54:09
depth2
children0
last_payout2018-09-28 15:49:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length347
author_reputation405,243,319,324
root_title"🔰Machine learning python tutorial - Predict the no. of steemit followers of a user using basic Linear Regression"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id71,868,805
net_rshares0