CSci574 / AI 520 Machine Learning: Classroom Session 09/03/2026
Overview
Derek Harter closes out Assignment 1 with guidance on NumPy vectorization, softmax, one-hot encoding, loss functions, and running pytest in the supplied or locally configured environment. He then explains the Chapter 2 machine-learning workflow, emphasizing held-out evaluation to detect overfitting and practical data preparation with pandas and scikit-learn, including stratified splitting, imputation, categorical encoding, feature engineering, scaling, and reusable pipelines.
Key takeaways
- Evaluate supervised models on a held-out test set because high training accuracy can reflect memorization rather than generalization.
- Use stratified splitting when a key category or measurement, such as housing income group, needs similar representation in training and test data.
- Scikit-learn preprocessing follows a reusable fit-and-transform pattern: fit learns parameters such as medians or scaling values, and transform applies them to data.
- Ordinal encoding is suitable only when categories have a meaningful order; one-hot encoding avoids artificial ordering for nominal categories but adds one column per category.
- Min-max scaling places features between 0 and 1, while standard scaling uses mean 0 and standard deviation 1; scaling is essential for algorithms affected by feature magnitude.
- Scikit-learn pipelines make data preparation reproducible by combining imputation, categorical encoding, feature engineering, and scaling into reusable workflows.
Chapters
- Derek Harter says a commit message can be minimal: a descriptive title plus one or two sentences explaining the change.
- He plans to review selected Assignment 1 solutions before returning to Chapter 2 material.
- Students can request alternative example solutions to compare approaches.
- For feature-wise means and standard deviations, use NumPy array operations with axis=0 to calculate values for each column.
- Vectorized operations and broadcasting apply standardization across the dataset without explicit loops.
- Softmax sums across each prediction row, using axis=1, to convert class scores into a probability distribution.
- One-hot encoding can initialize a zero array and set one class column per sample; several implementations are valid.
- Mean absolute error measures the average magnitude of prediction errors, regardless of whether each error is positive or negative.
- Root mean squared error squares errors, averages them, and takes the square root to return to the target's original units.
- A vector dot product with itself sums the squared elements, providing a compact way to express squared error.
- Harter notes that mean squared error is commonly used in regression because its derivatives are mathematically convenient for optimization.
- Assignment autograding uses pytest, so students should run the same tests locally before submitting.
- From a notebook directory, a command may need to reference the parent directory and then the tests directory to find the test modules.
- Jupyter's shell-command cell magic runs the equivalent of a terminal command, provided the active environment can find Python 3.
- The supplied Docker development container is the recommended way to match library versions, but students can also use the Dockerfile directly or configure another environment.
- Harter connects Chapter 2's exploration and cleaning material to the class project: select a dataset, investigate it, prepare it, and then build models.
- Real machine-learning work often involves more time inspecting and cleaning data than fitting models.
- Assignment datasets are generally prepared for the exercises, but project datasets may require more substantial cleaning.
- A useful supervised-learning model must generalize to examples that were not used for training.
- An overfit model can memorize training examples yet perform poorly on unseen data, much like memorizing an answer key.
- A train-test split holds back data so model performance can be evaluated on examples the model has not seen.
- Scikit-learn provides splitting utilities, and later workflows may also reserve a separate validation set for model selection or cross-validation.
- NumPy's random permutation can shuffle sample indices; passing 10 produces a shuffled ordering of indices 0 through 9.
- For an 80/20 split, divide the shuffled indices at the corresponding boundary and use one portion for training and the other for testing.
- Harter encourages students to run the IPython notebooks and experiment with their cells rather than only reading them.
- Jupyter contextual help and online NumPy documentation can clarify function parameters and behavior.
- A random split can introduce sampling bias if important groups are overrepresented in training or missing from testing.
- For the housing example, income categories should remain represented in similar proportions in both subsets.
- StratifiedShuffleSplit in scikit-learn can preserve a selected category distribution while producing training and test indices.
- A 20% test split returns the requested share while selecting samples differently from a plain random split.
- Missing data can be handled by dropping an affected feature, removing rows with missing values, or filling the gaps with estimated values.
- The housing example has missing entries in the total bedrooms feature, identifiable by comparing column counts or inspecting the data.
- Dropping rows or columns depends on how much data is missing and how important the feature is to the prediction task.
- Simple imputation can use a mean, median, or most frequent value; more advanced approaches can predict missing values from other features.
- SimpleImputer offers strategies such as median, mean, and most-frequent-value replacement for missing data.
- The imputer must be applied to numeric columns in the example, since its numeric strategies do not handle the string-valued ocean proximity feature.
- Scikit-learn commonly separates learning transformation parameters with fit from applying the operation with transform; fit_transform combines both steps.
- The imputer's transform returns a NumPy array, so restoring a pandas DataFrame requires rebuilding it with the original feature names.
- After median imputation, the total bedrooms column has values for all samples.
- Scikit-learn's reusable API centers on estimators with fit methods, transformers with fit and transform methods, and predictors that produce outputs for new data.
- Many scikit-learn objects share consistent method patterns, making the API easier to reuse across preprocessing and modeling tasks.
- The chapter transitions from general API conventions to transforming text-valued features such as ocean proximity.
- Pandas can inspect loaded data types and category counts, helping identify columns that need preprocessing.
- The housing dataset's ocean proximity column contains string categories, and value_counts reveals both the categories and their frequencies.
- OrdinalEncoder assigns integers to categories, which is appropriate when a meaningful order exists, such as distance from the ocean.
- Arbitrary integer assignments can imply false magnitude or similarity relationships, as with unrelated categories such as job titles.
- OneHotEncoder creates one binary column per category; it avoids imposing an order but can greatly increase the number of features when categories are numerous.
- A custom scikit-learn transformer can make feature engineering reproducible and reusable by implementing fit and transform methods.
- The housing example derives rooms per household and population per household from existing columns.
- An optional setting adds bedrooms per room, allowing the transformer to produce two or three engineered features.
- The transform combines the original data with the new columns, making the feature calculations easy to reuse in a preprocessing workflow.
- MinMaxScaler maps features into the 0-to-1 range, while StandardScaler centers values around mean 0 with standard deviation 1.
- Scaling matters for algorithms sensitive to feature magnitudes because large-valued features can dominate parameter estimation.
- Scaling changes the numeric range while retaining each feature's distributional shape; not every machine-learning algorithm is equally sensitive to it.
- Scikit-learn pipelines combine repeated steps such as categorical encoding, missing-value imputation, feature scaling, and transformation.
- Harter recommends starting Assignment 2 early, checking that the development environment works, and bringing setup problems to his attention.
Transcript excerpt
0:12 Okay. Um, so I had a couple people join. Are you guys able to hear me? Okay. >> Yes, professor. All right. Great. Thank you. Um, must go and get started. Uh so good afternoon. Um so my plan I'm I'm probably going to continue on with the um the the kind of big picture chapter stuffs. Um although I'm I'm I'm going to maybe just do a quick uh review of the assignment one. Um just had a couple things maybe that I wanted to bring up kind of mention on that. So, I'll do that first. Um, and then we'll go back to looking at the what was it? The the chapter two
1:01 materials um where kind of where we left off um looking at stuff last time. So, um Professor, just a quick question before we start. >> Yeah, anytime. >> On the commit message, how long would you expect those to be? Uh I'm I'm am just hoping to get people to get comfortable doing at least minimal. So um a minimal for me would be something like a title. Um and you know some sentences of English description. So uh even one is enough for I mean is more than I get from a lot of people. So, so but but yeah, usually, you know, if you read the link that I gave, give some, you know, if you're interested in
1:49 improving those kinds of skills, uh give some suggestions, but uh just a sentence or two um is enough of actual description below the title. So, >> okay, sounds good. Thank you. Um, so yeah, so I'm I'm uh kind of closing out the assignment ones here. Uh, I thought I mentioned one or two things. Um, I can post example solutions. I I
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Derek Harter.