Describe the order Python executes code, the job of print(), and what a variable is (slides 2–3).
name = "Ayesha", age = 20, gpa = 3.8).Name the four types on slide 4, match each to its example value, and explain how to confirm a value's type.
10 → int, 3.14 → float, "hello" → str, True → bool.<class 'int'> <class 'float'> <class 'str'> <class 'bool'>.Explain what a list and a dictionary each store, how you get items out of each, and when the deck says each is useful (slides 5–6).
fruits[0] is the first item ("apple"); len(fruits) gives how many items — 4 after fruits.append("mango").student["name"] returns "Ayesha"; student["gpa"] = 3.8 adds a new key-value pair.Explain what a function is, why the deck says to use one, and what the greet example returns (slide 7).
def greet(name): / return f"Hello, {name}!"; print(greet("Data Science Class")) outputs Hello, Data Science Class!.Explain when each loop repeats and trace the output of both slide-8 loops.
for fruit in fruits: prints apple, banana, cherry, mango.while i < 3: prints count: 0, count: 1, count: 2.i on each pass.Describe what NumPy arrays do well, NumPy's role under other libraries, and the slide-9 results.
import numpy as np; arr = np.array([1, 2, 3, 4, 5]) → arr.mean() = 3.0, arr.sum() = 15.Explain what a DataFrame is, what pandas is used for, and how read_csv() and head() start a project (slides 10–11).
Explain filtering and sorting, write the slide code for each, and state the results (slides 12–13).
ascending=False puts Noor (95) first and Yuki (45) last.Explain aggregation, list the deck's examples, and state the students.csv results (slide 14).
df["score"].mean() → 72.6; df["score"].max() → 95.Explain what groupby() does and state the average score per major (slide 15).
df.groupby("major")["score"].mean() → Business 59.67 · CS 72.5 · Math 85.67.Define features and label, identify both in students.csv, and explain why a supervised model needs both (slides 16–17).
X = df[["age", "score"]].y = df["passed"].Explain why feature selection matters and how the deck starts it, with the slide-18 results.
df[["age", "score", "passed"]].corr()["passed"] → score 0.844 · age 0.611 · passed 1.0 (itself).Explain why encoding is needed and how slide 19 encodes "major" and attaches it to X.
Contrast the two techniques, name the tool for each, and identify which columns the slides transform (slides 20–21).
StandardScaler.MinMaxScaler.sklearn.preprocessing: create the object, then call fit_transform() on X[["age", "score"]].Explain why data is held back and read every part of the slide-22 split call.
sklearn.model_selection; does the split in one line.X_train, X_test, y_train, y_test.test_size=0.2, random_state=42 on 10 rows: Train rows: 8 · Test rows: 2.The notebook builds one small class of students and uses it all the way through to a train/test split, "the same way a real project flows."
| name | age | major | score | passed |
|---|---|---|---|---|
| Ali | 20 | CS | 88 | 1 |
| Sara | 21 | Math | 92 | 1 |
| Omar | 19 | CS | 65 | 0 |
| Priya | 22 | Business | 74 | 1 |
| Liam | 20 | CS | 55 | 0 |
| Noor | 23 | Math | 95 | 1 |
| Diego | 21 | Business | 60 | 0 |
| Emma | 20 | CS | 82 | 1 |
| Kwame | 22 | Math | 70 | 1 |
| Yuki | 19 | Business | 45 | 0 |
passed comes from. Only the notebook defines it: passed = 1 if score ≥ 70, else 0 (6 of 10 passed). Kwame's 70 counts as a pass because the test is >=.| Type | Slide example | type() prints |
|---|---|---|
| int | x = 10 | <class 'int'> |
| float | y = 3.14 | <class 'float'> |
| str | z = "hello" | <class 'str'> |
| bool | is_valid = True | <class 'bool'> |
x and y are throwaway variable names (10 and 3.14). From slide 16 on, uppercase X = features (several input columns) and lowercase y = target (one column you predict). Keep that casing exact — Python is case-sensitive, so X and x are different variables.| List | Dictionary | |
|---|---|---|
| Stores | An ordered collection of items | Key-value pairs |
| Get a value | By position, starting at index 0 — fruits[0] | By key — student["name"] |
| Change it | Mutable — fruits.append("mango") | student["gpa"] = 3.8 adds a pair |
| Deck's use case | — | Labeled data like a student record |
fruits.append("mango") is a method call: fruits is a list object and append is a method that belongs to it. Same object.method() dot syntax as Java's list.add("mango") on an ArrayList. len(fruits) is different — it's a plain function that takes the list as an argument.f"…{name}…" string form on slide 7. The output shows the value of name appears where {name} sits; the deck gives no name or rule for this syntax.| Loop | Repeats… | Slide example |
|---|---|---|
| for | Once for each item in a collection | for fruit in fruits: → 4 lines |
| while | As long as a condition stays true | while i < 3: → count 0, 1, 2 |
np.array(...) and pd.DataFrame(data) each create an object; np and pd are just short names (aliases) for the imported libraries. Everything after a dot on arr or df — .mean(), .head(), .sort_values() — is a method on that object. df["score"] pulls out one column, which is itself an object, so df["score"].mean() calls .mean() on the column.| Operation | Slide code | Question it answers | Result (run) |
|---|---|---|---|
| Filtering | df[df["score"] > 80] | "Who scored above 80?" | Ali 88, Sara 92, Noor 95, Emma 82 |
| Sorting | df.sort_values("score", ascending=False) | Top (or bottom) performers at a glance | Noor 95 first … Yuki 45 last |
| Aggregation | df["score"].mean() · .max() | One number for a column (mean, sum, max, count) | 72.6 · 95 |
| describe() | df.describe() | Full statistical summary in one line | count, mean, std, min, 25%, 50%, 75%, max |
| GroupBy | df.groupby("major")["score"].mean() | "Average score, per major?" | Business 59.67 · CS 72.5 · Math 85.67 |
passed = 1..corr(). The deck uses it as a ranking tool but never explains what the numbers mean or their range. Also note from the notebook: passed is computed directly from score (≥ 70), so a strong score correlation is built into this toy data.prefix="major" names the new columns major_Business / major_CS / major_Math.axis=1 in pd.concat.| Scaling | Normalization | |
|---|---|---|
| What it does | Puts features on a comparable range using their mean and standard deviation | Rescales features into a fixed [0, 1] range |
| Tool | StandardScaler | MinMaxScaler |
| Import | sklearn.preprocessing — both | |
| Columns used | X[["age", "score"]] only — dummy columns left out | |
| First row on the run (Ali: 20, 88) | [-0.55, 0.97] | [0.25, 0.86] |
scaler = StandardScaler() creates an instance of the StandardScaler class. In Java that's StandardScaler scaler = new StandardScaler(); — Python has no new; calling the class name builds the object. Then scaler.fit_transform(...) calls a method on that instance. Naming tip: CapitalizedWords = class (StandardScaler, MinMaxScaler); lowercase_with_underscores = function or method (train_test_split, get_dummies, fit_transform).fit_transform() (see the Module 3 page, where fit learns the parameters and transform applies them) and the [:5] in print(X_scaled[:5]), which on the run prints the first 5 rows. The deck also gives no formula for either scaler.test_size=0.2 and random_state=42 each control. The run shows 10 rows → 8 train / 2 test.fit_transform on X_train, transform on X_test. This page keeps the Lecture 4 code as written; ask Dr. Al Amin which order he expects on the midterm.Reproduce the Lecture 4 code from memory. Drill one slide, one part, or the Full program. Each non-blank line is scored pass / fail against the deck's code — spacing, indentation, quote style, and # comments are ignored, but names and capitalization must match (Python is case-sensitive: X ≠ x). Slide 22's multi-line train_test_split(…) call is scored as one line.