Lab # 10
Lab # 10
Lab Manual 10
CS3151-Artificial Intelligence Lab
Table of Contents
1 Objectives ............................................................................................................................... 3
2 Task Distribution ..................................................................................................................... 3
3 Decision Tree .......................................................................................................................... 3
3.1 Key Concepts ................................................................................................................... 3
3.2 Component ....................................................................................................................... 3
4 Steps in Performing Decision Tree: ........................................................................................ 4
4.1 Applications of Decision Tree .......................................................................................... 4
5 Visualization ........................................................................................................................... 4
6 Code ........................................................................................................................................ 4
7 Exercise (50 Marks) ................................................................................................................ 5
8 Submission Instructions .......................................................................................................... 5
CS3151: Artificial Intelligence Lab
1 Objectives
After performing this lab, students shall be able to understand the following:
Linear Regression
Linear Regression model with scikit-learn
2 Task Distribution
Total Time 170 Minutes
3 Decision Tree
A decision tree is a flowchart-like structure used to make decisions or predictions. It consists of
nodes representing decisions or tests on attributes, branches representing the outcome of these
decisions, and leaf nodes representing final outcomes or predictions. Each internal node
corresponds to a test on an attribute, each branch corresponds to the result of the test, and each leaf
node corresponds to a class label or a continuous value.
Decision Nodes: These are the nodes where the data is split based on the features of the
dataset.
Leaf Nodes (Terminal Nodes): These nodes represent the final outcome or decision. Each leaf
node corresponds to a class label (in classification tasks) or a continuous value (in regression
tasks).
3.2 Component
Features: Attributes or variables used to make decisions at each node.
CS3151: Artificial Intelligence Lab
Splits: Criteria for dividing the data at each node, typically based on feature values. Common
criteria include Gini impurity, entropy, or variance reduction.
Branches: The outcomes of the splits, leading to the next decision node or a leaf node.
5 Visualization
Decision trees can be visualized, making them particularly useful for understanding the logic
behind predictions. Visualization helps in interpreting the results and in communicating the
decision rules derived from the model.
In summary, decision trees are a versatile and powerful tool in the machine learning toolbox,
known for their simplicity, interpretability, and ability to model complex relationships. However,
care must be taken to manage their tendency to overfit and their sensitivity to data changes.
6 Code
# Step 1: Import Libraries
import numpy as np
import pandas as pd
from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import accuracy_score, classification_report
from sklearn.tree import export_text, plot_tree
CS3151: Artificial Intelligence Lab
8 Submission Instructions
Always read the submission instructions carefully.
• Rename your Jupyter notebook to your roll number and download the notebook as
.ipynb extension.
• To download the required file, go to File->Download .ipynb
• Only submit the .ipynb file. DO NOT zip or rar your submission file.
CS3151: Artificial Intelligence Lab