Instagram Algorithm with Machine Learning

Predicting the reach of Instagram posts is one of the most important tasks for every business that relies heavily on social media customers. So in such competition, it is very important to know how the Instagram algorithm works. In this article, I’m going to walk you through an implementation of the Instagram algorithm with Machine Learning using Python to understand how your posts can get more reach on Instagram.

How Instagram Algorithm Works?

What people see in their Instagram posts and stories depends on a combination of the user behaviour they display in most of the content they see. The most important characteristics that contribute to the reach of your Instagram posts are the type of posts people interact with, the type of posts they like and engage in discussion.

Also, Read – 100+ Machine Learning Projects Solved and Explained.

When Instagram’s algorithm receives a positive signal according to the above features in your posts, the algorithm gives more opportunities for your post to gain greater reach among your audience.

So now I hope you have an idea of how the Instagram algorithm works. But how to implement it with Machine Learning? In the section below, I’ll walk you through how to implement the Instagram algorithm with Machine Learning using Python.

Instagram Algorithm with Machine Learning

Based on how the Instagram algorithm works, we figured out that when a user has more followers, then the post is more likely to get more likes and engagement to reach more audience.

So we need to identify a linear relationship in the data and build a machine learning algorithm based on the relationship we find in the data to implement the Instagram algorithm with Machine Learning.

For this task, I will be using a dataset with around 100 rows and 6 features containing information on usernames, post captions, followers, hashtags, time since posted, and likes. So I’m going to train a machine learning model to predict the likes of an item.

Implementing Instagram Algorithm using Python

Now let’s start with the task of implementing an Instagram algorithm with Machine Learning using Python. I’ll start by importing the dataset:

import pandas as pd
data = pd.read_csv("instagram_reach.csv")
Instagram dataset
data.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 100 entries, 0 to 99
Data columns (total 8 columns):
 #   Column             Non-Null Count  Dtype 
---  ------             --------------  ----- 
 0   Unnamed: 0         100 non-null    int64 
 1   S.No               100 non-null    int64 
 2   USERNAME           100 non-null    object
 3   Caption            94 non-null     object
 4   Followers          100 non-null    int64 
 5   Hashtags           100 non-null    object
 6   Time since posted  100 non-null    int64 
 7   Likes              100 non-null    int64 
dtypes: int64(5), object(3)
memory usage: 6.4+ KB

Now let’s import some other Python libraries and prepare a function to examine the word cloud to understand the maximum type of words used in Instagram captions and hashtags:

word cloud Instagram dataset
WordCloudPlotter('Hashtags')
Instagram algorithm

Now let’s understand the number of likes we get based on the number of followers we have and the time elapsed since our post:

Instagram algorithm with machine learning

Now I’m going to train a simple model to predict the target value which is “likes” with the combination of followers and time since post:

Max value of target is 349.0

Training Model:

Now let’s train the Instagram algorithm with Python:

GradientBoostingRegressor(alpha=0.9, ccp_alpha=0.0, criterion='friedman_mse',
                          init=None, learning_rate=0.1, loss='ls', max_depth=3,
                          max_features=None, max_leaf_nodes=None,
                          min_impurity_decrease=0.0, min_impurity_split=None,
                          min_samples_leaf=1, min_samples_split=2,
                          min_weight_fraction_leaf=0.0, n_estimators=100,
                          n_iter_no_change=None, presort='deprecated',
                          random_state=None, subsample=1.0, tol=0.0001,
                          validation_fraction=0.1, verbose=0, warm_start=False)
Instagram algorithm linear relationship

So the machine learning model above looks good, now let’s implement it by framing the realtime cases:

predictions on 100 followers
# likes progression for 200 followers
PredictionsWithConstantFollowers(gbr, 200, stdSc, maxValLikes)
predictions on 200 followers
# Like progression for 1000 followers
PredictionsWithConstantFollowers(gbr, 1000, stdSc, maxValLikes)
the linear relationship of hours since posted

Conclusion

Based on the predictions above, we can observe one thing: if you have a higher number of subscribers, your post is more likely to get more likes in attendance for life. But the maximum likes will not increase more than 20 times the number of followers only contributes to an increase of about 20% in likes.

I hope you liked this article on how to implement the Instagram algorithm with Machine Learning using Python programming language. Feel free to ask your valuable questions in the comments section below.

Aman Kharwal
Aman Kharwal

I'm a writer and data scientist on a mission to educate others about the incredible power of data📈.

Articles: 1534

Leave a Reply