Teaching with Jupyter Notebooks

Jess Hamrick
@jhamrick

What is the Jupyter notebook?

What is the Jupyter notebook?

Live demo: try.jupyter.org

Notebook viewer: nbviewer.org

Example notebook: Perceptron Demo

In [2]:
@interact
def plot_histogram(num_samples=(0, 10000), bins=(10, 100), normed=True):
    rv = scipy.stats.norm(0, 1)
    samples = rv.rvs(num_samples)
    x = np.linspace(-3, 3)
    y = rv.pdf(x)
    plt.hist(samples, normed=normed, color='k', bins=bins)
    plt.plot(x, y, 'r-', lw=3)

Teaching computational science

  • Fast code iteration
  • Inline plots
  • Interactive visualization
  • Cross-platform

Notebooks as assignments

  • and many more!

Issues

  • Instructor and student versions

Instructor

Write code to compute the mean error between two arrays:

In [3]:
def error(x, y):
    return np.sum(np.abs(x - y))

Student

Write code to compute the mean squared error between two arrays:

In [4]:
def error(x, y):
    # YOUR CODE HERE
    raise NotImplementedError

Issues

  • Instructor and student versions
  • Renamed and missing files

Original

$ ls ps1/

Problem 1.ipynb
Problem 2.ipynb

Submitted

$ ls ps1/

problem 1.ipynb
Problem 2 Copy.ipynb

Issues

  • Instructor and student versions
  • Renamed and missing files
  • What should/should not be autograded

What should be graded?

In [5]:
def error(x, y):
    return np.sum(np.abs(x - y))
In [6]:
print(error(1, 2))
print(error(np.array([1, 2]), np.array([3, 4]))
  File "<ipython-input-6-2b19b0758384>", line 2
    print(error(np.array([1, 2]), np.array([3, 4]))
                                                   ^
SyntaxError: unexpected EOF while parsing

Issues

  • Instructor and student versions
  • Renamed and missing files
  • What should and should not be autograded?
  • Grading code and written answers together

Grading written answers

Run your error code on the ouput of the two models:

In [7]:
print("Model 1: {}".format(error(model1(x), y)))
print("Model 2: {}".format(error(model2(x), y)))
Model 1: 4.038695669499274
Model 2: 0.05343573722600464

Explain why the models have different error rates.

YOUR ANSWER HERE

Issues

  • Instructor and student versions
  • Renamed and missing files
  • What should and should not be autograded?
  • Grading code and written answers together
  • Students changing support code or tests

Meet nbgrader!

Thanks!

  • Project Jupyter
  • nbgrader contributors
  • pioneering nbgrader users
  • CodeNeuro SF