This directory contains a trained Random Forest classifier for detecting bot accounts on Instagram.
The model was trained with balanced class weights to handle any class imbalance in the dataset.
The model uses 10 features to detect bot accounts. Top 5 most important features:
1import joblib
2import numpy as np
3
4# Load model and scaler
5model = joblib.load('instagram_bot_detection_v2.pkl')
6scaler = joblib.load('instagram_scaler_v2.pkl')
7
8# Example prediction
9features = np.array([[
10 1, # profile_pic
11 0.15, # username_num_ratio
12 0, # username_is_numeric
13 2, # fullname_words
14 0.0, # fullname_num_ratio
15 0, # is_name_number_only
16 0, # name_equals_username
17 1200, # followers
18 300, # follows
19 4.0 # followers_to_follows_ratio
20]])
21
22# Scale features
23features_scaled = scaler.transform(features)
24
25# Make prediction
26prediction = model.predict(features_scaled)
27probability = model.predict_proba(features_scaled)
28
29print(f"Bot: {prediction[0] == 1}")
30print(f"Probability: {probability[0][1]:.4f}")
1def predict_instagram_bot(account_data: dict) -> dict:
2 """
3 Predict if an Instagram account is a bot.
4
5 Args:
6 account_data: Dictionary with account features
7
8 Returns:
9 Dictionary with prediction and probability
10 """
11 features = np.array([[
12 account_data['profile_pic'],
13 account_data['username_num_ratio'],
14 account_data['username_is_numeric'],
15 account_data['fullname_words'],
16 account_data['fullname_num_ratio'],
17 account_data['is_name_number_only'],
18 account_data['name_equals_username'],
19 account_data['followers'],
20 account_data['follows'],
21 account_data['followers_to_follows_ratio']
22 ]])
23
24 features_scaled = scaler.transform(features)
25 prediction = model.predict(features_scaled)[0]
26 probability = model.predict_proba(features_scaled)[0]
27
28 return {
29 'is_bot': bool(prediction),
30 'bot_probability': float(probability[1]),
31 'confidence': float(max(probability))
32 }
1@misc{instagram-bot-detection-v2,
2 title={Instagram Bot Detection Model v2},
3 author={Nahiar},
4 year={2025},
5 month={November},
6 publisher={Hugging Face},
7 howpublished={\url{https://huggingface.co/nahiar/instagram-bot-detection}}
8}
For issues, improvements, or questions, please contact the model maintainer.