Difference Between AI, ML, and Deep Learning

Tutorial 2 of 5

1. Introduction

In this tutorial, we aim to clarify the differences and relationships between Artificial Intelligence (AI), Machine Learning (ML), and Deep Learning (DL). Although these terms are often used interchangeably, they each refer to distinct concepts in the realm of intelligent systems.

By the end of this tutorial, you will have a clear understanding of what AI, ML, and DL are, how they relate to each other, and the practical applications of each.

This tutorial is suitable for beginners and doesn't require any prerequisites.

2. Step-by-Step Guide

2.1 Artificial Intelligence (AI)

Artificial Intelligence refers to the simulation of human intelligence processes by machines, especially computer systems. These processes include learning, reasoning, problem-solving, perception, and language understanding.

AI is classified into two types:

  • Weak AI: Designed to perform a narrow task (e.g., voice recognition).
  • Strong AI: Also known as General AI, it performs any intellectual task that a human being can do.

2.2 Machine Learning (ML)

Machine Learning is a subset of AI that provides systems the ability to learn and improve from experience without being explicitly programmed. It focuses on the development of computer programs that can access data and use it to learn for themselves.

There are three types of learning in ML:

  • Supervised Learning: The model learns from labeled data.
  • Unsupervised Learning: The model learns from unlabeled data.
  • Reinforcement Learning: The model learns by interacting with its environment.

2.3 Deep Learning (DL)

Deep Learning is a subset of ML that imitates the workings of the human brain in processing data for use in decision making. DL uses artificial neural networks with several layers (hence the 'deep' in deep learning).

3. Code Examples

In this section, we'll use Python's sklearn library for ML examples and keras for DL examples. Note that these are not AI code examples, since AI is a broader concept that encompasses ML and DL.

3.1 Machine Learning Example

This is an example of supervised learning. We'll use a simple linear regression model to predict house prices based on a single feature.

# Import necessary libraries
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
import numpy as np

# Assume we have the following data
# house_sizes = size of the house in square feet
# house_prices = price of the house in thousands of dollars

house_sizes = np.array([1500, 2000, 2500, 3000, 3500])
house_prices = np.array([200, 250, 300, 350, 400])

# Reshape the data since we only have one feature
house_sizes = house_sizes.reshape(-1, 1)

# Split the data into training set and test set
X_train, X_test, y_train, y_test = train_test_split(house_sizes, house_prices, test_size=0.2, random_state=42)

# Create a linear regression model
model = LinearRegression()

# Train the model
model.fit(X_train, y_train)

# Predict house price for a new house size
new_house_size = np.array([3200]).reshape(-1, 1)
predicted_price = model.predict(new_house_size)

print(f'The predicted price for a house of size {new_house_size[0][0]} sq ft is {predicted_price[0]} thousand dollars.')

3.2 Deep Learning Example

This is a simple DL example using Keras to classify handwritten digits using the MNIST dataset.

# Import necessary libraries
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense
from keras.utils import np_utils

# Load data
(X_train, y_train), (X_test, y_test) = mnist.load_data()

# Flatten 28*28 images to a 784 vector for each image
num_pixels = X_train.shape[1] * X_train.shape[2]
X_train = X_train.reshape((X_train.shape[0], num_pixels)).astype('float32')
X_test = X_test.reshape((X_test.shape[0], num_pixels)).astype('float32')

# Normalize inputs from 0-255 to 0-1
X_train = X_train / 255
X_test = X_test / 255

# One hot encode outputs
y_train = np_utils.to_categorical(y_train)
y_test = np_utils.to_categorical(y_test)
num_classes = y_test.shape[1]

# Define model
model = Sequential()
model.add(Dense(num_pixels, input_dim=num_pixels, kernel_initializer='normal', activation='relu'))
model.add(Dense(num_classes, kernel_initializer='normal', activation='softmax'))

# Compile model
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])

# Fit the model
model.fit(X_train, y_train, validation_data=(X_test, y_test), epochs=10, batch_size=200, verbose=2)

# Final evaluation of the model
scores = model.evaluate(X_test, y_test, verbose=0)
print("Baseline Error: %.2f%%" % (100-scores[1]*100))

4. Summary

In this tutorial, we've covered the differences and relationships between AI, ML, and DL. We've learned that ML is a subset of AI that focuses on the ability of machines to receive a set of data and learn for themselves, changing their behavior based on what they learn. DL, on the other hand, is a subset of ML that uses the concept of neural networks to solve complex problems.

5. Practice Exercises

  1. Use the sklearn library to write a program for a classification problem using supervised learning. Use any sample dataset of your choice.

  2. Write a deep learning program using the keras library to solve a problem of your interest.

  3. (Advanced) Implement a reinforcement learning model to play a simple game like tic-tac-toe. You can use any library of your choice.

Remember, practice is key to mastering these concepts. Happy coding!