Machine Learning
2 min read
Introduction
I have been working with LLM models for a while now, and every day I'm fascinated by how good they are becoming. However, they still have plenty of shortcomings.
A few days ago, I realized I have a passion for AI and decided to dive deeper into the field. I started by taking a course on Coursera for ML, and I'm loving it!
I've learned so many things in a short amount of time and finally put the linear algebra course that I took in my first year of university to use. Here is some of what I've learned.
Some basics
I'm going to summarize every major topic I've learned, so it might not be too intuitive, but here we go! Keep in mind that I'm still learning these topics and am no expert.
Supervised learning is when the model is trained on labeled data. An example is predicting house prices based on different parameters such as size and the number of bedrooms, given already known house prices and their parameters.
Unsupervised learning is when the model is trained on unlabeled data. An example is clustering similar articles together based on their content. This is different from supervised learning, as there are no labels to guide the model.
Linear regression is a supervised learning algorithm that uses an optimization algorithm like gradient descent or the normal equation to minimize the cost function (the difference between the predicted value and the actual value) and create a line of best fit. This best fit line doesn't have to be a straight line; it could be a polynomial if that would better fit the data.
Why Linear Algebra?
When I was taking Math 211 at university, I couldn't imagine a use case for linear algebra, but recently I found out it's quite useful. Using matrices and vectors is essential in ML for mapping out parameters, expected values, and performing complex operations on them.
Take the normal equation, for example; linear algebra is fundamental for performing optimization using it. Linear algebra becomes even more useful when the number of parameters increases.
Logistic Regression
Logistic regression is a supervised learning algorithm used for binary classification tasks. Unlike linear regression, which predicts a continuous value, logistic regression predicts the probability that an input belongs to a particular class.
The key to logistic regression is the use of the sigmoid function, which transforms the output into a probability between 0 and 1. This allows logistic regression to classify data points based on a threshold, typically 0.5.
The cost function for logistic regression is the binary cross-entropy or log-loss, which measures how well the predicted probabilities match the actual binary outcomes.
Regularization
Regularization is a technique to prevent overfitting by adding a penalty to the model's cost function. In logistic regression, common regularization techniques include L1 (Lasso) and L2 (Ridge) regularization.
L2 regularization penalizes large coefficients by adding the squared magnitude of coefficients to the cost function, helping to reduce variance without increasing bias too much. L1 regularization, on the other hand, adds the absolute value of coefficients, often resulting in sparse models by driving some coefficients to zero.
The regularization parameter, lambda, controls the strength of the penalty. A higher lambda value increases the regularization effect, which can be useful when working with a large number of features.