Thursday, November 14, 2024

Ad Click Prediction Using Logistic Regression

 

Ad Click Prediction Using Logistic Regression


INTRODUCTION:

Logistic regression is a data analysis technique that uses mathematics to find the relationships between two data factors. It then uses this relationship to predict the value of one of those factors based on the other. The prediction usually has a finite number of outcomes, like yes or no.

CODE 😃👇:

# Import necessary libraries
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score, classification_report, confusion_matrix
from sklearn.preprocessing import StandardScaler

# Load the dataset
# Replace ‘path_to_csv’ with the actual file path
df = pd.read_csv(‘/content/advertising.csv’)

# Display the first few rows of the dataset
print(“Dataset Preview:\n”, df.head())

# Select relevant features and the target variable
# Dropping columns that are not directly useful for prediction
df = df[[‘Daily Time Spent on Site’, ‘Age’, ‘Area Income’, ‘Daily Internet Usage’, ‘Male’, ‘Clicked on Ad’]]

# Separate the features (X) and target variable (y)
X = df.drop(“Clicked on Ad”, axis=1)
y = df[“Clicked on Ad”]

# Split the data into training and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Standardize the feature values
scaler = StandardScaler()
X_train = scaler.fit_transform(X_train)
X_test = scaler.transform(X_test)

# Initialize and train the Logistic Regression model
log_reg_model = LogisticRegression()
log_reg_model.fit(X_train, y_train)

# Make predictions on the test set
y_pred = log_reg_model.predict(X_test)

# Evaluate the model
accuracy = accuracy_score(y_test, y_pred)
print(“\nAccuracy of the Logistic Regression model:”, accuracy)
print(“\nClassification Report:\n”, classification_report(y_test, y_pred))
print(“\nConfusion Matrix:\n”, confusion_matrix(y_test, y_pred))

DATASET LINK 😃👇:


https://www.kaggle.com/datasets/marius2303/ad-click-prediction-dataset


SUPPORT ME 😟

FREE C++ SKILLSHARE COURSE

https://skl.sh/3AUpE4C


FREE C SKILLSHARE COURSE

https://skl.sh/3Ynolmw


All Courses 😃👇

https://linktr.ee/Freetech2024


All Products 😃👇

https://linktr.ee/rockstararun


HP Laptop 🤩👇

https://dir.indiamart.com/impcat/hp-laptop.html?utm_source=freetech-xu1ob&utm_medium=affiliate&utm_campaign=1024&utm_content=29&mTd=1

Asus Laptop 🤩👇

https://www.indiamart.com/proddetail/24957009948.html?utm_source=freetech-xu1ob&utm_medium=affiliate&utm_campaign=1024&utm_content=43&mTd=1


No comments:

Post a Comment

SQL INJECTION DETECTION USING RANDOM FOREST CLASSIFIER

  SQL INJECTION DETECTION USING RANDOM FOREST CLASSIFIER