{ "cells": [ { "cell_type": "markdown", "id": "c0fceb06-b5e7-4c2f-9f46-5216128911da", "metadata": {}, "source": [ "# Using AI and Machine Learning to Predict Consumer Behavior\n", "\n", "Companies understand that predicting customer behavior fills the gap in the markets and identifies products that are needed and which could generate bigger revenue.\n", "\n", "Consumer behavior prediction can be done by:\n", "\n", "- **Segmentation**: separating customers into smaller groups based on buying behaviors. This helps in the separation of concerns, which in turn helps us identify the region of the market.\n", "- **Predictive Analytics**: we use statistical techniques to analyze previous historical data to predict the future behavior of customers.\n", "\n", "# Data\n", "In this dataset, we have information related to customers:\n", "\n", "- **CustomerID** - ID of the customer\n", "- **Gender** - Gender of the customer\n", "- **Age** - Age of the customer\n", "- **AnnualIncome** - annual income of the customer\n", "- **SpendingScore** - score assigned based on the customer’s behavior and their purchasing data\n", "\n", "You can get tha dataset her: [Mall_Customers.csv](https://www.kaggle.com/datasets/vjchoudhary7/customer-segmentation-tutorial-in-python)" ] }, { "cell_type": "code", "execution_count": null, "id": "3206a006-12a2-4f27-b960-a01c9b3d07a6", "metadata": {}, "outputs": [], "source": [ "# Install\n", "!pip install -U scikit-learn" ] }, { "cell_type": "code", "execution_count": null, "id": "76854c32-87c0-4b16-b47c-c18a29803119", "metadata": {}, "outputs": [], "source": [ "!pip3 install -U seaborn" ] }, { "cell_type": "code", "execution_count": null, "id": "76d09b1e-e780-4fc0-a84a-71b296800c1a", "metadata": {}, "outputs": [], "source": [ "# Import Libraries\n", "import numpy as np\n", "import pandas as pd\n", "import sklearn\n", "from sklearn.cluster import KMeans\n", "import matplotlib.pyplot as plt\n", "import seaborn as sns" ] }, { "cell_type": "code", "execution_count": 2, "id": "f9f4d570-7642-4896-bb8d-9dd3d02ddbc9", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | CustomerID | \n", "Gender | \n", "Age | \n", "Annual Income (k$) | \n", "Spending Score (1-100) | \n", "
---|---|---|---|---|---|
0 | \n", "1 | \n", "Male | \n", "19 | \n", "15 | \n", "39 | \n", "
1 | \n", "2 | \n", "Male | \n", "21 | \n", "15 | \n", "81 | \n", "
2 | \n", "3 | \n", "Female | \n", "20 | \n", "16 | \n", "6 | \n", "
3 | \n", "4 | \n", "Female | \n", "23 | \n", "16 | \n", "77 | \n", "
4 | \n", "5 | \n", "Female | \n", "31 | \n", "17 | \n", "40 | \n", "