This project demonstrates how to use logistic regression to predict whether a user will click on an online advertisement. The model is built and evaluated using Python and popular data science libraries.
Given a user's demographic and behavioral features, the model predicts the likelihood of an ad click (Clicked on Ad
: 1 = Clicked, 0 = Not Clicked).
Daily Time Spent on Site
: Minutes user spends daily on the websiteAge
: Age of the userArea Income
: Average income of the user's geographic areaDaily Internet Usage
: Average minutes per day user spends on the internetAd Topic Line
: Headline of the advertisementCity
: User's cityMale
: 1 if user is male, 0 otherwiseCountry
: User's countryTimestamp
: Time when user clicked or closed the adClicked on Ad
: Target variable (1 if clicked, 0 if not)
-
Data Loading & Exploration
- Import required libraries
- Load the dataset (
advertising.csv
) - Explore data types and summary statistics
- Visualize distributions and feature relationships
-
Data Preparation
- Select relevant features
- Split data into training and test sets
-
Model Building
- Train a logistic regression model using scikit-learn
-
Evaluation
- Predict on the test set
- Evaluate using classification metrics (precision, recall, f1-score, accuracy)
precision recall f1-score support
0 0.87 0.96 0.91 162
1 0.96 0.86 0.91 168
avg / total 0.91 0.91 0.91 330
- Distribution of user ages
- Joint plots of features (e.g., Area Income vs Age, Daily Time Spent on Site vs Age)
- Pair plots colored by ad click outcome
You can run this project locally or on Google Colab:
-
Clone the repository or upload the notebook to Colab
-
Upload the
advertising.csv
dataset- To Colab: Use the file upload feature or
from google.colab import files; files.upload()
- To Colab: Use the file upload feature or
-
Install dependencies (if needed)
!pip install pandas numpy matplotlib seaborn scikit-learn
-
Run all cells in the notebook
Logistic Regression Project.ipynb
β Main notebookadvertising.csv
β Dataset (make sure it is in the same directory or uploaded in Colab)
- Dataset and project structure inspired by typical machine learning course exercises.
For questions or improvements, feel free to open an issue or pull request!