01 Introduction & Linear Regression
🎲 Random

Դե, բարի գալուստ ՄԼ-ի կտոր :^)
📚 Նյութը
- 📺 Introduction & Linear Regression, 🎞️ Սլայդեր, 📝 Նշումներով
- 📺 Design matrix, normal equation, polynomial regression, 🎞️ Սլայդեր, 📝 Նշումներով
- 📺 Data preprocessing: missing data, categorical encoding, scaling, 🎞️ Սլայդեր, 📝 Նշումներով
Սլայդերի մեծ մասը հիմնված ա LMU Munich SLDS — Introduction to Machine Learning (I2ML) բաց նյութերի վրա։
🏡 Տնային
Two assignments. Assignment 1 is pure implementation (no scikit-learn); Assignment 2 is a practical end-to-end workflow.
Assignment 1 — Linear regression from scratch
Use the dataset data_lin_reg.csv (two columns, x and y). Only the libraries we have covered so far (numpy, pandas, matplotlib) — no scikit-learn.
- Load the data with pandas and make a scatter plot.
- Implement gradient descent for the model \(\hat{y} = \theta_0 + \theta_1 x\). Write down the L2 empirical risk \(R(\theta) = \frac{1}{n}\sum_i (\hat{y}_i - y_i)^2\) and derive its gradient.
- Tune the learning rate \(\alpha\). Plot iterations vs. risk for a few values of \(\alpha\) (one too small, one good, one that diverges).
- Implement the normal equation using the design matrix \(X\) (with the column of ones). Confirm that gradient descent and the closed-form solution give the same \(\theta\).
- Plot the data together with the fitted line and the predictions. Report the final formula.
- Polynomial regression: extend the design matrix to degree \(d\) (e.g. \(\theta_0 + \theta_1 x + \theta_2 x^2 + \dots\)), fit it with the normal equation, and plot the fit for a few degrees. What happens as \(d\) grows?
Additional
- Plot a histogram of the residuals.
- Plot the risk surface (or a \(\theta_0\)–\(\theta_1\) contour) and overlay the gradient-descent trajectory on it.
- Vectorize everything — no Python loops over individual samples.
Assignment 2 — Practical regression with scikit-learn
Use the dataset House_Rent_Dataset.csv. Build a full pipeline and interpret the result — don’t just call .fit().
- EDA: load the data,
describe()it, visualize the target and the feature distributions, and note any problems. - Missing data: detect it and decide how to handle it (drop vs. impute) — justify your choice.
- Encode categorical features: choose One-Hot / Ordinal / Target encoding per feature and justify each. (Remember the trap: don’t label-encode an unordered category as if it were ordered.)
- Scale the features (StandardScaler or MinMaxScaler) and explain when scaling matters for linear regression.
- Interpret the coefficients: sort them by absolute value. Which features matter most? Does it make sense?
Additional
- Add polynomial features and watch the model start to learn the noise in the data and lose generalizability.
Helpful links to get started with scikit-learn:
- Getting Started with scikit-learn
- User Guide: Preprocessing data (encoders, scalers, polynomial features)
LinearRegressionAPI reference