Write a module to package your CHE 116 methods. You will create two files: stats.py
and regression.py
. Your stats.py
file will contain the confidence interval function from Unit 13, Lecture 1. You will write two regression functions in regression.py
: linear_regress
and nonlinear_regress
. Here are their attributes:
linear_regress
:
nonlinear_regress
:
You should be able to install your resulting CHE 116 module using the pip
command as shown in lecture.
I have been intentionally vague on the specifications. It is up to you to write detailed documentation and specifications about your function. You will be graded according to the following:
You should submit a zipped folder containing your module and notebook demonstrating how to use your function.
In [20]:
#making subplots
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(0,10, 0.01)
#share x-axis and make a 2x2 grid of plots
fig, axs = plt.subplots(nrows=2, ncols=2, sharex=True)
#index the axs to make individual plots
axs[0,0].plot(x, 2 * x)
axs[0,1].plot(x, x**2)
axs[1,1].plot(x, 2**x)
axs[1,0].plot(x, x / 2)
#can add labeles
axs[1,1].set_ylabel('fdsa')
axs[0,1].set_title('Title for one subplot')
#if you add labels, calling this method will spread out subplots until they fight
fig.tight_layout()
plt.show()
In [22]:
#compute numerical derivatives - need package
%system pip install numdifftools
Out[22]:
In [38]:
#create a function
def fxn(beta, x):
return x * beta[0]**2 + x * beta[1]
In [45]:
import numdifftools as nd
#get derivative wrt to beta
df = nd.Gradient(fxn)
#get some x-values to evaluate function
x = np.arange(0,10, 0.1)
#compute df/dbeta using gradient
df_dbeta = df([1,1], x)
In [ ]: