Changeset 20 for trunk/lib/nanownlib/stats.py
- Timestamp:
- 08/18/15 22:09:24 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/nanownlib/stats.py
r16 r20 7 7 import gzip 8 8 import random 9 import numpy 9 try: 10 import numpy 11 except: 12 sys.stderr.write('ERROR: Could not import numpy module. Ensure it is installed.\n') 13 sys.stderr.write(' Under Debian, the package name is "python3-numpy"\n.') 14 sys.exit(1) 10 15 11 16 # Don't trust numpy's seeding … … 31 36 32 37 return statistics.mean(products) 38 39 40 def OLSRegression(x,y): 41 #print(x,y) 42 x = numpy.array(x) 43 y = numpy.array(y) 44 #A = numpy.vstack([x, numpy.ones(len(x))]).T 45 #m, c = numpy.linalg.lstsq(A, y)[0] # broken 46 #c,m = numpy.polynomial.polynomial.polyfit(x, y, 1) # less accurate 47 c,m = numpy.polynomial.Polynomial.fit(x,y,1).convert().coef 48 49 #print(m,c) 50 51 #import matplotlib.pyplot as plt 52 #plt.clf() 53 #plt.scatter(x, y) 54 #plt.plot(x, m*x + c, 'r', label='Fitted line') 55 #plt.show() 56 57 return (m,c) 33 58 34 59
Note: See TracChangeset
for help on using the changeset viewer.