-3

this is an IBM skill lab code. try running it and keeps getting a error

pearson_coef, p_value = stats.pearsonr(df['city-mpg'], df['price'])
print("The Pearson Correlation Coefficient is", pearson_coef, " with a P-value of P = ", p_value)  

error message

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Input In [71], in <cell line: 1>()
----> 1 pearson_coef, p_value = stats.pearsonr(df['city-mpg'], df['price'])
      2 print("The Pearson Correlation Coefficient is", pearson_coef, " with a P-value of P = ", p_value)

NameError: name 'stats' is not defined
​
1
  • I read this as the pearsonr method is in something called stats. Have you got an import stats somewhere before this call? Commented Oct 27, 2022 at 13:07

1 Answer 1

1

You have to import stats - which without knowing what package you're trying to use - I would assume is the stats package from scipy

Add the following line at the top of your cell or file

# Import statistical package from Scipy
from scipy import stats
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.