Skip to content

Instantly share code, notes, and snippets.

@pbowyer
Last active November 9, 2015 14:18
Show Gist options
  • Save pbowyer/2e257c7567d8ac8d0201 to your computer and use it in GitHub Desktop.
Save pbowyer/2e257c7567d8ac8d0201 to your computer and use it in GitHub Desktop.
This gives different results on each platform we test
"""
Please paste your output into a comment at
https://gist.github.com/pbowyer/2e257c7567d8ac8d0201
"""
import scipy # Imported for version number only
from scipy.odr import Model, Data, ODR
from scipy.stats import linregress
import numpy as np
def orthoregress(x, y):
"""Perform an Orthogonal Distance Regression on the given data,
using the same interface as the standard scipy.stats.linregress function.
Arguments:
x: x data
y: y data
Returns:
[m, c, nan, nan, nan]
Uses standard ordinary least squares to estimate the starting parameters
then uses the scipy.odr interface to the ODRPACK Fortran code to do the
orthogonal distance calculations.
"""
linreg = linregress(x, y)
print(linreg)
mod = Model(f)
dat = Data(x, y)
od = ODR(dat, mod, beta0=linreg[0:2])
out = od.run()
return list(out.beta) + [np.nan, np.nan, np.nan]
def f(p, x):
"""Basic linear regression 'model' for use with ODR"""
return (p[0] * x) + p[1]
######################################################
# Start useful debugging code
######################################################
import platform
import sys
def linux_distribution():
try:
return platform.linux_distribution()
except:
return "N/A"
print("""Python version: %s
dist: %s
linux_distribution: %s
system: %s
machine: %s
platform: %s
uname: %s
version: %s
mac_ver: %s
""" % (
sys.version.split('\n'),
str(platform.dist()),
linux_distribution(),
platform.system(),
platform.machine(),
platform.platform(),
platform.uname(),
platform.version(),
platform.mac_ver(),
))
print("Numpy version: " + np.__version__)
print("Scipy version: " + scipy.__version__)
print("")
######################################################
# End useful debugging code
######################################################
x = np.arange(5).astype(np.float64)
y = np.array([3.5, 2.7, 6.8, 5.6, 9.7]).astype(np.float64)
res = orthoregress(x, y)
print(res)
@pbowyer
Copy link
Author

pbowyer commented Nov 9, 2015

Python version: ['2.7.10 |Anaconda 2.3.0 (64-bit)| (default, Sep 15 2015, 14:50:01) ', '[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]']
dist: ('debian', 'jessie/sid', '')
linux_distribution: ('debian', 'jessie/sid', '')
system: Linux
machine: x86_64
platform: Linux-3.19.0-32-generic-x86_64-with-debian-jessie-sid
uname: ('Linux', 'robin', '3.19.0-32-generic', '#37~14.04.1-Ubuntu SMP Thu Oct 22 09:41:40 UTC 2015', 'x86_64', 'x86_64')
version: #37~14.04.1-Ubuntu SMP Thu Oct 22 09:41:40 UTC 2015
mac_ver: ('', ('', '', ''), '')

Numpy version: 1.10.1
Scipy version: 0.16.0

LinregressResult(slope=1.5299999999999998, intercept=2.6000000000000005, rvalue=0.86825369874211522, pvalue=0.056255802911426386, stderr=0.50474415961620245)
[1.9017643855965598, 1.8564712525382667, nan, nan, nan]

@pbowyer
Copy link
Author

pbowyer commented Nov 9, 2015

Python version: ['2.7.10 |Anaconda 2.4.0 (64-bit)| (default, Oct 21 2015, 19:35:23) [MSC v.1500 64 bit (AMD64)]']
dist: ('', '', '')
linux_distribution: ('', '', '')
system: Windows
machine: AMD64
platform: Windows-7-6.1.7601-SP1
uname: ('Windows', 'ComputerName', '7', '6.1.7601', 'AMD64', 'Intel64 Family 6 Model 60 Stepping 3, GenuineIntel')
version: 6.1.7601
mac_ver: ('', ('', '', ''), '')

Numpy version: 1.10.1
Scipy version: 0.16.0

LinregressResult(slope=1.5299999999999998, intercept=2.6000000000000005, rvalue=0.86825369874211511, pvalue=0.056255802911426428, stderr=0.50474415961620267)
[1.9017645308344246, 1.8564708499354836, nan, nan, nan]

@robintw
Copy link

robintw commented Nov 9, 2015

Python version: ['2.7.10 |Anaconda 2.3.0 (x86_64)| (default, Oct 19 2015, 18:31:17) ', '[GCC 4.2.1 (Apple Inc. build 5577)]']
dist: ('', '', '')
linux_distribution: ('', '', '')
system: Darwin
machine: x86_64
platform: Darwin-14.5.0-x86_64-i386-64bit
uname: ('Darwin', 'NewMBP.local', '14.5.0', 'Darwin Kernel Version 14.5.0: Wed Jul 29 02:26:53 PDT 2015; root:xnu-2782.40.9~1/RELEASE_X86_64', 'x86_64', 'i386')
version: Darwin Kernel Version 14.5.0: Wed Jul 29 02:26:53 PDT 2015; root:xnu-2782.40.9~1/RELEASE_X86_64
mac_ver: ('10.10.5', ('', '', ''), 'x86_64')

Numpy version: 1.10.1
Scipy version: 0.16.0

LinregressResult(slope=1.5299999999999998, intercept=2.6000000000000005, rvalue=0.86825369874211522, pvalue=0.056255802911426386, stderr=0.50474415961620245)
[1.9017643914833195, 1.856471228776897, nan, nan, nan]

@robintw
Copy link

robintw commented Nov 9, 2015

Python version: ['2.7.5 (default, Jul  3 2013, 14:38:56) ', '[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)]']
dist: ('redhat', '6.3', 'Santiago')
linux_distribution: ('Red Hat Enterprise Linux Server', '6.3', 'Santiago')
system: Linux
machine: x86_64
platform: Linux-2.6.32-279.19.1.1.el6.soton.x86_64-x86_64-with-redhat-6.3-Santiago
uname: ('Linux', 'cyan01', '2.6.32-279.19.1.1.el6.soton.x86_64', '#1 SMP Sun May 12 01:25:42 BST 2013', 'x86_64', 'x86_64')
version: #1 SMP Sun May 12 01:25:42 BST 2013
mac_ver: ('', ('', '', ''), '')

Numpy version: 1.7.0
Scipy version: 0.14.0

(1.5299999999999998, 2.6000000000000005, 0.86825369874211522, 0.056255802911426386, 0.50474415961620245)
[1.9017643649794611, 1.8564713073517836, nan, nan, nan]

@germannp
Copy link

germannp commented Nov 9, 2015

Python version: ['2.7.10 |Anaconda 2.3.0 (64-bit)| (default, Sep 15 2015, 14:50:01) ', '[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]']
dist: ('debian', 'jessie/sid', '')
linux_distribution: ('debian', 'jessie/sid', '')
system: Linux
machine: x86_64
platform: Linux-3.19.0-31-generic-x86_64-with-debian-jessie-sid
uname: ('Linux', 'philipp-HP', '3.19.0-31-generic', '#36-Ubuntu SMP Wed Oct 7 15:04:02 UTC 2015', 'x86_64', 'x86_64')
version: #36-Ubuntu SMP Wed Oct 7 15:04:02 UTC 2015
mac_ver: ('', ('', '', ''), '')

Numpy version: 1.9.2
Scipy version: 0.16.0

LinregressResult(slope=1.5299999999999998, intercept=2.6000000000000005, rvalue=0.86825369874211522, pvalue=0.056255802911426386, stderr=0.50474415961620245)
[1.9017643855965598, 1.8564712525382667, nan, nan, nan]

@p-i-
Copy link

p-i- commented Nov 9, 2015

[email protected] ~ /Users/pi:
⤐ python3 testcase.py
File "testcase.py", line 26
print linreg
^
SyntaxError: Missing parentheses in call to 'print'

[email protected] ~ /Users/pi:
⤐ python testcase.py
File "testcase.py", line 26
print linreg
^
SyntaxError: Missing parentheses in call to 'print'

[email protected] ~ /Users/pi:
⤐ which python
/Users/pi/anaconda/bin/python

Looks like Conda ate my 2.x
:-x

@pbowyer
Copy link
Author

pbowyer commented Nov 9, 2015

@p-i- thanks & sorry, does the script work now with Python 3?

@pbowyer
Copy link
Author

pbowyer commented Nov 9, 2015

Another from the community:

Python version: ['2.7.6 (default, Jun 22 2015, 17:58:13) ', '[GCC 4.8.2]']
dist: ('Ubuntu', '14.04', 'trusty')
linux_distribution: ('Ubuntu', '14.04', 'trusty')
system: Linux
machine: x86_64
platform: Linux-3.13.0-65-generic-x86_64-with-Ubuntu-14.04-trusty
uname: ('Linux', 'ropey', '3.13.0-65-generic', '#106-Ubuntu SMP Fri Oct 2 22:08:27 UTC 2015', 'x86_64', 'x86_64')
version: #106-Ubuntu SMP Fri Oct 2 22:08:27 UTC 2015
mac_ver: ('', ('', '', ''), '')
Numpy version: 1.8.2
Scipy version: 0.13.3
(1.5299999999999998, 2.6000000000000005, 0.86825369874211522, 0.056255802911426386, 0.50474415961620245)
[1.9017647664279498, 1.8564703727657534, nan, nan, nan]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment