This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from scipy import sparse | |
| from scipy.sparse.linalg import spsolve | |
| import numpy as np | |
| def als(self, y, lam, p, niter): | |
| '''Asymmetric Least Squares Smoothing algorithm of Eilers and Boelens (2005) | |
| From Stackoverflow 29185844 by Sparrowcide as modified by jpatina | |
| Good choices for the parameters are: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from matplotlib import pyplot as plt | |
| fractions = range(1, 16) | |
| mcgs = [0,0,0,0,0,190,145,10,0,0,0,0,0,0,0] | |
| dpms = [0,0,0,0,0,290,390,0,0,0,0,5,20,80,350] | |
| #check lists for length | |
| for list in [dpms, mcgs]: | |
| assert len(list) == len(fractions), "lists should be same length" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| figsize = (10, 4) # set the fgsize for both the box plots and histograms | |
| # make boxplots | |
| # notch shape box plot | |
| def make_boxplot(ax, data, title): | |
| labels = [d.name for d in data] | |
| ax.boxplot(data, | |
| notch=True, # notch shape |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import logging | |
| logger = logging.getLogger(__name__) | |
| logger.setLevel(logging.DEBUG) | |
| formatter = logging.Formatter('%(asctime)s:%(levelname)s:%(name)s:%(message)s') | |
| file_handler = logging.FileHandler('combined.log') | |
| file_handler.setFormatter(formatter) | |
| stream_handler = logging.StreamHandler() | |
| stream_handler.setFormatter(formatter) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| x_data = np.arange(0, 10) | |
| y_data = [n + np.random.normal() for n in x_data] | |
| def poly_model(x_data, coeffs): | |
| '''Fit data to a linear polynomial model | |
| Args: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Use the recomended numpy array notation | |
| import numpy as np | |
| y = np.array([6.95,5.22,6.36,7.03,9.71,9.67,10.69,13.88,13.21,14.82]) | |
| X0 = np.array(np.ones(10)) | |
| X1 = np.array(range(0, 10, 1)) | |
| X = np.column_stack((X0.T, X1.T)) | |
| yhat = np.linalg.inv(X.T.dot(X)).dot(X.T).dot(y.T) | |
| print yhat | |
| ''' | |
| > [ 4.97309091 1.06242424] |
NewerOlder