Possible extra topics

One of the rubric items for the course project is to include something “extra” that wasn’t covered in Math 10. Here are a few possibilities. It’s even better if you find your own extra topic; it can be anything in Python that interests you.

pandas styler

pandas styler

See these examples in the pandas documentation. This provides a way to highlight certain cells in a pandas DataFrame, and is good practice using apply and applymap.

Altair interaction

interactive gif

See this section from these notes, or the Altair documentation.

scikit-learn

train_test_split. Next time I teach Math 10, I will be sure to introduce train_test_split early on when we discuss machine learning.

Random forests. This is maybe the machine learning method I see most often in Kaggle competitions.

faces with pca

Principal component analysis. We saw clustering as our only example of unsupervised learning. Another type of unsupervised learning is dimensionality reduction. PCA is a famous example.

Streamlit layout options

streamlit cheat sheet

If you want to add some variety to the layout of your Streamlit app, there are a few different options.

Gradient descent app. Here is an app I made for our class (but I never ended up using it). The box on the left is called a sidebar. Here is the code that made the sidebar:

with st.sidebar:
    st.write("Here you can adjust some parameters for the gradient descent algorithm.")

    learn = st.slider("What learning rate?",min_value=0.0,max_value=0.2,step=0.002, value = init_alpha,
                key="alpha", on_change = update, format="%.3f")

    batch = st.slider("What batch size?",min_value=1,max_value=pts,step=1, value = init_batch,
                key="batch", on_change = update)

If you really want, you can see the full code for the app, but I didn’t make an attempt to have the code readable.

Blog post introducing some of the other options for changing the layout in Streamlit. I really like columns.

on_change/on_click. In the code example above I used a keyword argument called on_change, which specifies a function to call. This is another way to add interactivity to a Streamlit app. It is a good concept to learn, because it is used in many different contexts related to websites.

Other libraries

Here are a few other libraries that you might find interesting.

  • sympy for symbolic computation, like what you did in Mathematica.

  • Pillow for image processing.

  • re for advanced string methods using regular expressions.

  • Seaborn It’s like a cross between Altair and Matplotlib.

  • Plotly It’s like a cross between Altair and Streamlit.