ML Club sessions
Math for ML

Two-day workshop, with GDSC · Epoch, IIT Hyderabad · 1st April, 2023 and 4th April, 2023

A hands-on workshop on the most important mathematical concepts: probability, statistics, linear algebra and calculus, with hands-on and theory exercises.

Slide 1 of 176
1 / 176

Math for ML

Two-day workshop, with GDSC · Epoch, IIT Hyderabad · 1st April, 2023 and 4th April, 2023

A hands-on workshop on the most important mathematical concepts: probability, statistics, linear algebra and calculus, with hands-on and theory exercises.

  1. Math for ML An Epoch-GDSC Collaboration
  2. Probability Distributions
  3. Probability Distributions: Gaussian Distribution Gaussian/Normal distribution - The probability density for the Gaussian distribution is - The function has its peak at the mean, and its “spread” increases with the standard deviation. This implies that normal is more likely to return samples lying close to the mean, rather than those far away. Saw this in Modern Physics right? It’s not that scary as it looks!
  4. Random Sampling from Distributions - np.random.normal(loc = 0.0, scale = 1.0, size = None) - It generates random numbers from a normal distribution. - Here, loc is the mean of the distribution and scale = variance of the distribution. - Confusing?? Let’s plot it !!
  5. Other Distributions! There are still a lot of distributions that NumPy offers like: 1. np.random.weibull() 2. np.random.poisson() 3. np.random.binomial() 4. np.random.uniform() 5. etc., These are left for you to explore ! And stay tuned for the Math for ML session!
  6. Intro to
  7. Plotting - Let’s get started! - We use matplotlib for plotting figures in python. - Matplotlib is a comprehensive library for creating static, animated, and interactive visualizations in Python. - plt.hist(x,bins, density) : Plot the histogram of the data - plt.plot() : Plot the curve in the figure - We will see this in more details in the upcoming slides
  8. Gaussian Distribution - The Bell Curve!
  9. Cricketing Analyst - Tutorials! - Let’s plot some interesting data. - I extracted out the scores of Virat Kohli in the last 6 ODI innings. Let begin our journey to Cricket Analyst and plot the data. - plt.bar(x, height, width = 0.8, align = “center”) : Plots the bar graph of the data x - We generate the x using np.linspace and Virat score is the height of our bars.
  10. Plotting - Important Functions - plt.title() - gives a title to the graph - plt.xlabel() - gives a label to the x-axis - plt.ylabel() - gives a label to the y-axis
  11. The plt.plot() function! - plt.plot(x, y, color, marker, linestyle, linewidth, label) - Plot y versus x as lines - Color - To specify a colour to our line plot - Linestyle - To customize our line - Linewidth - To customize our line width - Label - To label our line
  12. plt.grid() - plt.grid() - Plots the gridlines in the graph
  13. Can we plot multiple plots in a single figure? Yes! - Multiple plots in a single figure
  14. plt.legend(): Yeah Virat is a legend, but this is different! - plt.legend() - Plots the legend box in the figure
  15. Upcoming Legend? Tendulkar?? Sara Shubman Gill - Exercise Time! Plot the bar graph of Shubman Gill’s scores
  16. Scatter Plots! - plt.scatter(x, y, marker, color) - Plots the scatter plot of x v/s y with varying markers.
  17. The Final Plot!
  18. Functions and Gradients
  19. Mathematical Functions - Wait, we gonna see Cal - 1? Absolutely not! Mathematical functions in numpy are special because they can be used to perform operations element-wise on either python lists or numpy arrays.
  20. Trig Functions! .sin(), .cos(), .tan() .arcsin(), .arccos(), .arctan()
  21. Trigonometric functions .sinh(), .cosh(), .tanh() .degree(), .radian()
  22. Logarithmic functions .log(), .log2(), .log10() .exp(), .exp2()
  23. Additional functions .around(), .floor(), .ceil() .mod(a,b) Modulo function, prints remainder of elements in a with those in b element wise.
  24. .max(), .min() The maximum/minimum element in an array. .add(), .subtract(), .multiply(), .divide() Add, subtract, multiply, or divide two numpy arrays element wise.
  25. .conj(), .isreal() .maximum, .minimum
  26. A few interesting functions .cbrt() - returns the cube root of a number. It is one of the few ways in python that allows you to take the real cube root of a negative number - Most functions return the complex root instead.
  27. .where() Allows you to set your own conditions and returns result from the first array if true, else returns the value from the second array.
  28. Gradients np.gradient(fx,x) will output the approximate gradient calculated using numpy arrays of f(x) and x.
  29. Since gradients are calculated mathematically, they do have inaccuracies - but thankfully, they are rather low.
  30. Matrix Operations and Transformations
  31. Matrices or Multi-Dimensional Arrays Let's cover some basic functions to create numpy matrices 1. Matrices from 2D or 3D or ND Lists. 2. Ones, Zeros,and Identity.
  32. array() Method: It takes a 2D or 3D or ND List and returns a Numpy Multidimensional Array or Matrix. Creating Matrices using NumPy array method
  33. zeros(): Returns a Numpy Array of all zeros of given shape. Creating Matrices using NumPy Functions ones(): Returns a Numpy Array of all ones of given shape. identity(): Returns a 2D Identity Square Matrix of given Rows, Columns.
  34. Shape of np array shape: Returns the number of elements in each dimension of the np array. ndim: Returns the Number of Dimensions of the np array.
  35. Reshaping np arrays reshape(): Returns the reshaped np array if possible.
  36. Matrix Transformations : Addition Now we will look at a function to add two matrices: add() method : Takes Two numpy matrices of same size and adds them.
  37. C vs NumPy for matrix multiplication
  38. Matrix Transformations : Multiplication Now we will look at a function to multiply two matrices: element wise matrix multiplication : Multiplies matrices element by element just as add() does
  39. Matrix Multiplication - 1 matmul() method : Multiplies matrices just like you did in your JEE !
  40. Matrix Multiplication - 2 Another way of multiplying : :::;matrices: @ operator
  41. Matrix Transformations : Trace trace() method takes np array as input and outputs its trace.
  42. linalg.det() method takes np array as input and returns its determinant Matrix Transformations : Determinant
  43. Matrix Transformations : Transpose T attribute returns a matrix which is the transpose of the given Matrix.
  44. Numpy’s Reaction when you calculate inverse of a matrix on your own
  45. Matrix Transformations : Inverse linalg.inv() method takes matrix as input and return a matrix which is its inverse
  46. Matrix Transformation : Matrix Power linalg.matrix_power() takes a matrix and an integer as input and returns matrix raised to the power integer.
  47. Solving Linear Equation Quick Exercise! Given matrices A and B, can you calculate X such that AX = B using functions used so far ?
  48. Solving A linear equation Solving a linear equation can be cumbersome when the number of equations increases, numpy gets it done efficiently!
  49. Matrix Transformations : Stacking Stacking matrices in a new dimension has many uses. This can be implemented with the numpy stack() method
  50. Other Functions There are still a lot functionalities that NumPy offers like: Important Statistical Functions: mean(), median(), var()[For variance] ,std() [Standard Deviation] Functions for expanding and squeezing dimensions: squeeze(), expand_dims() These are left for you to explore !!!
  51. Resources! 1. Python Documentation 2. NumPy Documentation 3. Matplotlib Documentation
  52. Social Media - Epoch Follow our social media handles for regular updates Instagra m Twitter YouTube WhatsAp p
  53. Social Media - GDSC Follow our social media handles for regular updates Instagra m Twitter
  54. Any Questions or Suggestions?
  55. Thank You!