You are on page 1of 8

PAF- KARACHI INSTITUTE OF ECONOMICS & TECHNOLOGY

College of Engineering

(Software Engineering)

Artificial Intelligence

Semester: ______________________ Date of Experiment: _____________________

Student name: __________________ Faculty Signature: ______________________

Student ID: ____________________

Lab08
Machine Learning Algorithm (Decision Tree)

PLO1 – Engineering Knowledge C1 – Recall


PLOs PLO3 – Design & Development Bloom’s Taxonomy C3 - Apply
PLO8 – Ethics P2 – Set
LAB TASK PERFORMANCE
Excellent Average Poor
CLO’s Aspects of Assessments Marks
(75-100%) (50-75%) (<50%)
CLO1 Student lacks clear
Recall The associated Complete understanding of Complete understanding of
understanding of concepts of
10% concepts of Programming Programming / actively Programming / less actively
Programming / Unable to read
Language. participate during lecture. participate during lecture.
and interpret it.

Design & Develop ML


CLO4 Accurately implement the Implement the Decision Tree Not able to implement the
Design/Develop solutions for
Decision Tree Model and Model with minor errors that Decision Tree Model and don’t
80%
machine learning algorithm
obtain the correct output as will lead to a slightly different understand how required output
(Decision Tree) with python
per requirement/ given tasks. output as per given in a task. and task is achieved.
programming language.

CLO7
Lab Safety Properly handle
Properly handle lab equipment Moderate level lab handling and Minor or no safety measurements
10%
lab infrastructure/safety
& obey safety measures. safety measurements has been considered.
precautions

Total Marks: 10
Lab 10– Machine Learning Algorithm (Decision Tree)
Learning Outcome:
Implement the Machine Learning Algorithm Decision Tree Model in Python Programming Language.

Theory:
A Decision Tree algorithm is one of the most popular machine learning algorithms. It uses a tree like structure
and their possible combinations to solve a particular problem. It belongs to the class of supervised learning
algorithms where it can be used for both classification and regression purposes.

A decision tree is a structure that includes a root node, branches, and leaf nodes. Each internal node denotes a
test on an attribute, each branch denotes the outcome of a test, and each leaf node holds a class label. The
topmost node in the tree is the root node.

Classification and Regression Trees (CART)

Nowadays, Decision Tree algorithm is known by its modern name CART which stands for Classification and
Regression Trees. Classification and Regression Trees or CART is a term introduced by Leo Breiman to refer
to Decision Tree algorithms that can be used for classification and regression modeling problems.

The CART algorithm provides a foundation for other important algorithms like bagged decision trees, random
forest and boosted decision trees. In this kernel, I will solve a classification problem. So, I will refer the
algorithm also as Decision Tree Classification problem.

In a Decision Tree algorithm, there is a tree like structure in which each internal node represents a test on an
attribute, each branch represents the outcome of the test, and each leaf node represents a class label. The paths
from the root node to leaf node represent classification rules.

We can see that there is some terminology involved in Decision Tree algorithm. The terms involved in Decision
Tree algorithm are as follows:-

Root Node
It represents the entire population or sample. This further gets divided into two or more homogeneous sets.

Splitting
It is a process of dividing a node into two or more sub-nodes.

Decision Node
When a sub-node splits into further sub-nodes, then it is called a decision node.

Leaf/Terminal Node
Nodes that do not split are called Leaf or Terminal nodes.

Pruning
When we remove sub-nodes of a decision node, this process is called pruning. It is the opposite process of
splitting.

Branch/Sub-Tree
A sub-section of an entire tree is called a branch or sub-tree.
Parent and Child Node
A node, which is divided into sub-nodes is called the parent node of sub-nodes where sub-nodes are the
children of a parent node.

The above terminology is represented clearly in the following diagram:-

Code Implementation:

Import the Library:


Upload the Dataset:

Drop the output feature:


Output feature contents:

Encoded the Contents of input features:


Encoded contents of input features:

Encoded output feature:


Training and Testing Size of the Model:

Create a Decision Tree Model:

Predict the Model:


Lab Task:

Task # 01: Implement the Example Code and predict the salary of the Employees for different values of
input features.

Task # 02: Build decision tree model to predict survival based on certain parameters
In this file using following columns build a model to predict if person would survive or not,

1. Pclass
2. Sex
3. Age

Predict the survival of the persons for different values of input features.

CSV available at Google classroom.

You might also like