Introduction to Machine Learning
Informal
In our daily lives, we all face decisions every day:
- Given the current traffic situation, should I take the metro or drive?
- Should I delete the email as spam or keep it?
- Is rain expected, and should I take an umbrella?
- Should I call someone with a specific offer, or will they most likely refuse it?
- Should I buy more bread and milk, or will they last until the end of the week?
- What focal length should I set on my camera to ensure that the person I’m photographing is clearly visible?
Similar decision-making problems are being solved by organizations on a massive scale:
- How much bread and milk should the store buy to meet demand until the end of the week?
- How can a mail service automatically separate emails into useful and spam?
- What methods and routes should be used to send cargo?
- What weather forecast service will predict for the rest of the day?
- How to automatically set the focal length on manufactured cameras?
When making decisions on a large scale and repetitively, it makes sense to automate the process. We can develop an explicit system of rules for this process. For example, when determining the importance of an email, we might consider whether we’ve previously corresponded with the sender, whether the sender belongs to a reliable and well-known company, and whether the email text includes certain keywords that we’re not initially interested in. In this case, we’re explicitly programming the decision-making algorithm. But the problem is that
- It’s difficult to develop a universal algorithm that would suit all users. Some may not be interested in obtaining a loan or psychological counseling, while others may find these relevant.
- It’s difficult to account for the wide variety of situations. For example, “free psychological consultation” could be rephrased as “a free consultation with a psychologist,” and the original rule would no longer apply.
In such cases, it is useful to use machine learning.
Machine learning is a process by which a computer learns to better solve a given problem using observed data. The solution is sought within a broad class of functions, parameterized by a vector of parameters, which is then selected based on the observed data.
Instead of explicitly defining a clear system of decision-making rules, machine learning utilizes these rules to automatically generate data. A computer can be any computing device, such as a smartphone or a robot’s processor. Let’s consider a more detailed definition:
A machine learns from a given experience to solve a certain problem , with respect to a certain quality indicator , if the quality indicator increases on the problem after gaining experience.
In our example, the task is to classify emails as spam/not spam, the quality indicator is the proportion of correctly classified emails, and the experience is a collection of past emails that were previously manually labeled into classes.
In another example, the task is to predict travel time based on the current time of day, day of the week, weather, and road congestion; the quality indicator is the absolute deviation of the predicted time from the actual time; and the experience is the history of previous movements under known conditions and with known travel times.
Examples
Here are some examples of popular problems solved using machine learning:
- Predict whether a customer will switch to a competitor (churn prediction)
- Is a sequence of financial transactions fraudulent? (fraud detection)
- Prediction of traffic jams and travel times when planning a route (traffic prediction).
- Should a given product be shown to the buyer as a recommendation? (recommender systems)
- Should I recommend someone as a friend on a social network?
- Is a social media account a bot?
- Voice assistant: speech recognition, automatic answering of questions, speech response generation.
- Facial identification. License plate recognition on cameras.
- Counting and tracking people using CCTV cameras (object tracking). Detecting unlawful actions (activity recognition).
- Self-driving cars: situation recognition, route planning.
- Automatic trading on the stock exchange (algorithmic trading).
- Translation from one language to another (machine translation).
- Making medical diagnoses based on patient complaints and examination results.
- Recommending web pages based on a search query (information retrieval).
- Automatic assessment of a candidate’s expected salary based on their resume.
- Computer chess game, control of game characters.
- Automatic assessment of an apartment based on its characteristics.
- Does the user praise or criticize the product in their review? (sentiment analysis)
- Generating illustrations for text. Text description of what is shown in the image.
- Weather forecast. Recommendations for farmers on when to plant/water/fertilize crops.
- Automatic writing of program code (no code AI).
- Automatic selection of which online advertisements to show to which users (targeted ads).
- Generation of chemical compounds with the required properties:
- strong, yet lightweight and heat-resistant material with increased conductivity (material design)
- a drug that provides treatment and has minimal side effects (drug discovery)
Types
Machine learning broadly describes approaches to data preparation, tuning, and evaluating predictive algorithms. This is the topic of the site’s first book, which you’re reading now.
Deep learning is a subset of machine learning that focuses on complex multilayer models (neural networks) capable of solving more complex forecasting problems. With increasing computing power and data volumes, there is a steady trend toward replacing classical machine learning algorithms with neural network-based ones, which provide greater accuracy and the ability to generate not only numerical answers but also answers in the form of complex structured data, such as text, speech, images, and video.
Reinforcement learning is also a subset of machine learning, in which a one-time prediction is not made independently for each object, but an interactive strategy for behavior in a changing environment is developed.
An example of reinforcement learning is automated chess, where each subsequent move must be sequentially generated. The success of the generation is determined not only by the current move but also by the entire sequence of decisions made throughout the game. Reinforcement learning is also used to control game characters, self-driving cars, drones, advanced chatbots, and robotic assistants.
Code examples for running
Many of the methods described in the tutorial are accompanied by examples of running them in Python using the sklearn,, numpyand libraries. Versions 1.3.0, 1.26.0, and 3.8.4 of these libraries were used, respectively. The free JupyterLabmatplotlib development environment is convenient for data analysis and testing various machine learning methods. For ease of installation, the Anaconda package manager is recommended. The following functions are used in the examples provided to generate data:
import numpy as np
from sklearn.datasets import make_moons
def get_demo_classification_data():
X,Y = make_moons(n_samples=3000, noise=0.3 ,random_state=0)
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.4, stratify=Y, random_state=0)
return X_train, X_test, Y_train, Y_test
def get_demo_regression_data():
np.random.seed(0)
X = np.random.normal(size=[3000,5])
NOISE = 0.3*np.random.normal(size=[3000])
Y = X.mean(axis=1)+(X**2).mean(axis=1)+NOISE
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.4, random_state=0)
return X_train, X_test, Y_train, Y_test
Examples of running methods will follow the description of the methods themselves, but you can also view the code for all examples at once by following the link with the results of their execution.