This file contains 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] |
This file contains 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 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 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 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 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 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
FLATTEN = LAMBDA(array, | |
LET( | |
//name definitions | |
rows_, ROWS(array), | |
cols_, COLUMNS(array), | |
// index the zero-based array | |
seq_, SEQUENCE(rows_*cols_, 1, 0, 1), | |
// row and column indices |
This file contains 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 <https://exceljet.net/formula/lambda-append-range> | |
//stack arrays vertically | |
APPENDRANGEV = LAMBDA(range1, range2, default, | |
LET( | |
rows1, ROWS(range1), | |
rows2, ROWS(range2), | |
cols1, COLUMNS(range1), | |
cols2, COLUMNS(range2), | |
rowindex, SEQUENCE(rows1 + rows2), | |
colindex, SEQUENCE(1, MAX(cols1, cols2)), |
This file contains 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 <https://exceljet.net/formula/lambda-append-range> | |
//stack arrays horizontally | |
APPENDRANGEH = LAMBDA(range1, range2, default, | |
LET( | |
rows1, ROWS(range1), | |
rows2, ROWS(range2), | |
cols1, COLUMNS(range1), | |
cols2, COLUMNS(range2), | |
rowindex, SEQUENCE(MAX(rows1, rows2)), | |
colindex, SEQUENCE(1, cols1 + cols2), |
This file contains 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
/* | |
Append two ranges horizontally. | |
Inputs: | |
- range1: the first range | |
- range2: the second range | |
- default: the value entered into missing rows. | |
Return: The merged ranges, with empty rows filled with the default value. Missing | |
value within either of the two ranges filled with zeros (0). The number of rows |
OlderNewer