Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling statistics functions from Scipy

This may well be completely trivial.

I want to call the spearmanr function from scipy: (the data are just examples)

import scipy from numpy import *  Len = [2,3,5,7,2] Pop = [5,2,6,3,2]  a = array(Len) b = array(Pop)  print scipy.stats.spearmanr(a,b) 

This generates the error:

AttributeError: 'module' object has no attribute 'spearmanr' 

What am I doing wrong?

Thanks

like image 904
WillJones Avatar asked Jul 12 '11 13:07

WillJones


People also ask

How do I import stats from SciPy?

In the above program, first, we need to import the norm module from the scipy. stats, then we passed the data as Numpy array in the cdf() function. To get the median of the distribution, we can use the Percent Point Function (PPF), this is the inverse of the CDF.

What is SciPy stats as stats?

stats ) This module contains a large number of probability distributions, summary and frequency statistics, correlation functions and statistical tests, masked statistics, kernel density estimation, quasi-Monte Carlo functionality, and more.

What is CDF in SciPy?

A cumulative distribution function (CDF) tells us the probability that a random variable takes on a value less than or equal to some value. This tutorial explains how to calculate and plot values for the normal CDF in Python.


1 Answers

Use import scipy.stats. Then it works. Importing a package does not automatically import all the subpackages/modules. In these cases you have to do this explicitly.

like image 117
Björn Pollex Avatar answered Sep 18 '22 15:09

Björn Pollex