Explain what an SVM is, what it's mainly used for, and what kind of boundary it looks for.
Describe what the margin is and why SVM picks the boundary with the largest one.
Identify the support vectors and explain why only they matter for the boundary.
Explain the difference between the two and which one is used in practice.
Describe what a large C and a small C do to the margin and to mistakes.
Describe the problem the kernel trick solves and how it solves it.
Match each kernel to when or how it's used.
kernel = 'linear'.Explain each symbol in the decision boundary and how a point gets its class.
w · x + b = 0.y = sign(w · x + b).Connect the margin to ||w|| and describe training as an optimization problem.
2 / ||w||.Name each strength and say briefly why it helps.
Name each weakness and connect at least one to the soft margin or kernels.
Name four use cases and summarize the lecture's three takeaways.
Explain how the notebook builds X and y and splits them 75/25.
pd.read_csv('Social_Network_Ads.csv'): 400 rows, columns Age, EstimatedSalary, Purchased.dataset.iloc[:, :-1].values: every column but the last (Age, EstimatedSalary).dataset.iloc[:, -1].values: the last column, Purchased (0 or 1).train_test_split(X, y, test_size = 0.25, random_state = 0) → 300 training rows, 100 test rows.Walk through the StandardScaler cell and why it's fit on the training set only.
sc = StandardScaler().X_train = sc.fit_transform(X_train) learns each feature's mean and standard deviation from the training data.X_test = sc.transform(X_test) applies those same numbers; it never learns from the test set.Explain SVC(kernel = 'linear', random_state = 0), its printed defaults, and what .fit does.
from sklearn.svm import SVC (SVC = the scikit-learn class for SVM classification).classifier = SVC(kernel = 'linear', random_state = 0): a straight-line (linear) boundary.C=1.0 (the soft-margin penalty) and probability=False (no probabilities, matching the lecture's weakness).classifier.fit(X_train, y_train) solves the optimization for the best w and b.Explain classifier.predict(sc.transform([[30, 87000]])) inside-out and its output.
[[30, 87000]] is one person (age 30, salary $87,000) as a 2-D list: one row, two features.sc.transform(...) uses the training mean and standard deviation.classifier.predict(...) checks which side of the boundary the point falls on.[0]: predicted not to purchase.Label each number in [[66 2] [8 24]] and compute the accuracy of 0.9.
y_pred = classifier.predict(X_test), printed side by side with y_test.confusion_matrix(y_test, y_pred): rows = actual, columns = predicted, class 0 first → [[TN FP] [FN TP]].Describe how the plotting cell builds the chart and what the boundary looks like.
sc.inverse_transform(...) puts real ages and salaries back on the axes.np.meshgrid(..., step = 0.25) builds a very fine grid of (age, salary) points around the data.plt.contourf predicts every grid point and paints it: red = 0, green = 1.plt.scatter draws each real person in their true color.Use the Module 6, 7 and 8 notebooks (same data, split and scaling) to compare the three models.
Social_Network_Ads.csv), whose outputs were reproduced to confirm every number. The notebook has no written explanations, so code behavior comes from the scikit-learn / NumPy / Matplotlib documentation (links on the Notes tab). All diagrams are redrawn for study. Purple Study aid boxes are memory tricks, OOP reminders, extra runs on the class data, and links to earlier modules — not lecture content.| Hard margin | Soft margin | |
|---|---|---|
| Rule | Perfect separation — no points allowed inside the margin | Some points may be misclassified or inside the margin |
| Works on | Only perfectly separable data | Real, noisy data |
| Used | Rarely | Almost always — real data is rarely perfectly separable |
| Setting | Misclassification | Margin |
|---|---|---|
| Large C | Punished heavily | Narrower |
| Small C | More flexibility allowed | Wider |
C=1.0.| C | Margin width (2/||w||) | Support vectors | Test accuracy |
|---|---|---|---|
| 0.01 | 2.76 | 206 | 0.87 |
| 0.1 | 1.46 | 148 | 0.89 |
| 1 (notebook) | 1.07 | 128 | 0.90 |
| 10 | 1.03 | 126 | 0.89 |
| 100 | 1.02 | 125 | 0.89 |
| Kernel | What it does | scikit-learn |
|---|---|---|
| Linear | No transformation — used when data is already linearly separable | kernel='linear' ← the class notebook |
| Polynomial | Curved boundaries from polynomial combinations of features | kernel='poly' |
| RBF (Radial Basis Function) | The most popular choice for complex, nonlinear boundaries | kernel='rbf' |
| Sigmoid | Behaves similarly to a neural network activation function | kernel='sigmoid' |
degree=3 is the polynomial kernel's degree and is ignored by the linear kernel. Also, scikit-learn's own default kernel is 'rbf'; the notebook overrides it with 'linear'.| Kernel | Confusion matrix | Accuracy | Missed buyers (FN) |
|---|---|---|---|
| linear (notebook) | [[66 2] [8 24]] | 0.90 | 8 |
| poly | [[67 1] [13 19]] | 0.86 | 13 |
| rbf | [[64 4] [3 29]] | 0.93 | 3 |
| sigmoid | [[54 14] [12 20]] | 0.74 | 12 |
| Piece | Formula | Meaning |
|---|---|---|
| Decision boundary | w · x + b = 0 | The hyperplane itself |
| w | weight vector | Perpendicular to the boundary |
| x | input features | The point being classified |
| b | bias | Shifts the boundary |
| Classification rule | y = sign(w · x + b) | Which side of the boundary a point falls on determines its predicted class |
| Margin width | 2 / ||w|| | So maximizing the margin = minimizing ||w|| |
| Training | optimization | Find the best w and b |
sign returns −1 or +1. The usual math convention labels the classes −1 and +1 and puts the margin edges at w·x + b = ±1, which is where the 2 / ||w|| comes from. scikit-learn maps those back to your labels, so the notebook still prints 0 and 1. ("||w||" means the length of w.).fit, classifier.coef_ = w ≈ [1.60, 0.97] and classifier.intercept_ = b ≈ −0.77, in scaled units. So ||w|| ≈ 1.87 and the margin ≈ 2 / 1.87 ≈ 1.07. Age has the bigger weight, so it tilts the line more than salary does.
[0]._ (coef_, intercept_, support_vectors_, n_support_) only exist after .fit — they're what the object learned. Same idea as Java instance fields that a method fills in.| Strengths | Weaknesses |
|---|---|
| Effective in high-dimensional spaces | Slow to train on very large datasets |
| Memory-efficient — only uses the support vectors | Performance drops with lots of noise or overlapping classes |
| Versatile, thanks to different kernel choices | Choosing the right kernel and tuning C can be tricky |
| Works well with a clear margin of separation | Doesn't directly output probabilities |
probability=False. Per the scikit-learn documentation, setting probability=True makes it estimate probabilities with an extra internal cross-validation step, which slows training — consistent with the lecture's "not directly."| Use case | What gets classified |
|---|---|
| Text classification & spam filtering | Documents and emails |
| Image classification & face detection | Images |
| Bioinformatics | Genes and proteins |
| Handwriting recognition | Handwritten characters |
| Column | Role | Range in the CSV |
|---|---|---|
| Age | feature → X | 18 – 60 |
| EstimatedSalary | feature → X | 15,000 – 150,000 |
| Purchased | target → y | 0 (didn't buy) or 1 (bought) |
| Feature | Training mean | Training std | Example: raw → scaled |
|---|---|---|---|
| Age | ≈ 38.1 | ≈ 10.1 | 44 → 0.58 |
| EstimatedSalary | ≈ 69,583 | ≈ 34,491 | 39,000 → −0.89 |
sc.mean_, sc.scale_) on the same split. The example row is the first training person, whose raw and scaled values both appear in the notebook's printouts.| Piece | What it means | Lecture link |
|---|---|---|
SVC | scikit-learn's class for SVM classification | "used mainly for classification" |
kernel = 'linear' | Straight-line boundary, no transformation | Linear kernel |
random_state = 0 | Repeatable results | — |
C=1.0 (default) | Soft-margin penalty | The C parameter |
probability=False (default) | No probability output | "Doesn't directly output probabilities" |
.fit(X_train, y_train) | Solves the optimization for the best w and b | "Training an SVM" |
SVC(kernel='linear', random_state=0).SVC is the class (the blueprint). classifier = SVC(...) creates an object (an instance) and the arguments go to its constructor, like new SVC(...) in Java. .fit and .predict are methods called on that object. It's the same .fit / .predict pair as LogisticRegression and KNeighborsClassifier, which is why swapping models only changes these lines.classifier.n_support_ → [64 64] (128 support vectors). classifier.support_vectors_ holds those 128 points. The classes overlap, so many points sit inside the soft margin (Part 1 note).[[30, 87000]] (one person, 2-D: 1 row × 2 features) → sc.transform (scale with the training numbers) → classifier.predict (which side of the boundary?) → [0].[predicted actual]. A row like [0 1] is a missed buyer; [1 0] is a false alarm.| Predicted 0 | Predicted 1 | |
|---|---|---|
| Actual 0 | TN = 66 correctly said "won't buy" | FP = 2 said "buy" — didn't |
| Actual 1 | FN = 8 said "won't buy" — did | TP = 24 correctly said "buy" |
[[TN FP] [FN TP]]. The layout comes from the scikit-learn documentation; the notebook doesn't label it.| Piece | What it does |
|---|---|
A · sc.inverse_transform(...) | Undoes the scaling so the axes show real ages and salaries. |
B · np.meshgrid(...), step = 0.25 | Builds a grid of (age, salary) points 10 years past the age range and 1,000 past the salary range, in steps of 0.25. That's 248 ages × 548,000 salaries ≈ 136 million points — 16× more than Module 7's step = 1. |
C · plt.contourf(...) | Flattens the grid, scales it, predicts every point with the SVM, folds the answers back into the grid shape, and paints the background: red = predicted 0, green = predicted 1. |
D · plt.scatter loop | Plots each real person in their true color: red for 0, green for 1. |
c-argument warning as Modules 6–7.[predicted actual] printout to its X_test printout. The grid size was computed from the code.| Logistic regression (M6) | K-NN, K = 5 (M7) | SVM, linear (M8) | |
|---|---|---|---|
| Model line | LogisticRegression(random_state = 0) | KNeighborsClassifier(n_neighbors = 5, metric = 'minkowski', p = 2) | SVC(kernel = 'linear', random_state = 0) |
What .fit does | Learns weights and a bias | Stores the training data (lazy) | Finds the maximum-margin w and b |
| Boundary | Straight line | Irregular, jagged | Straight line |
| Confusion matrix | [[65 3] [8 24]] | [[64 4] [3 29]] | [[66 2] [8 24]] |
| Accuracy | 0.89 | 0.93 | 0.90 |
| Missed buyers (FN) | 8 | 3 | 8 |
| False alarms (FP) | 3 | 4 | 2 |
| New person (30, $87,000) | 0 | 0 | 0 |
[[64 4] [3 29]] (Part 3 extra run): the curved boundary the lecture promises.