## 10 Fundamental Concepts with Python Implementations for Machine Learning. The bridge between math, code, and machine learning.

Never stop reading, coding, dreaming, coffee, repeating!

In the universe’s vision, mathematics guides machine learning. Merging Eastern with Western wisdom and South with North, with modern algorithms, we navigate, learn, and honor Science in the Dawn of AI. — By author

## Linear Algebra — Matrix Multiplication

**Concept**: Matrix multiplication is the cornerstone of many operations in machine learning, especially in neural networks.**Exercise**: Given two matrices, perform matrix multiplication.

`import numpy as np`

A = np.array([[1, 2], [3, 4]])

B = np.array([[2, 0], [1, 3]])

result = np.dot(A, B)

print(result)

**Output**

`[[ 4 6]`

[10 12]]

## Calculus — Gradient Descent *Concept:*

Gradient descent is an optimization algorithm used to minimize some function by iteratively moving in the direction of the steepest decrease of that function. *Exercise:* Implement a simple gradient descent to find the minimum of the function

`def gradient(x):`

return 2*xlr = 0.1

x = 10 # initial guess

for i in range(50):

x = x - lr * gradient(x)

print(x)

**Output:**

`0.00014272476927059603`

## Probability – Bayes’ Theorem *Concept:* Bayes’

The theorem describes the probability of an event based on prior knowledge. *Exercise:* Given a prior probability and likelihoods, compute the posterior probability using Bayes’ theorem.

`def bayes(prior, likelihood_true, likelihood_false):`

return (prior * likelihood_true) / ((prior * likelihood_true) + ((1 - prior) * likelihood_false))print(bayes(0.01, 0.9, 0.05))

**Output:**

`0.15384615384615385`