PearsonとSpearman
線形関係と順位関係の違い
「PearsonとSpearman」はCoddyKit上の無料Data Science Academyレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはData Science Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Data Science Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Two Ways to Correlate
Not all correlation is the same. The two most common methods, Pearson and Spearman, ask slightly different questions about how your variables relate. 🔍
What Pearson Measures
Pearson measures how well a straight line fits your data. It is the classic choice when both variables are numeric and their relationship looks roughly linear.
r = df["income"].corr(df["spending"], method="pearson")
print(round(r, 2))Pearson Needs Linearity
Because Pearson only sees lines, a strong but curved relationship can trick it. If the pattern bends, the Pearson value may look weak even when a real link exists.
Pearson and Outliers
Pearson is also sensitive to outliers. A single extreme point can drag the coefficient up or down and paint a misleading picture of your data.
What Spearman Measures
Spearman works on the ranks of your values, not the raw numbers. It asks whether one variable tends to increase as the other increases, in any consistent order.
r = df["rank_a"].corr(df["rank_b"], method="spearman")
print(round(r, 2))Monotonic Relationships
Spearman captures any monotonic trend, even a curved one. As long as the direction stays consistent, it reports a strong score regardless of the exact shape.
Robust to Outliers
Since Spearman uses ranks, one wild value barely matters. That makes it more robust when your data has extremes that would shake Pearson.
Spearman and Ordinal Data
Spearman shines with ordinal data like satisfaction ratings or rankings, where order matters but the gaps between levels are not truly equal.
When Both Agree
If a relationship is linear and outlier-free, Pearson and Spearman land close together. A big gap between them is a useful signal to look closer.
Choosing Between Them
Reach for Pearson on clean, linear numeric data. Switch to Spearman when you have ranks, curves, or outliers that you do not want to dominate the result.
One Method Argument
In pandas you switch with one argument. Pass method as either pearson or spearman to corr, and the rest of your code stays exactly the same.
Quick Check
Your data has a strong curved trend and a few wild outliers. Which method fits best?
Recap
Pearson measures linear strength on raw numbers, while Spearman ranks values to catch monotonic trends and shrug off outliers. Match the method to your data. ✅
よくある質問
「PearsonとSpearman」レッスンは無料ですか?
はい。「PearsonとSpearman」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Data Science Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Data Science Academyコースには全4レッスンが含まれています。
「PearsonとSpearman」で何を学びますか?
線形関係と順位関係の違い ブラウザで直接実行するハンズオンコードでData Science Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Data Science Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのData Science Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。
「PearsonとSpearman」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このData Science Academyレッスンでコードを書いて実行できますか?
はい。すべてのData Science Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- 相関は因果関係ではない
- PearsonとSpearman
- 相関ヒートマップを読む
- 歪度、尖度、正規性