Friday, November 15, 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

Just ₹10 You Can Buy Online Courses

You Can Buy Online Courses With Just ₹10 – Learn New Skills at an Affordable Price! What if you could learn new technology skills without sp...