Implementing Apriori Algorithm in Python
Apriori Algorithm is a Machine Learning algorithm utilized to understand the patterns of relationships among the various products involved. The most popular use of the algorithm is to suggest products based on the items already in the user's shopping cart. Walmart specifically has utilized the algorithm in recommending items to its users.
Dataset: Groceries data
Implementation of algorithm in Python:
Step 1: Import the required libraries
Step 2: Load and explore the data
Index(['InvoiceNo', 'StockCode', 'Description', 'Quantity', 'InvoiceDate', 'UnitPrice', 'CustomerID', 'Country'], Dtype = 'object')
array(['United Kingdom', 'France', 'Australia', 'Netherlands', 'Germany', 'Norway', 'EIRE', 'Switzerland', 'Spain', 'Poland', 'Portugal', 'Italy', 'Belgium', 'Lithuania', 'Japan', 'Iceland', 'Channel Islands', 'Denmark', 'Cyprus', 'Sweden', 'Austria', 'Israel', 'Finland', 'Bahrain', 'Greece', 'Hong Kong', 'Singapore', 'Lebanon', 'United Arab Emirates', 'Saudi Arabia', 'Czech Republic', 'Canada', 'Unspecified', 'Brazil', 'USA', 'European Community', 'Malta', 'RSA'], dtype = object)
Step 3: Clean the Data
Step 4: Split the data according to the region of transaction
Step 5: Hot encoding the Data
Step 6: Build the models and analyse the results
From the above output, it can be seen that paper cups, paper and plates are bought together in France. This is because the French has a culture of having a get-together with their friends and family at least once a week. Also, since the French government has banned the use of plastic in the country, people have to purchase paper-based alternatives.
b) United Kingdom:
If the guidelines for British transactions are examined in greater detail, it is discovered that British consumers purchase various colored tea plates. The reason could be due to the fact that the British love tea and tend to collect different colors of tea plates to suit different occasions.
In analysing the association regulations to Portuguese transactions, the use of Tiffin set (Knick Knack Tins) and colour pencils can be found. These two items are typically belonging to a primary school child. Both of these items are needed by students at school to carry their lunches as well as for work that requires creativity, and therefore it is logical to pair them together.
Analysing the above guidelines and the above rules, we find that both girls' and boys' cutlery are placed together. This makes sense since when a parent shops for cutlery items for their children, they would like the item to be specific to the child's desires.
Next TopicSentiment Analysis using VADER
JavaTpoint offers too many high quality services. Mail us on h[email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected].
Duration: 1 week to 2 week