← Back to NumPy Course | Chapter 8: Statistics | Lesson 3 of 6

np.corrcoef() से Correlation

Correlation बताता है कि numbers के दो sets कितने closely साथ move करते हैं, -1 से +1 तक।

In this page:

  1. np.corrcoef()
Syntax
python
corr = np.corrcoef(x, y)

np.corrcoef()

np.corrcoef एक correlation matrix return करता है। +1 के पास values मतलब variables साथ बढ़ते हैं, -1 के पास मतलब एक बढ़ता है जबकि दूसरा गिरता है, और 0 के पास मतलब कोई linear relationship नहीं। Diagonal हमेशा 1 है।

Note: off-diagonal entry [0, 1] दो inputs के बीच correlation है।

उदाहरण: np.corrcoef()

python
import numpy as np

hours = np.array([1, 2, 3, 4, 5])
score = np.array([52, 58, 65, 70, 78])
r = np.corrcoef(hours, score)
print(r.round(3))
print("r =", r[0, 1].round(3))

# Output:
# [[1.    0.998]
#  [0.998 1.   ]]
# r = 0.998
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. correlation को causation की तरह पढ़ना
  2. यह भूल जाना कि यह सिर्फ linear relationships detect करता है
  3. जब NumPy को rows expect हों तब columns pass करना
चैप्टर सारांश
  • corrcoef एक matrix return करता है
  • Range -1 से +1 है
  • Diagonal 1 है
  • Rows को variables की तरह treat किया जाता है
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.