Math For Specific ModelsMath for LLMs

Math For Specific Models

Private notes
0/8000

Notes stay private to your browser until account sync is configured.

Math For Specific Models
1 min read18 headings

Practice Lab

Runnable lab version for web reading.

Linear Models: Exercises

Ten exercises cover affine prediction, least squares, gradients, ridge regularization, logistic and softmax probabilities, standardization, and diagnostics.

Code cell 2

Try itPython / Pyodide

Python snippet

Output
Run the code to see stdout, return values, and errors here.

Runs in your browser sandbox. DeepML does not send this code to the server.

Exercise 1: Affine prediction

Compute one affine prediction.

Code cell 4

Try itPython / Pyodide

Python snippet

Output
Run the code to see stdout, return values, and errors here.

Runs in your browser sandbox. DeepML does not send this code to the server.

Code cell 5

Try itPython / Pyodide

Python snippet

Output
Run the code to see stdout, return values, and errors here.

Runs in your browser sandbox. DeepML does not send this code to the server.

Exercise 2: Least squares

Solve a tiny least-squares problem.

Code cell 7

Try itPython / Pyodide

Python snippet

Output
Run the code to see stdout, return values, and errors here.

Runs in your browser sandbox. DeepML does not send this code to the server.

Code cell 8

Try itPython / Pyodide

Python snippet

Output
Run the code to see stdout, return values, and errors here.

Runs in your browser sandbox. DeepML does not send this code to the server.

Exercise 3: Squared-loss gradient

Compute gradient X.T@(Xw-y).

Code cell 10

Try itPython / Pyodide

Python snippet

Output
Run the code to see stdout, return values, and errors here.

Runs in your browser sandbox. DeepML does not send this code to the server.

Code cell 11

Try itPython / Pyodide

Python snippet

Output
Run the code to see stdout, return values, and errors here.

Runs in your browser sandbox. DeepML does not send this code to the server.

Exercise 4: Gradient step

Take one gradient descent step.

Code cell 13

Try itPython / Pyodide

Python snippet

Output
Run the code to see stdout, return values, and errors here.

Runs in your browser sandbox. DeepML does not send this code to the server.

Code cell 14

Try itPython / Pyodide

Python snippet

Output
Run the code to see stdout, return values, and errors here.

Runs in your browser sandbox. DeepML does not send this code to the server.

Exercise 5: Ridge solution

Compute ridge solution for identity X.

Code cell 16

Try itPython / Pyodide

Python snippet

Output
Run the code to see stdout, return values, and errors here.

Runs in your browser sandbox. DeepML does not send this code to the server.

Code cell 17

Try itPython / Pyodide

Python snippet

Output
Run the code to see stdout, return values, and errors here.

Runs in your browser sandbox. DeepML does not send this code to the server.

Exercise 6: Shrinkage path

Compare ridge coefficients for two lambdas.

Code cell 19

Try itPython / Pyodide

Python snippet

Output
Run the code to see stdout, return values, and errors here.

Runs in your browser sandbox. DeepML does not send this code to the server.

Code cell 20

Try itPython / Pyodide

Python snippet

Output
Run the code to see stdout, return values, and errors here.

Runs in your browser sandbox. DeepML does not send this code to the server.

Exercise 7: Logistic probability

Compute sigmoid and BCE.

Code cell 22

Try itPython / Pyodide

Python snippet

Output
Run the code to see stdout, return values, and errors here.

Runs in your browser sandbox. DeepML does not send this code to the server.

Code cell 23

Try itPython / Pyodide

Python snippet

Output
Run the code to see stdout, return values, and errors here.

Runs in your browser sandbox. DeepML does not send this code to the server.

Exercise 8: Softmax

Compute softmax probabilities.

Code cell 25

Try itPython / Pyodide

Python snippet

Output
Run the code to see stdout, return values, and errors here.

Runs in your browser sandbox. DeepML does not send this code to the server.

Code cell 26

Try itPython / Pyodide

Python snippet

Output
Run the code to see stdout, return values, and errors here.

Runs in your browser sandbox. DeepML does not send this code to the server.

Exercise 9: Standardization

Standardize using train mean and std.

Code cell 28

Try itPython / Pyodide

Python snippet

Output
Run the code to see stdout, return values, and errors here.

Runs in your browser sandbox. DeepML does not send this code to the server.

Code cell 29

Try itPython / Pyodide

Python snippet

Output
Run the code to see stdout, return values, and errors here.

Runs in your browser sandbox. DeepML does not send this code to the server.

Exercise 10: Checklist

Write four linear-model diagnostics.

Code cell 31

Try itPython / Pyodide

Python snippet

Output
Run the code to see stdout, return values, and errors here.

Runs in your browser sandbox. DeepML does not send this code to the server.

Code cell 32

Try itPython / Pyodide

Python snippet

Output
Run the code to see stdout, return values, and errors here.

Runs in your browser sandbox. DeepML does not send this code to the server.

Closing Reflection

Linear models are the best place to learn the full supervised-learning loop because every shape, gradient, regularizer, and diagnostic is visible.

PreviousNext