Product developers’ guide to cross joins

TLDR

Learn how to use AI to select your next outfit that matches the occasion. Featuring Pandas and the merge function to find all combinations.

Introduction

We’ve all been there staring into our closet, admiring all the clothes …


This content originally appeared on DEV Community and was authored by Mage

TLDR

Learn how to use AI to select your next outfit that matches the occasion. Featuring Pandas and the merge function to find all combinations.

Introduction

We’ve all been there staring into our closet, admiring all the clothes but not quite realizing all the different combinations of clothes. In this follow up guide, I’ll go over how we can use AI to make our selection more transparent by understanding all the combinations we can use and when we should wear them. Let’s get started by looking at our wardrobe!

Image descriptionWhat’s in your wardrobe? (Source: Anna Mu)

Before we begin

First, please make sure you know the basics of sorting and filtering in Pandas, as we’ll be using it frequently. For a quick refresher, read our introductory guide for information on importing, exporting, and processing all our data, and our guide to merge. With that out of the way, let’s start by downloading the wardrobe dataset and importing it on Google Collab.
Image description

My closet

The wardrobe dataset contains information on 5 different shirts, and 5 different pants, along with labels for whether they are casual wear. We’ll break down this dataset into 2 portions, 1 for shirts and another for pants.

Image descriptionShirts: T-Shirt, Sweatshirt, Vest, Tuxedo, and Suit
Image descriptionPants: Slacks, Jeans, Shorts, Cargo pants, and overalls
Image descriptionSo many options

Cartesian Product

Using our datasets, we’re going to begin creating a combination calculated by the cartesian product. This is an operation where every object is paired with another object. In other words, a shirt for each pair of pants to calculate all possible combinations. This is a many to many relationship, where many objects connect with many other objects.

Image descriptionSource: Mathstopia

Cross Join

Another term for the cartesian product is a cross join, which is a join that follows the operation of a cartesian product, by crossing each object with each other. A many to many relationship can be specified in Pandas using on and matching values. In this case, we want everything to match with everything, so we add a new column called ‘keys’ and store in both the same value.
Image description
Once the key is created, we call merge on the keys to perform the Cartesian Product.

Image descriptionResult of the cross join

Our result shows that we have 25 different outfits, and will use this finalized data to answer questions about the wardrobe and pick the right outfit for each special occasion, whether it’s a date, casual hangout, trips and more. Let’s start by looking at common scenarios.

Scenarios

What could be worn to a date?

You’ve got to dress to impress by picking formal clothing.

Image descriptionSlacks with a vest, tux, or suit. (Source: Date Night)

Image description

How about playing at an Amusement Park?
Casual clothing for fun and games!

Image descriptionYou’ve got a lot of outfits to choose from.

Image description

What about going to class?
Wear clothes that match. The last thing you want is to be bullied because of the way you dress. There are 11 different combinations of matching clothes that are both casual or not.

Image descriptionOutfits that match (Source: Tumblr)

Image description

Anything special we could wear for hiking?
When hiking you want to be prepared, so wear cargo shorts with lots of pockets, along with any casual shirt.
Image description

Image descriptionA happy camper wears cargo pants and a t-shirt or a sweatshirt. (Source: National Geographic)

Finally, what about a leisure-filled vacation?
You may wear whatever outfit you wish. You’re on vacation and it doesn’t need to match. You have 25 different combinations to choose from.

Image descriptionA vacation to the Caribbean (Source: Jade Mountain)

Conclusion

Outside of saving time and wearing the right attire for the occasion, cross joins are an efficient way to get all combinations. Combined with filters, this can greatly reduce the cost and increase the speed of data preprocessing. Speaking of which, our outfit isn’t complete yet. It’s become customary to wear a mask out in public. Cross join your new combination with another dataset of masks to complete the outfit.


Image descriptionJust in time for Halloween! (Source: Disney)


This content originally appeared on DEV Community and was authored by Mage


Print Share Comment Cite Upload Translate Updates
APA

Mage | Sciencx (2021-10-21T23:53:57+00:00) Product developers’ guide to cross joins. Retrieved from https://www.scien.cx/2021/10/21/product-developers-guide-to-cross-joins/

MLA
" » Product developers’ guide to cross joins." Mage | Sciencx - Thursday October 21, 2021, https://www.scien.cx/2021/10/21/product-developers-guide-to-cross-joins/
HARVARD
Mage | Sciencx Thursday October 21, 2021 » Product developers’ guide to cross joins., viewed ,<https://www.scien.cx/2021/10/21/product-developers-guide-to-cross-joins/>
VANCOUVER
Mage | Sciencx - » Product developers’ guide to cross joins. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/10/21/product-developers-guide-to-cross-joins/
CHICAGO
" » Product developers’ guide to cross joins." Mage | Sciencx - Accessed . https://www.scien.cx/2021/10/21/product-developers-guide-to-cross-joins/
IEEE
" » Product developers’ guide to cross joins." Mage | Sciencx [Online]. Available: https://www.scien.cx/2021/10/21/product-developers-guide-to-cross-joins/. [Accessed: ]
rf:citation
» Product developers’ guide to cross joins | Mage | Sciencx | https://www.scien.cx/2021/10/21/product-developers-guide-to-cross-joins/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.