Winnipeg Ideas

Jul 03, 2026 RAW
Article

Machine Learning: Simple Example

Machine Learning: A Simple Example

Machine Learning (ML), a subset of Artificial Intelligence (AI), is a fascinating field that enables systems to learn and improve from experience without being explicitly programmed. To understand its basics, let's explore a simple example: predicting whether a passenger survived the Titanic disaster based on their features like age, sex, and passenger class.

the machine learning poster is shown in purple and black ink, with instructions on how to use
the machine learning poster is shown in purple and black ink, with instructions on how to use

Preparing the Dataset

the info sheet shows how to learn machine learning and how to use it for teaching
the info sheet shows how to learn machine learning and how to use it for teaching

The Titanic dataset is a classic example in ML, containing information about passengers who embarked on the ship's ill-fated maiden voyage. We'll use this dataset to build our simple ML model. The dataset can be found in the Kaggle Titanic dataset.

Exploring the Dataset

Machine Learning Explained in 60 Seconds: A Beginner's Guide
Machine Learning Explained in 60 Seconds: A Beginner's Guide

Let's explore the dataset using Python and its libraries, such as pandas for data manipulation and seaborn for visualization.

```python import pandas as pd import seaborn as sns # Load the dataset data = pd.read_csv('titanic.csv') # Display the first few rows print(data.head()) # Check for missing values print("\nMissing values:\n", data.isnull().sum()) ```

Data Preprocessing

Regression Algorithms in Machine Learning Explained Visually
Regression Algorithms in Machine Learning Explained Visually

Before feeding the data into our ML model, we need to preprocess it. This involves handling missing values, encoding categorical variables, and scaling numerical features.

Handling Missing Values

In our dataset, the 'Age' and 'Embarked' columns have missing values. We can fill these with appropriate values based on the available data.

the word of the day machine learning
the word of the day machine learning

```python # Fill missing 'Age' with median age data['Age'].fillna(data['Age'].median(), inplace=True) # Fill missing 'Embarked' with the most frequent value data['Embarked'].fillna(data['Embarked'].mode()[0], inplace=True) ```

Encoding Categorical Variables

Machine Learning algorithms can't process categorical data, so we need to convert categorical variables like 'Sex' and 'Embarked' into numerical data using one-hot encoding.

```python data = pd.get_dummies(data, columns=['Sex', 'Embarked'], drop_first=True) ```

Scaling Numerical Features

Machine Learning Made Stupid-Simple: How AI Learns Like a Human!"
Machine Learning Made Stupid-Simple: How AI Learns Like a Human!"

To bring all features to a similar scale, we'll use standardization.

```python from sklearn.preprocessing import StandardScaler # Select numerical features num_features = ['Pclass', 'Age', 'SibSp', 'Parch', 'Fare'] # Initialize the scaler scaler = StandardScaler() # Fit and transform the scaler on the selected features data[num_features] = scaler.fit_transform(data[num_features]) ```

Building the Machine Learning Model

Machine Learning for Beginners Complete Guide (2026) | AI & ML Roadmap
Machine Learning for Beginners Complete Guide (2026) | AI & ML Roadmap
a poster with instructions on machine learning for beginners to learn how to use it
a poster with instructions on machine learning for beginners to learn how to use it
What Is Machine Learning? (Beginner-Friendly Guide)
What Is Machine Learning? (Beginner-Friendly Guide)
Naive Bayes Made Simple with Easy AI Examples
Naive Bayes Made Simple with Easy AI Examples
AI vs ML vs DL – Easy Diagram
AI vs ML vs DL – Easy Diagram
Machine Learning Made Stupid-Simple: How AI Learns Like a Human!"
Machine Learning Made Stupid-Simple: How AI Learns Like a Human!"
Machine Learning Roadmap for Complete Beginners 🤖
Machine Learning Roadmap for Complete Beginners 🤖
Machine Learning Roadmap Checklist for Beginners
Machine Learning Roadmap Checklist for Beginners
Machine Learning
Machine Learning
Machine Learning Engineer Roadmap 2025: Skills, Projects & Learning Path 🚀
Machine Learning Engineer Roadmap 2025: Skills, Projects & Learning Path 🚀
the machine learning poster shows how to use it for teaching and other activities, including math skills
the machine learning poster shows how to use it for teaching and other activities, including math skills
Types of machine learning models
Types of machine learning models
Machine Learning Workflow Explained
Machine Learning Workflow Explained
Machine Learning vs Artificial Intelligence — Simple Explanation for Beginners 2026
Machine Learning vs Artificial Intelligence — Simple Explanation for Beginners 2026
MACHINE LEARNING IN POWER SYSTEMS
MACHINE LEARNING IN POWER SYSTEMS
What Are Machine Learning Algorithms? Simple AI Guide
What Are Machine Learning Algorithms? Simple AI Guide
Machine Learning Roadmap for Beginners (2026 Guide 🚀)
Machine Learning Roadmap for Beginners (2026 Guide 🚀)
How AI Actually Works: A Simple, Step-by-Step Guide for the Rest of Us 💡
How AI Actually Works: A Simple, Step-by-Step Guide for the Rest of Us 💡
Machine Learning For Beginners: Absolute Beginners Guide, Learn Machine Learning And Artificial Intelligence From Scratch - 9781738901999
Machine Learning For Beginners: Absolute Beginners Guide, Learn Machine Learning And Artificial Intelligence From Scratch - 9781738901999
Probability Explained for Beginners
Probability Explained for Beginners

Now that our data is preprocessed, we can build our ML model. For this example, let's use a simple Logistic Regression model from scikit-learn.

Splitting the Dataset

We'll split the dataset into training and testing sets using an 80:20 ratio.

```python from sklearn.model_selection import train_test_split # Define features (X) and target (y) X = data.drop('Survived', axis=1) y = data['Survived'] # Split the dataset X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) ```

Training the Model

Let's train our Logistic Regression model on the training dataset.

```python from sklearn.linear_model import LogisticRegression # Initialize the model model = LogisticRegression() # Fit the model on the training data model.fit(X_train, y_train) ```

Evaluating the Model

To evaluate our model's performance, we'll use it to make predictions on the testing dataset and compare them to the actual values.

```python from sklearn.metrics import accuracy_score, classification_report # Make predictions on the testing data y_pred = model.predict(X_test) # Evaluate the model print("Accuracy:", accuracy_score(y_test, y_pred)) print("\nClassification Report:\n", classification_report(y_test, y_pred)) ```

Interpreting the Results

After evaluating our model, we can interpret the results to understand which features were most important in predicting whether a passenger survived the Titanic disaster. We can use feature importance techniques or simply look at the coefficients of our Logistic Regression model.

In this simple example, we've demonstrated the basic steps involved in building a Machine Learning model: preparing the dataset, preprocessing the data, splitting the dataset, training the model, evaluating the model, and interpreting the results. By following these steps, you can apply Machine Learning to various problems and datasets.