Пирсон или Спирмен
Линейные и ранговые взаимосвязи
«Пирсон или Спирмен» — бесплатный урок Data Science Academy на CoddyKit. Это урок 2 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 24/7. Это часть пути обучения 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. ✅
Часто задаваемые вопросы
Урок «Пирсон или Спирмен» бесплатный?
Да — полный текст урока «Пирсон или Спирмен» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 24/7) и разблокировать остальной курс Data Science Academy, подпишись на CoddyKit PRO. Курс Data Science Academy содержит 4 уроков всего.
Чему я научусь в уроке «Пирсон или Спирмен»?
Линейные и ранговые взаимосвязи Ты практикуешь Data Science Academy с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.
Нужен ли мне опыт, чтобы начать Data Science Academy?
Предыдущий опыт не требуется. Data Science Academy на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 2 из 4.
Сколько времени занимает урок «Пирсон или Спирмен»?
Большинство уроков CoddyKit занимают около 5–10 минут. Каждый из них компактный и интерактивный, поэтому ты постоянно делаешь прогресс и продолжаешь с того же места в веб-версии и приложении.
Можно ли писать и запускать код в этом уроке Data Science Academy?
Да. Каждый урок Data Science Academy включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.
Все уроки этого курса
- Корреляция не означает причинность
- Пирсон или Спирмен
- Чтение тепловой карты корреляций
- Асимметрия, эксцесс и нормальность