{"id":86306,"date":"2022-10-03T10:00:38","date_gmt":"2022-10-03T04:30:38","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=86306"},"modified":"2022-10-03T10:00:38","modified_gmt":"2022-10-03T04:30:38","slug":"customer-segmentation-using-machine-learning","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/customer-segmentation-using-machine-learning\/","title":{"rendered":"Customer Segmentation using Machine Learning"},"content":{"rendered":"<p>With this Machine Learning Project, we are going to do customer segmentation on data. This data is from a mall. We are going to divide its customers into different groups. This is a very important project in data science because you will be always analyzing such kinds of data and dividing your customers into groups. For this project, we are going to use KMeans clustering algorithm.<\/p>\n<p>So, let\u2019s start with the project.<\/p>\n<h3>Customer Segmentation<\/h3>\n<p>Today, many businesses are going online and therefore online marketing is essential to retain customers. However, considering all customers as equal and targeting them all with similar marketing strategies is not an efficient way, since it also annoys the customers by neglecting their individuality, so customer segmentation has become very popular and has also become a viable solution.<\/p>\n<p>The goal of customer segmentation is to divide the company&#8217;s customers based on their demographic characteristics (age, gender, marital status) and their behavior characteristics (types of products ordered, annual income). It&#8217;s a better approach for customer segmentation to focus on behavioral aspects rather than demographic characteristics since they do not emphasize individuality of customers.<\/p>\n<h3>The Model Architecture<\/h3>\n<p>It is often used in marketing to create customer segments and understand the behaviors of these segments. The K-means clustering algorithm provides insight into formats and differences in a database. The Python environment offers a great environment for building assemblies<\/p>\n<p>With K-means Clustering, we are given data points with their data sets and features, and the mechanism is to classify their data into clusters according to their similarities. K clusters are formed based on the similarity of the data. A Euclidean distance measurement method is used by KMeans to calculate similarity.<\/p>\n<ol>\n<li>This is step one. A random initialization of k points is done in the first step.<\/li>\n<li>Using K-means, each data point is classified according to its nearest mean, and its coordinates are rewritten according to the mean.<\/li>\n<li>Iteration is continuing up till all data points are classified.<\/li>\n<\/ol>\n<h3>Project Prerequisites<\/h3>\n<p>The required modules for this project are :<\/p>\n<ol>\n<li>Pandas &#8211; pip install pandas<\/li>\n<li>Numpy- pip install numpy<\/li>\n<li>Seaborn &#8211; pip install seaborn<\/li>\n<li>Matplotlib &#8211; pip install matplotlib<\/li>\n<\/ol>\n<h3>Customer Segmentation Project<\/h3>\n<p>The dataset for this project is a csv file. This file contains four columns which are customer_id, genre, age, annual_income, and spending_score. This data is from customers of a mall. We are going to analyze this data and divide its customers into segments.\u00a0Please download customer segmentation machine learning project along with the dataset from the following link: <a href=\"https:\/\/techvidvan.s3.amazonaws.com\/machine-learning-projects\/customer-segmentation.zip\"><strong>Customer Segmentation Project<\/strong><\/a><\/p>\n<h3>Steps to Implement Customer Segmentation Project<\/h3>\n<p>1. Importing all the modules to be used in the project.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import numpy as np \nimport pandas as pd \nimport matplotlib.pyplot as plt \nimport seaborn as sns\n \nimport numpy as np\nimport matplotlib.pyplot as plt\n%matplotlib inline\nfrom tensorflow.keras.layers import Input,Conv2D,MaxPooling2D,Dropout,Flatten,Dense,Activation,BatchNormalization,add\nfrom tensorflow.keras.models  import Model,Sequential\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator\nfrom tensorflow.keras.utils import plot_model\nfrom tensorflow.keras.applications.vgg16 import VGG16,preprocess_input\n\nimport os\n<\/pre>\n<p>2. Here we are reading our dataset.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">df = pd.read_csv('Mall_Customers.csv')\n\ndf.info()\n<\/pre>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/08\/customer-segmentation-dataset.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-86307\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/08\/customer-segmentation-dataset.webp\" alt=\"customer segmentation dataset\" width=\"780\" height=\"278\" \/><\/a><\/p>\n<p>3. Here we are defining our KMeans Model and we are fitting our training data.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">X = df.iloc[:, [3,4]].values\n \nfrom sklearn.cluster import KMeans\nwcss=[]\nfor i in range(1,11):\n    kmeans = KMeans(n_clusters= i, init='k-means++', random_state=0)\n    kmeans.fit(X)\n    wcss.append(kmeans.inertia_)\n<\/pre>\n<p>4. Here we are plotting the result.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">plt.plot(range(1,11), wcss)\nplt.title('The Elbow Method')\nplt.xlabel('no of clusters')\nplt.ylabel('wcss')\n\nplt.show()\n\n<\/pre>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/08\/elbow-method-plot.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-86308\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/08\/elbow-method-plot.webp\" alt=\"elbow method plot\" width=\"852\" height=\"381\" \/><\/a><\/p>\n<p>5. Here we are passing the testing data and we are predicting the result and we are plotting the data as clusters of the points.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">kmeansmodel = KMeans(n_clusters= 5, init='k-means++', random_state=0)\ny_kmeans= kmeansmodel.fit_predict(X)\n \nplt.scatter(X[y_kmeans == 0, 0], X[y_kmeans == 0, 1], s = 80, c = 'red', label = 'Customer 1')\nplt.scatter(X[y_kmeans == 1, 0], X[y_kmeans == 1, 1], s = 80, c = 'blue', label = 'Customer 2')\nplt.scatter(X[y_kmeans == 2, 0], X[y_kmeans == 2, 1], s = 80, c = 'green', label = 'Customer 3')\nplt.scatter(X[y_kmeans == 3, 0], X[y_kmeans == 3, 1], s = 80, c = 'cyan', label = 'Customerr 4')\nplt.scatter(X[y_kmeans == 4, 0], X[y_kmeans == 4, 1], s = 80, c = 'magenta', label = 'Customer 5')\nplt.scatter(kmeans.cluster_centers_[:, 0], kmeans.cluster_centers_[:, 1], s = 100, c = 'yellow', label = 'Centroids')\n\nplt.title('Clusters of customers')\n\nplt.xlabel('Annual Income (k$)')\nplt.ylabel('Spending Score (1-100)')\n\nplt.legend()\n\nplt.show()\n<\/pre>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/08\/customer-segmentation-output.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-86309\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/08\/customer-segmentation-output.webp\" alt=\"customer segmentation output\" width=\"818\" height=\"370\" \/><\/a><\/p>\n<h3>Summary<\/h3>\n<p>In this Machine Learning project, we learned how to implement customer segmentation. This is a really important project for data science. We are going to analyze such kinds of data a lot of times in data science. For segments, we have used kmeans clustering algorithm.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>With this Machine Learning Project, we are going to do customer segmentation on data. This data is from a mall. We are going to divide its customers into different groups. This is a very&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":86310,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[210],"tags":[4779,4780,4781,204,205],"class_list":["post-86306","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-machine-learning","tag-customer-segmentation","tag-customer-segmentation-using-k-means","tag-customer-segmentation-using-machine-learning","tag-machine-learning-project","tag-machine-learning-project-for-beginners"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Customer Segmentation using Machine Learning - TechVidvan<\/title>\n<meta name=\"description\" content=\"Develop a machine learning project for customer segmentation with k-means clustering using python, pandas, seaborn, numpy\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/customer-segmentation-using-machine-learning\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Customer Segmentation using Machine Learning - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Develop a machine learning project for customer segmentation with k-means clustering using python, pandas, seaborn, numpy\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/customer-segmentation-using-machine-learning\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-03T04:30:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2022\/08\/machine-learning-project-customer-segmentation.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Customer Segmentation using Machine Learning - TechVidvan","description":"Develop a machine learning project for customer segmentation with k-means clustering using python, pandas, seaborn, numpy","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techvidvan.com\/tutorials\/customer-segmentation-using-machine-learning\/","og_locale":"en_US","og_type":"article","og_title":"Customer Segmentation using Machine Learning - TechVidvan","og_description":"Develop a machine learning project for customer segmentation with k-means clustering using python, pandas, seaborn, numpy","og_url":"https:\/\/techvidvan.com\/tutorials\/customer-segmentation-using-machine-learning\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2022-10-03T04:30:38+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2022\/08\/machine-learning-project-customer-segmentation.webp","type":"image\/webp"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/customer-segmentation-using-machine-learning\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/customer-segmentation-using-machine-learning\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Customer Segmentation using Machine Learning","datePublished":"2022-10-03T04:30:38+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/customer-segmentation-using-machine-learning\/"},"wordCount":542,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/customer-segmentation-using-machine-learning\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2022\/08\/machine-learning-project-customer-segmentation.webp","keywords":["Customer Segmentation","Customer Segmentation using k means","Customer Segmentation using machine learning","machine learning project","machine learning project for beginners"],"articleSection":["Machine Learning Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/customer-segmentation-using-machine-learning\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/customer-segmentation-using-machine-learning\/","url":"https:\/\/techvidvan.com\/tutorials\/customer-segmentation-using-machine-learning\/","name":"Customer Segmentation using Machine Learning - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/customer-segmentation-using-machine-learning\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/customer-segmentation-using-machine-learning\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2022\/08\/machine-learning-project-customer-segmentation.webp","datePublished":"2022-10-03T04:30:38+00:00","description":"Develop a machine learning project for customer segmentation with k-means clustering using python, pandas, seaborn, numpy","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/customer-segmentation-using-machine-learning\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/customer-segmentation-using-machine-learning\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/customer-segmentation-using-machine-learning\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2022\/08\/machine-learning-project-customer-segmentation.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2022\/08\/machine-learning-project-customer-segmentation.webp","width":1200,"height":628},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/customer-segmentation-using-machine-learning\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Customer Segmentation using Machine Learning"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/86306","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=86306"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/86306\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/86310"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=86306"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=86306"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=86306"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}