[SciPy-user] linear regression

jason-sage at creativetrax.com jason-sage at creativetrax.com
Wed May 27 17:04:27 EDT 2009


josef.pktd at gmail.com wrote:
> On Wed, May 27, 2009 at 9:35 AM,  <jason-sage at creativetrax.com> wrote:
>   
>> Is there a recommended way now of calculating the slope of a linear
>> regression?  Using the scipy.stats.linregress function gives a
>> deprecation warning, apparently because that function uses the
>> scipy.mean function:
>>
>> sage: import numpy
>> sage: import scipy.stats
>> sage: scipy.stats.linregress(numpy.asarray([4,3,2,1,2,3,4]),
>> numpy.asarray([1,2,3,4,3,2,1]))
>> /home/jason/download/sage-sage-4.0.alpha0.5/local/lib/python2.5/site-packages/scipy/stats/stats.py:420:
>> DeprecationWarning: scipy.stats.mean is deprecated; please update your
>> code to use numpy.mean.
>> Please note that:
>>   - numpy.mean axis argument defaults to None, not 0
>>   - numpy.mean has a ddof argument to replace bias in a more general
>> manner.
>>     scipy.stats.mean(a, bias=True) can be replaced by numpy.mean(x,
>> axis=0, ddof=1).
>>  axis=0, ddof=1).""", DeprecationWarning)
>> (-1.0, 5.0, -1.0, 1.9206748078018268e-50, 0.0)
>>
>>
>> This is scipy 0.7.0.
>>
>>     
>
> I backported a fix for incorrect slopes standard error
> (http://projects.scipy.org/scipy/ticket/874)
>  together with the switch to using numpy versions of the depreciated
> stats function.
>   

Thanks.  I tested the fixes, and it's slower than np.polyfit, so for now 
(unless there is good reason not to), I'm moving the one call over to 
use np.polyfit.

> However, not all usage of the depreciated functions has been
> backported to 0.7.1, but all are (supposed to be) fixed in the trunk
> for 0.8.
>
> So, these kind of depreciation warnings in 0.7.0 and 0.7.1 are just
> the result of unfinished  conversion to numpy stats functions.
>
>   

Thanks.  I already fixed a lot of the deprecation warnings (by switching 
to the numpy functions) we received from the Sage doctests regarding the 
mean, variance, and std stats functions. 

Dare I ask for what the give-or-take-a-million-years deadline for 0.8 is?

Thanks for a great project!

Jason




More information about the SciPy-User mailing list