{"id":31649330,"url":"https://github.com/steffin12-git/logistic-regression-social-network-ads-ml","last_synced_at":"2026-05-03T10:35:20.316Z","repository":{"id":310157908,"uuid":"1038912319","full_name":"Steffin12-git/Logistic-Regression-social-network-ads-ML","owner":"Steffin12-git","description":"Built an interpretable Logistic Regression model to predict whether a user will purchase a product from social network ads using demographic and behavioral features. The notebook demonstrates a complete ML workflow — data ingestion, preprocessing, scaling, modeling, evaluation, and visual diagnostics.","archived":false,"fork":false,"pushed_at":"2025-08-16T04:44:22.000Z","size":115,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-16T06:28:31.309Z","etag":null,"topics":["matplotlib-pyplot","pandas","python","seaborn","sklearn","statistics"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Steffin12-git.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-16T04:21:54.000Z","updated_at":"2025-08-16T04:45:46.000Z","dependencies_parsed_at":"2025-08-16T06:28:34.404Z","dependency_job_id":"df5bb549-0d82-4fbb-bd36-7d3a88bde37b","html_url":"https://github.com/Steffin12-git/Logistic-Regression-social-network-ads-ML","commit_stats":null,"previous_names":["steffin12-git/logistic-regression-social-network-ads-ml"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/Steffin12-git/Logistic-Regression-social-network-ads-ML","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Steffin12-git%2FLogistic-Regression-social-network-ads-ML","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Steffin12-git%2FLogistic-Regression-social-network-ads-ML/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Steffin12-git%2FLogistic-Regression-social-network-ads-ML/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Steffin12-git%2FLogistic-Regression-social-network-ads-ML/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Steffin12-git","download_url":"https://codeload.github.com/Steffin12-git/Logistic-Regression-social-network-ads-ML/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Steffin12-git%2FLogistic-Regression-social-network-ads-ML/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278740831,"owners_count":26037480,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["matplotlib-pyplot","pandas","python","seaborn","sklearn","statistics"],"created_at":"2025-10-07T07:42:16.435Z","updated_at":"2025-10-07T07:42:23.359Z","avatar_url":"https://github.com/Steffin12-git.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 📣 Logistic Regression — Social Network Ads (Purchase Prediction)\n\n**Repository:** *Logistic Regression Social Network Ads*\n**Notebook:** `Logistic Regression Social network.ipynb`\n\n---\n\n## 🔎 TL;DR\n\nBuilt an interpretable **Logistic Regression** model to predict whether a user will purchase a product from social network ads using demographic and behavioral features. The notebook demonstrates a **complete ML workflow** — data ingestion, preprocessing, scaling, modeling, evaluation, and visual diagnostics.\n\n---\n\n## 📊 Key Results\n\n* **Dataset:** 400 rows, 5 columns (`User ID`, `Gender`, `Age`, `EstimatedSalary`, `Purchased`)\n\n* **Train/Test split:** 70% / 30% → **Train = 280**, **Test = 120**\n\n* **Model:** `sklearn.linear_model.LogisticRegression()` (default)\n\n* **Test set performance:**\n\n  * **Accuracy:** **0.86**\n  * **Classification report (test set):**\n\n    ```\n                  precision    recall  f1-score   support\n\n           0       0.83      0.97      0.89        73\n           1       0.94      0.68      0.79        47\n\n    accuracy                           0.86       120\n    macro avg       0.88      0.83      0.84       120\n    weighted avg    0.87      0.86      0.85       120\n    ```\n\n* **Confusion Matrix:**\n  ![Confusion Matrix](images/confusion%20metrics.png)\n\n* **ROC Curve (AUC \\~ 0.91):**\n  ![ROC Curve](images/Roc%20Curve.png)\n\n\u003e 📌 **Interpretation:**\n\u003e Model is very accurate at identifying non-purchasers (recall = 0.97), but misses \\~32% of actual purchasers (recall = 0.68). Depending on business goals, the decision threshold can be adjusted to improve recall.\n\n---\n\n## 📂 Dataset \u0026 Preprocessing\n\n* **Data file:** `Social_Network_Ads.csv`\n* **Features used (`X`):** `Gender`, `Age`, `EstimatedSalary`\n* **Target (`y`):** `Purchased`\n* **Steps performed:**\n\n  * Dropped `User ID`\n  * Encoded `Gender` (Male = 1, Female = 0)\n  * Standardized features using **StandardScaler**\n  * Train-test split (70% train, 30% test)\n\n```python\n# Encoding gender\ndf['Gender'] = df['Gender'].apply(lambda x: 1 if str(x).strip().lower() == \"male\" else 0)\n\n# Feature scaling\nscalar = StandardScaler()\nX_scaled = scalar.fit_transform(X)\n```\n\n---\n\n## 🧑‍💻 Model Training \u0026 Evaluation\n\n* **Logistic Regression model:**\n\n  ```python\n  lr = LogisticRegression()\n  lr.fit(X_train, y_train)\n  y_pred = lr.predict(X_test)\n  ```\n* **Evaluation metrics generated:**\n\n  * Accuracy score (0.86)\n  * Classification report (precision, recall, F1-score)\n  * Confusion matrix (visualized above)\n  * ROC Curve \u0026 AUC\n\n---\n\n## 📈 Insights \u0026 Business Relevance\n\n* ✅ **High precision for purchasers (0.94):** When the model predicts a purchase, it’s usually correct. Useful for **targeted campaigns** where false positives are costly.\n* ⚠️ **Lower recall for purchasers (0.68):** The model misses \\~32% of buyers. If the goal is **maximizing sales capture**, recall should be improved (via class weighting, resampling, or threshold tuning).\n* ⚡ **Lightweight \u0026 interpretable:** With only three predictors, this model is fast, explainable, and easy to deploy. Ideal for **marketing proof-of-concept**.\n\n---\n\n## 🧾 Reproducibility — How to Run\n\n1. Clone the repo and ensure the dataset `Social_Network_Ads.csv` is present.\n2. Install dependencies:\n\n   ```bash\n   pip install pandas seaborn matplotlib scikit-learn jupyter\n   ```\n3. Launch Jupyter and run the notebook:\n\n   ```bash\n   jupyter notebook \"Logistic Regression Social network.ipynb\"\n   ```\n4. To export plots for README:\n\n   ```python\n   plt.savefig(\"images/confusion metrics.png\", bbox_inches=\"tight\")\n   plt.savefig(\"images/Roc Curve.png\", bbox_inches=\"tight\")\n   ```\n\n---\n\n## 📁 Project Structure\n\n```\n├── Logistic Regression Social network.ipynb   # Main notebook\n├── Social_Network_Ads.csv                     # Dataset (400 rows)\n├── images/                                    # Visualization assets\n│   ├── confusion metrics.png\n│   └── Roc Curve.png\n└── README.md                                  # Documentation\n```\n\n---\n\n## 💡 Elevator Pitch\n\nDeveloped an **86% accurate Logistic Regression model** to predict purchase behavior from social network ads using demographic features (Age, Gender, Estimated Salary). Produced **business-driven insights**: strong precision for targeting campaigns, but opportunities to boost recall for wider sales reach. Delivered a reproducible ML pipeline with visual diagnostics (confusion matrix \u0026 ROC curve) for easy deployment.\n\n**Tech Stack:** Python, Pandas, Matplotlib, Seaborn, Scikit-learn, Jupyter.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsteffin12-git%2Flogistic-regression-social-network-ads-ml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsteffin12-git%2Flogistic-regression-social-network-ads-ml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsteffin12-git%2Flogistic-regression-social-network-ads-ml/lists"}