Article by Ayman Alheraki in March 17 2025 08:29 PM
In today's world, we frequently hear about "Machine Learning" and "Deep Learning," but what do these terms mean? How do these systems actually work? In this article, we will explain how intelligent models learn, how they read data, how they store information, and how the results are used in daily applications, with practical examples in Python.
Machine learning is a branch of artificial intelligence that allows computers to "learn" from data instead of being explicitly programmed. The core idea is that a computer takes in large amounts of data, looks for patterns and relationships within it, and then uses this information to make decisions or predictions without direct human intervention.
If we want to teach a computer to distinguish between images containing cats and those without, we provide it with thousands of labeled images (some with cats and some without). The system analyzes these images, identifies common features of cat images (such as ears, eyes, body shape), and then uses this knowledge to classify new images it has never seen before.
Learning in intelligent systems follows a mathematical model called the "learning model." There are two primary types of learning:
Supervised Learning: The system is given pre-labeled data (like the cat example above).
Unsupervised Learning: The system discovers patterns and relationships on its own without being given predefined answers (such as segmenting customers in sales based on their behavior).
The computer receives input data.
It processes the data using mathematical algorithms (neural networks or statistical models).
It updates its internal parameters based on the difference between its predictions and actual results.
This process repeats until the model achieves high accuracy in predicting new results.
xfrom sklearn.linear_model import LinearRegression
import numpy as np
# Training Data (Study Hours -> Exam Score)
x_train = np.array([[1], [2], [3], [4], [5]])
y_train = np.array([50, 55, 65, 70, 80])
# Creating a Machine Learning Model
model = LinearRegression()
model.fit(x_train, y_train)
# Predicting the score of a student who studied for 6 hours
prediction = model.predict([[6]])
print(f"Prediction for a student who studied 6 hours: {prediction[0]}")
When input data is fed into a machine learning model, it goes through several steps:
Data Cleaning: Removing invalid values, correcting errors, and converting data into a usable format.
Data Analysis: Transforming images, text, or numbers into a numerical representation that a computer can process.
Training and Storage: After processing the data, essential information is stored inside the model itself as "weights" and "parameters."
Where is the Data Stored?
Data is usually stored in large databases.
The trained model itself is saved as a file that can be reused later without needing retraining.
xxxxxxxxxx
import joblib
# Saving the trained model
joblib.dump(model, "trained_model.pkl")
# Loading the model later
loaded_model = joblib.load("trained_model.pkl")
prediction = loaded_model.predict([[7]])
print(f"Prediction for a student who studied 7 hours: {prediction[0]}")
Deep learning is an advanced form of machine learning that relies on "artificial neural networks," which simulate neural networks in the human brain. The main difference between traditional machine learning and deep learning is that deep learning can automatically extract features without requiring extensive human intervention.
Facial recognition in images relies on deep neural networks. Instead of manually defining features (such as eye shape or nose position), the model discovers these features itself by analyzing vast amounts of images.
xxxxxxxxxx
import tensorflow as tf
from tensorflow import keras
import numpy as np
# Creating a Simple Neural Network Model
model = keras.Sequential([
keras.layers.Dense(10, activation='relu', input_shape=(1,)),
keras.layers.Dense(1)
])
# Compiling the Model
model.compile(optimizer='adam', loss='mean_squared_error')
# Training Data
x_train = np.array([1, 2, 3, 4, 5], dtype=float)
y_train = np.array([50, 55, 65, 70, 80], dtype=float)
# Training the Model
model.fit(x_train, y_train, epochs=500, verbose=0)
# Making a Prediction
print(f"Prediction for a student who studied 6 hours: {model.predict([6])[0][0]}")
Once a model is trained, it can be used in various applications such as:
Facial Recognition (e.g., unlocking smartphones with face detection).
Self-Driving Cars (analyzing traffic signals and pedestrians to make decisions).
Medical Diagnosis (analyzing X-rays to detect tumors).
Automated Translation (such as Google Translate, which improves translation quality using machine learning).
Machine learning and deep learning are not just vague buzzwords; they are powerful tools transforming technology around us. Learning is based on analyzing data, discovering patterns, and storing information for future use. Thanks to these technologies, systems can make intelligent decisions and improve their performance over time without direct human intervention.
Using Python, developers can easily implement these techniques, as seen in the examples above. Libraries like scikit-learn
and TensorFlow
enable the creation of powerful models that mimic human intelligence in decision-making.