Pearson frente a Spearman
Relaciones lineales frente a relaciones de rangos.
Pearson frente a Spearman es una lección gratuita de Data Science Academy en CoddyKit. Esta es la lección 2 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Data Science Academy, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Data Science Academy incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en inglés.
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. ✅
Preguntas frecuentes
¿La lección «Pearson frente a Spearman» es gratis?
Sí — el texto completo de «Pearson frente a Spearman» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Data Science Academy, actualiza a CoddyKit PRO. El curso de Data Science Academy incluye 4 lecciones en total.
¿Qué aprenderé en «Pearson frente a Spearman»?
Relaciones lineales frente a relaciones de rangos. Practicas Data Science Academy con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar Data Science Academy?
No se requiere experiencia previa. Data Science Academy en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 2 de 4.
¿Cuánto tiempo toma la lección «Pearson frente a Spearman»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de Data Science Academy?
Sí. Cada lección de Data Science Academy incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- Correlación no es causalidad
- Pearson frente a Spearman
- Interpretar un mapa de calor de correlaciones
- Asimetría, curtosis y normalidad