Перейти к содержимому

What Is Machine Learning, Really? (With Real Code)

Just Known Dev

0:00 / 0:00

What Is Machine Learning, Really? (With Real Code)

26 просмотров · 7 дн. назад
Just Known Dev
75 подписчиков
26 просмотров · 7 дн. назад
Regular code: you write the rules. Machine learning: you give it examples with the answers, and it works out the rules itself. From a spam filter that breaks to features and labels, models as functions with knobs, generalization, the three kinds of learning (and how ChatGPT used all three), the ML workflow and what biased data does. Then real code: scikit-learn finds a rule I hid in made-up data, and a decision tree prints the rules it learned from the Iris flowers. Episode 2 of "From a Straight Line to ChatGPT", a full series on AI, machine learning and deep learning for developers and interview prep. ⏱ Chapters 0:00 Intro 1:16 Rules in, answers out 2:01 Examples, features, labels 2:38 A model is a function with knobs 3:43 The real goal: new examples 4:25 Supervised learning: regression and classification 4:58 Unsupervised learning 5:27 Reinforcement learning 6:00 ChatGPT used all three 6:33 The machine learning workflow 7:24 What can go wrong: garbage in, garbage out 8:35 Try it yourself 10:12 When not to use machine learning 10:48 Interview corner 11:53 Recap and next stop 🧪 Try it yourself (Python) pip install numpy scikit-learn import numpy as np from sklearn.linear_model import LinearRegression Made-up deliveries. Hidden rule: 8 minutes + 3 per km, plus some randomness rng = np.random.default_rng(1) km = rng.uniform(1, 10, size=10).round(1) minutes = (8 + 3 * km + rng.normal(0, 3, size=10)).round() model = LinearRegression() model.fit(km.reshape(-1, 1), minutes) # answers in... print(f"learned: {model.coef_[0]:.2f} min per km + {model.intercept_:.2f}") # ...rule out print("6.0 km:", model.predict([[6.0]])[0].round(1), "min") Real data: the Iris flowers from sklearn.datasets import load_iris from sklearn.model_selection import train_test_split from sklearn.tree import DecisionTreeClassifier, export_text iris = load_iris() X_train, X_test, y_train, y_test = train_test_split( iris.data, iris.target, test_size=0.2, random_state=0, stratify=iris.target) tree = DecisionTreeClassifier(max_depth=2, random_state=0).fit(X_train, y_train) print("test accuracy:", tree.score(X_test, y_test)) print(export_text(tree, feature_names=iris.feature_names, class_names=list(iris.target_names))) What we got: 3.17 min per km + 6.52 (the hidden rule was 3 and 8), 25.5 min for 6 km, and 28 of 30 test flowers right (93.3%). Try changing the hidden rule, or the noise, and see how close the model gets. 🧠 Cheat sheet Regular code: rules + data → answers. Machine learning: data + answers → rules (a model) Example = one row · features = the inputs · label = the answer you want to predict A model = a function with adjustable numbers (parameters, the "knobs"); training finds settings that match the examples Supervised: labeled examples → regression (a number) or classification (a category) Unsupervised: no labels → find structure (clusters, unusual cases) Reinforcement: no answers, just rewards → learn by trial and error Workflow: data → split (hold out a test set, often about 20%) → train → evaluate → deploy → monitor → retrain The goal is generalization: doing well on examples the model has never seen Use ML when the rules are too many or too fuzzy to write, you have lots of good examples, and being wrong sometimes is OK 📚 Sources Samuel, machine learning and checkers (IBM Journal, 1959): https://doi.org/10.1147/rd.33.0210 Paul Graham, A Plan for Spam (2002): https://paulgraham.com/spam.html Chollet, Deep Learning with Python, ch. 1 (the rules/answers framing): https://www.manning.com/books/deep-le... Reuters on Amazon's recruiting tool (Oct 2018): https://www.reuters.com/article/us-am... Gender Shades (Buolamwini & Gebru, 2018): https://proceedings.mlr.press/v81/buo... AlphaGo (Silver et al., Nature, 2016): https://doi.org/10.1038/nature16961 InstructGPT (Ouyang et al., 2022): https://arxiv.org/abs/2203.02155 Introducing ChatGPT (OpenAI, 2022): https://openai.com/index/chatgpt/ Fisher's Iris paper (1936; data by Edgar Anderson): https://doi.org/10.1111/j.1469-1809.1... 📚 Series: From a Straight Line to ChatGPT AI01 What Happens When You Ask ChatGPT a Question? AI02 What Is Machine Learning, Really? ← you are here AI03 How Machines Learn: Linear Regression & Gradient Descent … full playlist: {{PLAYLIST_URL}} Just Known: from unknown to known. A channel by Just Unknown. Note: the delivery data is made up from a hidden rule (as the video says); every model number on screen is real output from the code above, and the Iris data is real. Pictures marked "illustration" are not data. ChatGPT is a trademark of OpenAI; this channel isn't affiliated with OpenAI. #ai #machinelearning #python #scikitlearn #computerscience #codinginterview