Machine Learning 1 Lecture Notes PDF
Document Details

Uploaded by KnowledgeableAbundance
Tags
Summary
These lecture notes cover the fundamentals of machine learning, focusing on supervised learning techniques like regression and classification. They explore different types of machine learning and include visual aids like charts and graphs.
Full Transcript
Machine Learning 1 Week 1 - Lecture Agenda Course Introduction Supervised Machine Learning Course Introduction Book https://www.statlearning.com/ Syllabus Syllabus cont’d Blackboard DataCamp Supervised Machine Learning What is Supervised Machine Learning...
Machine Learning 1 Week 1 - Lecture Agenda Course Introduction Supervised Machine Learning Course Introduction Book https://www.statlearning.com/ Syllabus Syllabus cont’d Blackboard DataCamp Supervised Machine Learning What is Supervised Machine Learning, and Why Do We Use it? Is this a Tree? Learning from Data Learning from Data The learning algorithm will discover statistical patterns in the data The learning is done by making small, iterative adjustments Model Model https://crossingsauthor.com/2023/11/17/404-totally-true- tales-of-troublesome-tires/ Learning by Trial and Error Image source: https://www.gettingready4baby.org/playing Machine Learning Arthur Samuel (1959). Machine Learning: Field of study that gives computers the ability to learn without being explicitly programmed. Machine Learning Herb Simon (1978). Machine Learning is concerned with computer programs that automatically improve their performance through experience. Machine Learning Tom Mitchell (1997). A computer program is said to learn from experience E with respect to some task T and some performance measure P, if its performance on T, as measured by P, improves with experience E. Task T : Performance measure P : Training experience E: ad Why Now? More Data Increased Computational Power Progress on algorithms, theory & tools Accessible Computing Categories of Machine Learning Labeled data Supervised Learning Direct feedback Predict outcome/future Supervised Learning: Regression y x Supervised Learning: Classification x2 x1 Categories of Machine Learning Labeled data Supervised Learning Direct feedback Predict outcome/future No labels/targets Unsupervised Learning No feedback Find hidden structure in data Unsupervised Learning -- Clustering x2 x1 Categories of Machine Learning Labeled data Supervised Learning Direct feedback Predict outcome/future No labels/targets Unsupervised Learning No feedback Find hidden structure in data Decision process Reinforcement Learning Reward system Learn series of actions Reinforcement Learning Environment Reward State Action Agent Supervised Machine Learning Regression tasks: when the output is a continuous variable. Classification tasks: when the output is a discrete variable. Supervised Machine Learning Use training examples to estimate a function 𝑓𝑓̂ that 𝑥𝑥1 Unknown target function captures the relationship 𝑓𝑓: between the inputs and Input variables 𝑥𝑥2 y = 𝑓𝑓 𝑥𝑥1 , 𝑥𝑥2 , … 𝑥𝑥𝑝𝑝 + 𝜖𝜖 output. where 𝜖𝜖 is random error Observed: 𝑦𝑦.. Learning Algorithm A Predicted: 𝑦𝑦. Estimated function 𝑓𝑓: ̂ Goal is to use Learning 𝑥𝑥𝑝𝑝 𝑦𝑦 = 𝑓𝑓̂ 𝑥𝑥1 , 𝑥𝑥2 , … 𝑥𝑥𝑝𝑝 Algorithm A to infer a function 𝑓𝑓̂ that can predict the output 𝑦𝑦 Source accurately given new inputs. Abu-Mostafa, Y. S., Magdon-Ismail, M., & Lin, H. T. (2012). Learning from data (Vol. 4). New York, NY, USA: AMLBook. Supervised Machine Learning The algorithm learns to predict output given input by observing training examples in the form of pairs. The algorithm performance is measured based on how well the model predicts the outcome on test examples. The goal to for the model to perform well on new unseen examples. This is known as generalization. Supervised Machine Learning obs. X Y 1 5.0 217.4 2 9.7 184.2 3 14.5 188.3 Training examples 4 19.2 189.5 5 23.9 218.0 6 28.7 230.8 7 33.4 263.9 8 38.2 293.0 9 42.9 304.2 10 47.6 325.9 11 52.4 343.0 12 57.1 337.8 13 61.8 347.2 14 66.6 336.9 15 71.3 343.3 16 76.1 329.3 17 80.8 337.1 18 85.5 348.3 19 90.3 355.2 20 95.0 392.1 Test examples 21 7.0 204.3 22 16.3 235.5 23 25.7 242.5 24 35.0 272.4 25 44.3 283.8 26 53.7 279.7 27 63.0 335.8 28 72.3 342.0 29 81.7 356.8 30 91.0 388.2 We can use training examples (shown in red) to learn the relationship between input variable 𝑋𝑋 and output variable 𝑌𝑌. Our goal is to use the learned relationship to accurately predict 𝑌𝑌 for the test examples (shown in blue). Can you think of classification problems? Classification Many predictive problems are framed as binary classification problems. Will this customer leave us if the price of oil drops below X? Will this unit fail in the next 30 days? Will this construction site run out of fuel tomorrow? Is this a fraudulent transaction? Does this X-ray image represent a patient with Pneumonia? – Will this customer default on a loan? – Will this image trigger a person to click on my offer? Can you think of regression problems? Regression How much? Prices How many? Retweets How can we evaluate regression and classification models? Evaluating a Regression Model For continuous output, the quality of a model 𝑓𝑓̂ may be measured by the mean squared error: 1 𝑛𝑛 2 𝑀𝑀𝑀𝑀𝑀𝑀 = ∑𝑖𝑖=1 𝑦𝑦𝑖𝑖 − 𝑓𝑓̂ 𝑥𝑥𝑖𝑖 , where 𝑓𝑓̂ 𝑥𝑥𝑖𝑖 is the predicted 𝑛𝑛 value that 𝑓𝑓̂ returns for observation 𝑖𝑖. Evaluating a Regression Model Regression Model Overfitting The Bias Variance Tradeoff Simpler models can oversimplify the relationships between input features and prediction labels. High bias Low Variance Underfitting Complex models can be sensitive to noise and may not generalize well to new unseen examples. Low Bias High Variance Overfitting Evaluating a Classification Model For classification problems, the quality of a model 𝑓𝑓̂ may be measured by the proportion of correctly classified observations (accuracy) and the expected cost of misclassification (estimated from its confusion matrix). 𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶 𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃 Accuracy = 𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇 𝑂𝑂𝑂𝑂𝑂𝑂𝑂𝑂𝑂𝑂𝑂𝑂𝑂𝑂𝑂𝑂𝑂𝑂𝑂𝑂𝑂𝑂𝑂𝑂 Evaluating a Classification Model We are more interested in evaluating the accuracy of the model on the test set than the training set. The test accuracy is a better indicator of the ability of the model to generalize to new unseen examples. Note that accuracy can provide a misleading measure of the quality of a predictive model for an imbalanced data set. Evaluating a Classification Model Evaluation should be based on test samples that are not used for training the model. TP: Positive example predicted as positive FN: Positive example predicted as negative FP: Negative example predicted as positive TN: Negative example predicted as negative Predicted Positive Negative Positive TP FN Actual Negative FP TN Confusion Matrix Structure of Training and Prediction Split data: X_train, y_train; X_test; y_test = splitData(X, y) Create model: model = modelName(parameters) Train model: model.fit(X_train, y_train) where: x_train: inputs for training examples, y_train: outputs for training examples Predict with trained model on test examples: y_predicted = model.predict(X_test) where: x_test: inputs for examples to predict Check predictive accuracy of trained model on test examples: accuracy_score(y_test, y_predicted) where: y_test: correct outputs for predicted examples