Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
October 21, 2021 11:53 pm GMT

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

Weve 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, Ill 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. Lets get started by looking at our wardrobe!

Image descriptionWhats in your wardrobe? (Source: Anna Mu)

Before we begin

First, please make sure you know the basics of sorting and filtering in Pandas, as well 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, lets 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. Well 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, were 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 its a date, casual hangout, trips and more. Lets start by looking at common scenarios.

Scenarios

What could be worn to a date?

Youve 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 descriptionYouve 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. Youre on vacation and it doesnt 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 isnt complete yet. Its 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)

Original Link: https://dev.to/mage_ai/product-developers-guide-to-cross-joins-3obn

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To