Too Many Features
Part of the Unsupervised Learning section of Coddy's Machine Learning journey. Lesson 24 of 51.
This chapter squeezes many features into a few. By its end, 13 wine measurements become one map:
Why squeeze? Many features are hard to plot, slow to fit, and often repeat each other, like these two:
Twins carry one idea twice. The correlation matrix finds them, with an r near 1 or -1:
wine = load_wine(as_frame=True).frame
corr = wine.corr()
print(round(corr.loc["flavanoids", "total_phenols"], 2))This prints 0.86. Keep one of each pair, or merge them: merging is what this chapter builds.
Challenge
MediumA soap workshop measures 10 things on every batch of soap, and the reports grow long. Find the twins. The program reads a limit; the starter builds corr.
- Visit every pair of different columns once.
- Print each pair whose
ris at least the limit in size, either sign, withrto 2 decimals. - Print how many pairs you found.
For another workshop and limit 0.85:
lye_g and oil_g: 0.91
cure_days and water_left_pct: -0.88
Twin pairs: 2Try it yourself
import pandas as pd
# A soap workshop: 10 measurements for each of 60 batches of soap
batches = pd.read_csv("soaps.csv")
limit = float(input())
corr = batches.corr()
cols = corr.columns
# Write your code below
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Unsupervised Learning
1Finding Groups
Learning Without LabelsMeasuring SimilarityK-Means by HandK-Means in scikit-learnRecap: Gym Members7PCA in Practice
Seeing 64 DimensionsComponents as PatternsCompress and RebuildPCA Before a ModelRecap: Face Scanner10Project: Digit Explorer
Look at the DigitsShrink with PCACluster the DigitsName the ClustersFind the Odd OnesPractice on your own: Online Python compiler