You are on page 1of 12

Diploma all branch projects avilable….contact now… sahidshaikh850@gmail.

com

Instagram fake
account detection

That provided code utilizes artificial intelligence (AI) techniques, specifically deep learning, to predict
the authenticity of Instagram profiles. Here's how AI is used in the code:

1. Deep Learning Model The code uses TensorFlow and Keras, which are libraries for building deep
learning models. Specifically, it constructs a deep neural network (DNN) model using the Sequential
API from Keras. Deep learning is a subset of AI that involves training neural networks to learn
patterns and make predictions from data.

2. Model Training: The deep learning model is trained on a dataset containing features of Instagram
profiles and their corresponding labels (indicating whether they are fake or not). During training,
the model learns the underlying patterns in the data, enabling it to make predictions on new,
unseen data.

3. Prediction: Once the model is trained, it is used to predict the authenticity of new Instagram
profiles. Users input various features of an Instagram profile into the GUI, and the trained
model predicts whether the profile is likely to be fake or not based on these features. This
prediction process is driven by the AI model's learned patterns and decision-making
capabilities.

Overall, the code employs AI techniques, specifically deep learning, to develop a predictive model for
detecting fake Instagram profiles.

1. Importing Libraries: The script imports necessary libraries including pandas, numpy, scikit-
learn, TensorFlow, Tkinter, and PIL (Python Imaging Library).

2. Data Preprocessing: The training data is loaded from a CSV file named insta_train.csv. It
preprocesses the data by splitting it into features (X_train) and target labels (y_train). It then scales
the features using StandardScaler.

3. Model Building and Training: A deep learning model is constructed using Keras Sequential API. It
consists of several dense layers with ReLU activation functions and dropout layers for
regularization.
Diploma all branch projects mehidid850@gmail.com
Diploma all branch projects avilable….contact now… sahidshaikh850@gmail.com

The model is compiled with Adam optimizer and categorical cross-entropy loss function. It is trained
on the preprocessed training data for 50 epochs.

4. GUI Setup: A Tkinter window is created for the GUI. The background image is loaded and
displayed using PIL and Tkinter. Entry fields are created for users to input the features of an
Instagram profile
they want to predict.

5. Prediction Function: There's a function named predict_instagram_profile() that collects user


inputs from the GUI entry fields, converts them into a DataFrame, scales them, and then uses the
trained model to predict whether the provided Instagram profile is fake or not. The prediction result
is displayed using a message box.

6. GUI Widgets: Entry fields are created for each feature, allowing users to input the relevant data.
A "Predict" button triggers the prediction function when clicked.

7. Main Loop: The Tkinter main loop (root.mainloop()) is initiated to keep the GUI running
and responsive to user interactions.

import pandas as pd

import numpy as np

from sklearn.preprocessing import StandardScaler

from tensorflow.keras.models import Sequential

from tensorflow.keras.layers import Dense, Dropout

import tkinter as tk

from tkinter import ttk

from tkinter import

messagebox import tensorflow

as tf

from PIL import Image, ImageTk

Absolutely, let's break down the code line by line:

```python

import pandas as pd

import numpy as np

from sklearn.preprocessing import StandardScaler

from tensorflow.keras.models import Sequential

from tensorflow.keras.layers import Dense, Dropout

import tkinter as tk

from tkinter import ttk


Diploma all branch projects mehidid850@gmail.com
Diploma all branch projects avilable….contact now… sahidshaikh850@gmail.com

from tkinter import

messagebox import tensorflow

as tf

from PIL import Image, ImageTk

```

1. `import pandas as pd`: Imports the pandas library with the alias pd.

2. `import numpy as np`: Imports the numpy library with the alias np.

3. `from sklearn.preprocessing import StandardScaler`: Imports the StandardScaler class from


the preprocessing module of scikit-learn.

4. `from tensorflow.keras.models import Sequential`: Imports the Sequential class from the
models module of TensorFlow's Keras API.

5. `from tensorflow.keras.layers import Dense, Dropout`: Imports the Dense and Dropout
classes from the layers module of TensorFlow's Keras API.

6. `import tkinter as tk`: Imports the tkinter library with the alias tk, used for building GUIs.

7. `from tkinter import ttk`: Imports ttk (themed tk) module from tkinter, used for creating
themed widgets.

8. `from tkinter import messagebox`: Imports the messagebox module from tkinter, used
for displaying message boxes.

9. `import tensorflow as tf`: Imports TensorFlow library with the alias tf.

10. `from PIL import Image, ImageTk`: Imports the Image and ImageTk modules from the
PIL (Python Imaging Library).

The code provided uses several technologies and libraries for different purposes. Here's a
breakdown of the technologies used:

1. Python: The core programming language used for developing the entire script.

2. Pandas: A powerful data manipulation library in Python used for data analysis and manipulation.
It is used here for loading and preprocessing the training data.

3. NumPy: A fundamental package for scientific computing with Python, used for
numerical operations and array manipulation.

Diploma all branch projects mehidid850@gmail.com


Diploma all branch projects avilable….contact now… sahidshaikh850@gmail.com

4. Scikit-learn: A machine learning library in Python that provides simple and efficient tools for
data mining and data analysis. It is used here for preprocessing the data and scaling features using
StandardScaler.

5. TensorFlow: An open-source deep learning library developed by Google used for building and
training neural network models. The Keras API within TensorFlow is used to build and train the deep
learning model for predicting Instagram profiles.

6. Tkinter: The standard GUI (Graphical User Interface) toolkit included with Python, used
for creating the GUI window, widgets, and event handling.

7. PIL (Python Imaging Library): A library for adding image processing capabilities to Python. It
is used here for loading and displaying background images in the Tkinter GUI.

These technologies work together to create a machine learning model for predicting
the authenticity of Instagram profiles, integrated into a user-friendly GUI using Tkinter.

code line by line, explaining the purpose and functionality of each line:

```python
import pandas as pd
```
This line imports the pandas library and gives it an alias `pd`, which is commonly used for data
manipulation and analysis.

Diploma all branch projects mehidid850@gmail.com


Diploma all branch projects avilable….contact now… sahidshaikh850@gmail.com

```python
import numpy as np
```
This line imports the numpy library and gives it an alias `np`, which is used for numerical
computing and array operations
```python
from sklearn.preprocessing import StandardScaler
```
This line imports the `StandardScaler` class from the `preprocessing` module of the scikit-learn
library. The `StandardScaler` is used for standardizing features by removing the mean and scaling to
unit variance.
```python
from tensorflow.keras.models import Sequential
```
This line imports the `Sequential` class from the `models` module of the TensorFlow Keras API.
`Sequential` is a linear stack of layers used for building deep learning models.
```python
from tensorflow.keras.layers import Dense, Dropout
```
This
```python
import tkinter as tk
This line imports the `tkinter` library, which is the standard GUI (Graphical User Interface) toolkit for
Python.
from tkinter import ttk
This line imports the `ttk` module from `tkinter`, which provides themed widget classes for creating
GUI applications.
from tkinter import messagebox
This line imports the `messagebox` module from `tkinter`, which is used to display message boxes in
the GUI.
import tensorflow as tf
This line imports the TensorFlow library with the alias `tf`, which is an open-source deep learning
framework developed by Google.
from PIL import Image, ImageTk
This line imports the `Image` and `ImageTk` modules from the Python Imaging Library (PIL), which
are used for handling images in various formats.

Diploma all branch projects mehidid850@gmail.com


Diploma all branch projects avilable….contact now… sahidshaikh850@gmail.com

These lines at the beginning of the script import all the necessary libraries and modules required for
data preprocessing, model building, GUI development, and image handling.

```python
# Function to predict Instagram profile
def predict_instagram_profile():
# Create dictionary to store user input
data = {}
```
This defines a function named `predict_instagram_profile()` that will be used to predict whether an
Instagram profile is fake or not. It initializes an empty dictionary `data` to store user input for various
features of the Instagram profile.
```python
# Prompt user for input for each feature
for feature in ['profile pic', 'nums/length username', 'fullname words', 'nums/length fullname',
'name==username',
'description length', 'external URL', 'private', '#posts', '#followers', '#follows']:
data[feature] = float(entries[feature].get())
```
This loop iterates over a list of features of an Instagram profile. For each feature, it retrieves the user
input from the corresponding entry field in the GUI (`entries`) and converts it to a float before
storing it in the `data` dictionary.
```python
# Convert dictionary to DataFrame
user_data = pd.DataFrame([data])
```This line converts the `data` dictionary into a pandas DataFrame called `user_data`.
```python
# Convert numeric columns to numeric, ignoring non-numeric values
user_data = user_data.apply(pd.to_numeric, errors='ignore')
```
This line converts the columns of the `user_data` DataFrame to numeric data types, ignoring non-
numeric values.
```python

Diploma all branch projects mehidid850@gmail.com


Diploma all branch projects avilable….contact now… sahidshaikh850@gmail.com

# Scaling user data


user_data_scaled = scaler.transform(user_data)
```
This line scales the user data using the `scaler` object, which was previously fitted to the training
data.

```python
# Predict user data
user_pred = model.predict(user_data_scaled)
user_pred_label = "Fake" if np.argmax(user_pred) == 1 else "Not Fake"
messagebox.showinfo("Prediction", f"The provided Instagram profile is likely
{user_pred_label}.")
```
This section predicts the authenticity of the provided Instagram profile. It uses the trained deep
learning model (`model`) to predict the class label for the user data. The prediction result is displayed
in a message box indicating whether the profile is likely to be fake or not.
The subsequent lines of code load the training dataset, preprocess the data, build and train the deep
learning model, set up the GUI, create input fields for each feature, and define a "Predict" button
that triggers the prediction function when clicked.

This function `predict_instagram_profile()` is used to predict whether an Instagram profile is fake


or not. It collects user input for various features of the profile, converts it into a DataFrame, scales
the data, predicts the authenticity using the trained model, and displays the prediction result in a
message box.

```python
# Load the training dataset
instagram_df_train = pd.read_csv(r'D:\finfake\Fake-Instagram-Profile-Detection-main - Copy (3) -
Copy\insta_train.csv')
```
This line loads the training dataset from a CSV file using pandas.

```python
# Preparing Data to Train the Model

Diploma all branch projects mehidid850@gmail.com


Diploma all branch projects avilable….contact now… sahidshaikh850@gmail.com

# Training dataset (inputs)


X_train = instagram_df_train.drop(columns=['fake'])

# Training dataset (Outputs)


y_train = instagram_df_train['fake']

# Scaling the data before training the model


scaler = StandardScaler()
X_train_scaled = scaler.fit_transform(X_train)
y_train = tf.keras.utils.to_categorical(y_train, num_classes=2)
```
These lines prepare the training data for the model. It separates the features (X_train) and target
labels (y_train), scales the features using StandardScaler, and converts the target labels into
categorical format using TensorFlow's `to_categorical()` function.

```python
# Building and Training Deep Learning Model
model = Sequential([
Dense(50, input_dim=11, activation='relu'),
Dense(150, activation='relu'),
Dropout(0.3),
Dense(150, activation='relu'),
Dropout(0.3),
Dense(25, activation='relu'),
Dropout(0.3),
Dense(2, activation='softmax')
])

model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])

epochs_hist = model.fit(X_train_scaled, y_train, epochs=50, verbose=1, validation_split=0.1)


```
These lines build and train the deep learning model using TensorFlow's Keras API. The model consists
of several dense layers with ReLU activation functions and dropout layers for regularization. It's

Diploma all branch projects mehidid850@gmail.com


Diploma all branch projects avilable….contact now… sahidshaikh850@gmail.com

compiled with the Adam optimizer and categorical cross-entropy loss function, and then trained on
the preprocessed training data for 50 epochs.

```python
# GUI Setup
root =
tk.Tk()
root.title("Fake Instagram Profile Detection")
root.geometry("400x400")

# Load and display background image


background_image = Image.open(r'C:\final_year_project\images\4444444444444444.jpg')
background_photo = ImageTk.PhotoImage(background_image)
background_label = tk.Label(root, image=background_photo)
background_label.place(relwidth=1, relheight=1)

# Create input fields for each feature


entries = {}
for i, feature in enumerate(['profile pic', 'nums/length username', 'fullname words', 'nums/length
fullname', 'name==username',
'description length', 'external URL', 'private', '#posts', '#followers', '#follows']):
label = ttk.Label(root, text=feature)
label.grid(row=i, column=0, padx=10, pady=5)
entry = ttk.Entry(root)
entry.grid(row=i, column=1, padx=10, pady=5)
entries[feature] = entry

# Button to predict
predict_button = ttk.Button(root, text="Predict", command=predict_instagram_profile)
predict_button.grid(row=11, column=0, columnspan=2, pady=10)

root.mainloop()
```
These lines set up the GUI using Tkinter. It creates a window with a title "Fake Instagram Profile
Detection" and size 400x400. It loads and displays a background image. It creates input fields for

Diploma all branch projects mehidid850@gmail.com


Diploma all branch projects avilable….contact now… sahidshaikh850@gmail.com

each feature of an Instagram profile, and a "Predict" button that triggers the
`predict_instagram_profile()` function when clicked. Finally, it starts the Tkinter main loop to run the
GUI application.

Diploma all branch projects mehidid850@gmail.com

You might also like