Let's see how to apply unsupervised learning techniques to segment the market based on customer shopping habits. You have been provided with a file named sales.csv
. This file contains the sales details of a variety of tops from a number of retail clothing stores. Our goal is to identify the patterns and segment the market based on the number of units sold in these stores.
Create a new Python file and import the following packages:
import csv import numpy as np import matplotlib.pyplot as plt from sklearn.cluster import MeanShift, estimate_bandwidth
Load the data from the input file. Since it's a csv file, we can use the csv reader in python to read the data from this file and convert it into a NumPy
array:
# Load data from input file input_file = 'sales.csv' file_reader = csv.reader(open(input_file, 'r'), delimiter=',') X = [] for count, row in enumerate(file_reader): if...