You are on page 1of 6

Hidri_Chadha_2lSIB:

TP2 : Arbre de décision

Exercice 1 :

. Step 1 :

. Step 2 :
● Sklearn a machine learning library , it provides a range of
algorithms for tasks such as classification , regression , clustering ,
It also tools for working with data such as loading and
transforming data. It also includes a range of tools for working with
different data types such as text and image data .
❖ sklearn.tree its a library that contains classes and function related
to decision tree algorithms
❖ DecisionTreeClassifier a class used for classification tasks and
creates a decision tree models
❖ export_graphviz a function can be used to export a decision tree
model in graphviz format ( graphviz is a software that can be used
to create diagrams and graphs ) it takes as input a decision tree
model and other parameters .
❖ sklearn.model_selection it’s a module that provides tools for model
selection and evaluation ( the process of choosing the best
machine learning algorithm for a given task
❖ train_test_split a function used to split a dataset into two subsets a
training set and a testing set to evaluate the performance of a
machine learning model by training the model and then testing the
model

.Step2:
input 9 ⇒ we drops the Kyphosis column from d

input 11 ⇒ put the column kyphosis in y

.Step3:

input 12 => x_train and y_train will contain the training ata
y_train and x_train will contain the testing data
test_size =0.3 means that the testing set will contain 30%
of the data and 70% will be used for the training

.Step4:

input 14 => create an instance of the class by calling its constructor


and assigns it to dtree after we use fit() method to train the data to
learn the structure of the decision tree .

input 17 => method takes the testing features to make prediction on it


input 16 ⇒ metric is a module that provides a wide range of functions
for evaluating the performance of machine learning models

input 18 ⇒ accuracy_score function to calculate the accuracy


(précision) of the predictions

input 19 ⇒ tree module includes classes for both classification and


regression trees and functions for visualizing decision tree

tree.plot_tree() a function that visualizes a decision tree


Exercice 2

Input 8 ⇒ selecting all rows and the first four columns using the iloc
method in pandas used to select rows and columns by their numerical
index the first specifies the rows and the second specifies the columns
Input 9 ⇒ selecting all rows and the last column

Input 10 ⇒ get_dummies is a pandas function used to create dummy


variables it create a new binary column for each unique value in the
variable where the value is 1 if it exist otherwise it takes 0

You might also like