Solving The Retail Store Problems Using Machine Learning

Techno Startup
5 min readMar 13, 2017

--

If you’re selling directly in Amazon, spotify and eBay or you’re a retail store or a Startup company either having pile of inventories before orders or have order fulfillment from retail stores and scaling is a problem because of lack of capital or delivery time issue this post is for you!!!!!!!

Retail stores often face supply chain issues. Machine learning and deep learning are trying to produce better data analysis to anticipate the retail demand. There are tons of variables that can have a significant impact on the retail operation. Let’s take a look at some of them.

  1. Right Quantity of the product. There is always a difficulty in meeting the demands of the consumer. Companies face scaling issue, lack of capital, time taken between production and delivery.

2. Anticipating the cost system which affect the delivery of product from the production center to the customer. (Commodity prices, Shipping cost, and etc).

3. Anticipating the demands of the consumer from season to season. Understanding the trends and change in the technology landscape.

4. Anticipate the recession and drop in demand. Taxes and tariff have an impact on retail operations.

Machine learning have been able to classify data based on features to such a high efficiency, it’s now a growing trend to solving most of the healthcare, retail, and electricity grid problem. Machine learning can be split into two categories. 1. Supervised 2. Unsupervised.

In Supervised Machine learning, the machine learns by comparing the results generated with the desired output. Supervised Machine learning uses Support Vector Machine, K-neighbors, k-fold, RandomForest, Tree classifiers to classify the data. Once the machine is trained, it’s fed with unknown inputs to test the performance of the code.

We have used the data set from the UCL Machine learning repository. It’s a Wholesale Customer data set for a wholesaler who sells products to retail, hotels, and restaurants. We can make a logical theory that the retail stores and hotel have different requirement for inventories. That’s why we try to classify the data on nature of requirement. Whether the pattern of products match a retail or hotel need. Wholesaler sells Fresh, Milk, Grocery, Frozen, Detergents and Delicassen. If retail stores are buying more from some categorie. Then the wholesaler can stack that particular categorie of stocks to meet the demand.

There can be a variant to this classification where the data can be classified based Region and Channel. It will open up better analytics for the wholesaler to identify the region which often buys more from the them (retail and Hotel combined). This will help the wholesaler to stock up products and deliver quickly.

We dropped the region in the following example.

import numpy as np
from sklearn import cross_validation, tree, neighbors, svm
from sklearn.ensemble import RandomForestClassifier
from sklearn.neural_network import MLPClassifier
import pandas as pd
import matplotlib.pyplot as plt
from sklearn import metrics

df = pd.read_csv(‘Wholesalecustomers data.csv’)
df.drop([‘Region’], 1)

traindf, testdf = cross_validation.train_test_split(df, test_size = 0.3)

Function to do the classifier

def classification_model(model, data, predictors, output):

model.fit(data[predictors], data[output])

predictions = model.predict(data[predictors])

accuracy = metrics.accuracy_score(predictions, data[output])

print(accuracy)

key = np.array([7579, 4956, 9426, 1669, 3321, 2566])
key = key.reshape(1, -1)

predict = model.predict(key)
print(‘[7579, 4956, 9426, 1669, 3321, 2566]’)
print(predict)

predictors = [‘Fresh’, ‘Milk’, ‘Grocery’, ‘Frozen’, ‘Detergents_Paper’, ‘Delicassen’]
model = RandomForestClassifier(n_estimators = 10)
output = [‘Channel’]
classification_model(model, traindf, predictors, output)

‘’’

The Output figures out whether the purchase order is from a hotel or retail chains.

Hotel orders =1, retail orders =2
‘’’

Warning (from warnings module):
Output
0.996753246753
[7579, 4956, 9426, 1669, 3321, 2566]
[2]

Also try with different classifier to see which classifier performs better.

Multi layer Perceptron

Multi layer perceptron has a input layer, hidden layer and an output layer. Task of classifier is to make a clear judgement on the data based their pattern. Optimizer is used to train the network, there are few optimization options like Stochastic Gradient Dissent, Adam Optimizer, etc. But the point is finding the local maxima for the weights. Normalize the input data before feeding the data into the input layer. It’s one of the most successful classifier.

clf = MLPClassifier(solver =’lbfgs’, alpha=1e-05, hidden_layer_sizes = (5, 2), random_state = 1)

Tree structure

Tree structure classifies based on if- then- else pattern.

clf = tree.DecisionTreeClassifier()

Support Vector Machine

Support vector machine creates a linear separator hyper-plane to classify the data. Classifier optimizes the output by using gradient dissent method to find the local maxima for the weights vector. SVC has number of parameters that can be tweaked to reach a higher accuracy.

clf = svm.SVC(C = 1000, gamma = 0.01)

Machine learning works to classify the pattern and deep learning networks learn and store the optimal value so they perform better than machine learning classifiers.

There are three types of business that revolves around machine learning, the data collection and organizing, data processing and machine learning, data optimization.

If you’re selling in Amazon and Ebay pay attention to this new technology, it’s easy to add it to your business. Machine learning will help you to increase sales, create happy customers, scaling up your business, Anticipate demand and changing price.

On the next post we’ll tear into the retail supply chain problems and try to provide a better solution with Machine Learning. Thanks for reading through.

--

--

Techno Startup

We're a technology company trying to solve the problems using machine learning and AI.