Introduction to Machine Learning with Python
Informal definition
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 can the focal length be automatically set 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 of tasks
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)
- Predicting 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 of training
Machine learning broadly describes approaches to data preparation, tuning, and evaluating predictive algorithms.
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 methods
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
from sklearn.model_selection import train_test_split
def get_demo_classification_data():
X, Y = make_moons(n_samples=3000, noise=0.3, random_state=0) # Generate data for classification
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.4, stratify=Y, random_state=0) # Split sample into training (60%) and testing (40%)
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 # Generate data for regression
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.4, random_state=0) # Split sample into training (60%) and testing (40%)
return X_train, X_test, Y_train, Y_testExamples 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.
Explore More IT Terms
#
- Using an integrating factor
- Equations in total differentials
- Bernoulli's equation
- Linear differential equations of the first order
- 10 Mixed C++ Challenges to Test Your Skills
- 11 Tricky Non-Technical Questions to Ask in a Recruiting Interview
- 50 Terms Every Programmer Should Know
- 52 Java Thread Interview Questions
- 7 Levels of Using the Zip Function in Python
- 7 Python Code Bugs You Need to Fix
- 70+ Free Resources for Learning Programming
A
- A Comprehensive Guide to HTML and CSS
- A Comprehensive Guide to MODX CMS
- A computer science question tests your ability to work with IP addresses and network masks
- A Guide to SQL Query Formatting for Beginners
- A/B testing
- Abstract Data Type (ADT)
- AES Encryption Algorithm: How It Works and Where It's Used
- Agile
- Algorithm
- Algorithm Analysis
- Algorithm Complexity-Key Points
- Algorithm complexity: deep parsing O(log n)
- Algorithm vs. Program
- Algorithms and Data Structures in C#
- An overview of the C # programming language
- An overview of the Python programming language
- Anaconda Python
- Analysis of graphs and adjacency matrices question
- Android
- Android App Bundle
- Android SDK
- Angular
- Ansible
- Apache
- Apache Airflow
- Apache Kafka
- Apache Tomcat
- App Store
- AppCode
- Applications of microcontrollers: From simple circuits in electronics to complex systems
- Applications of the derivative
- Arduino: How to Program It: Basics for Beginners
- Array-based stack
- ArrayList
- ASCII
- ASP.NET
- Assembly Language Lessons
B
C
- C++ Lessons
- Cache
- Calculating Memory Capacity
- Character sets and encodings
- Characteristics of a good Algorithm
- Circular singly linked list
- Coding Tests with Answers
- Combinational Circuits Solved Questions
- Compiler
- Complexity of algorithms-Tutorial
- Computer Science Fundamentals Test with Answers (47 questions)
- Computer science tests with answers (More than 100 Questions)
- Constants
- Creating a Table in HTML
- Creating Forms in HTML
- Creating Lists
- Cybernetics and informatics
- Cycles
D
- Data Analytics: applications of data analysis in companies
- Data Engineer - Who is it, what does a data engineer do, and an overview of the profession
- Data modeling: what it is, types, and process steps.
- Data preprocessing: a complete guide for beginners and professionals.
- Data structure
- Data Structures and Algorithms (DSA)
- Data types vs. Data structures
- Database Tests with Answers
- Deep Learning
- Defining Aliases
- Defining Arrays
- Deque
- Detailed articles and tutorials on PHP
- Developing a Website from Scratch
- Differential Equations
- Differentiation of functions
- Digital data: understand the importance of this asset for businesses.
- Double integrals
- Doubly linked lists
- DSA Tutorial
E
F
G
H
- Handling errors and exceptions
- Heads or Tails? How Probability Theory Is Used in IT
- History of the development of computer science
- Homogeneous equations
- Homogeneous vs. non-homogeneous structures
- How to convert numbers between binary, octal, and hexadecimal number systems
- How to effectively organize your workflow
- How to Learn Java: Tips for Beginner Developers
- How to Learn PHP: A Beginner's Guide
- How to Use S3 Storage in Kubernetes with CSI
- HTML
- HTML and CSS: Definition, Application, and Operating Principles
- HTML and CSS. Layout from Scratch: What to Learn, Where to Learn, and How Long Will It Take?
- HTML Frame Structure
- HTML Link Formatting
- HTML Quizzes with Answers
I
- if..else construction
- Infinite sequences and series
- Information properties
- Inheritance in Java: A Complete Guide to Principles and Implementation
- Inserting an Image
- Integration of functions
- Interactive Python Tutorial – Learn Programming from Scratch
- Interpreter
- Interview Problem: Finding a Deleted Element in O(N)
- Interview Scare: The FizzBuzz Challenge
- Introduction to C++
- Introduction to Machine Learning
- Introduction to Machine Learning with Python
- Introduction to Networking | Network Fundamentals Part 1
- Introduction to Number Systems (Binary, Octal, Hexadecimal) | Math for CS Foundations #1
- IT Specialist Resume (CV)
J
K
L
M
- Machine Learning
- Machine Learning Basic Tool: NumPy
- Machine Learning Basic Tool: Pandas
- Machine Learning Basics
- Machine Learning Mathematics
- Machine Learning with Python
- Mathematics for programmers: what is really needed?
- MD5 encryption algorithm: What is it and why is it needed?
- Microcontroller and Microprocessor - what's the difference?
- ML Engineer: Who They Are, What They Do, How Much They Earn, and How to Become a Neural Network Specialist
- Monte Carlo Simulation: How It Works and What It's For
O
P
- PHP lessons
- Private DNS server and its configuration
- Program code
- Programmer's Dictionary
- Programming
- Programming with pseudocode
- Python Code Formatting Guide: PEP8
- Python for data analysis: how to do it and main libraries
- Python Lessons
- Python Superstar: 5 Ways to Use the * Operator
- Python vs. Julia: Should You Replace Python with Julia?
Q
R
S
- Setting up model parameters
- SFML Graphics Library Tutorials
- Sorting Algorithms in Programming: Types, Descriptions, and Comparisons
- SQL commands: see what they are, what the main ones are + examples
- SQL Interview Questions and Tasks
- SQL Lessons
- SQL Stored Procedures
- SQL Syntactic Sugar: The COALESCE Function
- Stack
- Start in analytics: Python or R
- Static vs. dynamic data structures
- Statistical analysis: importance for decision making.
- String formatting in Python
- Structure of computer science
- Supervised learning
- Swift Lessons
- switch/match construct
- Syntax
T
- Terms in programming
- Text and paragraph formatting tags
- The Complete Guide to Bootstrap
- The Complete Guide to JavaScript
- The concept of information and its transmission
- The Future of Python: Key Trends and Insights from Global Researc
- The Infrastructure of Code: A Complete Guide to Repositories for Languages, Frameworks, and Compilers
- The pip package manager in Python
- The role of informatization in the development of society
- Transfers
- Tricky Java Questions Often Asked in Interviews
- Tutorials / Articles
- TypeScript: What It Is and Why Developers Need It
W
- What are databases, and why do they need DBMS and SQL?
- What do Linux distributions consist of?
- What is .NET and what is it used for?
- What is a data structure?
- What is a GPU in a computer, in simple terms?
- What is a quantum computer: 100,500 problems in one second
- What Is an Algorithm?
- What is Arduino: How it Works and the Platform's Capabilities
- What is Big Data? Introduction, Types, Characteristics, and Examples
- What is FizzBuzz Challenge?
- What is Golang and what is it used for?
- What is Haskell and what is it used for?
- What is Kotlin and what is it used for?
- What is Linux? The History of Linux
- What is machine learning, and how does it work?
- What is Power BI: everything about the data analytics software
- What is recursion, recursive and iterative process in programming?
- What is the C++ programming language?
- What is the OSI Model: A Complete Explanation of the Seven Layers and Their Role in Networking
- What's the difference between x86 and ARM processors?
- Where to start learning the C programming language?
- Which Linux distribution should you choose? A Linux distribution overview

