Skip to playerSkip to main content
Master the implementation of Decision Trees (DT) in Python with this step-by-step Tamil tutorial by Skillfloor!

Our Website:
Visit 🔗 http://www.skillfloor.com

Our Blogs:
Visit 🔗 https://skillfloor.com/blog/

DEVELOPMENT TRAINING IN CHENNAI
https://skillfloor.com/development-training-in-chennai

DEVELOPMENT TRAINING IN COIMBATORE
https://skillfloor.com/development-training-in-coimbatore

Our Development Courses:
Certified Python Developer
Visit 🔗https://skillfloor.com/certified-python-developer
Certified Data BASE Developer
Visit 🔗https://skillfloor.com/certified-data-base-developer
Certified Android App Developer
Visit 🔗https://skillfloor.com/certified-android-app-developer
Certified IOS App Developer
Visit 🔗https://skillfloor.com/certified-ios-app-developer
Certified Flutter Developer
Visit 🔗https://skillfloor.com/certified-flutter-developer
Certified Full Stack Developer
Visit 🔗https://skillfloor.com/certified-full-stack-developer
Certified Front End Developer
Visit 🔗https://skillfloor.com/certified-front-end-developer

Our Classroom Locations:
Bangalore - https://maps.app.goo.gl/ZKTSJNCKTihQqfgx6
Chennai - https://maps.app.goo.gl/36gvPAnwqVWWoWD47
Coimbatore - https://maps.app.goo.gl/BvEpAWtdbDUuTf1G6
Hyderabad - https://maps.app.goo.gl/NyPwrN35b3EoUDHCA
Ahmedabad - https://maps.app.goo.gl/uSizg8qngBMyLhC76
Pune - https://maps.app.goo.gl/JbGVtDgNQA7hpJYj9

Our Additional Course:
Analytics Course
https://skillfloor.com/analytics-courses
https://skillfloor.com/analytics-training-in-bangalore
Artificial Intelligence Course
https://skillfloor.com/artificial-intelligence-courses
https://skillfloor.com/artificial-intelligence-training-in-bangalore
Data Science Course
https://skillfloor.com/data-science-courses
https://skillfloor.com/data-science-course-in-bangalore
Digital Marketing
https://skillfloor.com/digital-marketing-courses
https://skillfloor.com/digital-marketing-courses-in-bangalore
Ethical Hacking
https://skillfloor.com/ethical-hacking-courses
https://skillfloor.com/cyber-security-training-in-bangalore

#decisiontree #python #pythontutorial #skillfloor #tamilcoding #pythonintamil #machinelearning #datascience #datasciencetamil #machinelearningtamil #techeducation #mlalgorithm #supervisedlearning #classification #codingintamil #pythoncourse #tamiltech #visualization #pythonskills #sklearn #skillfloorcourse
Transcript
00:00Hello everyone, in the video we are going to talk about the implementation of decision tree in python.
00:07So in practical, we will talk about decision tree in python.
00:14So when we are going to talk about decision tree, we will talk about libraries.
00:19So we will talk about heart data set.
00:21So in the heart data set, we will talk about whether the person is having heart disease or not.
00:25Based on age, gender, chest pain type, 0, 1, 2, 3.
00:300 is anginal, 1 is non-anginal.
00:33So there are different types of CP.
00:36Then, Tres BPs.
00:38So BP level, cholesterol, ECG levels.
00:42So based on this, we will decide the target.
00:46So thal is called thalassemia.
00:51So there are different types.
00:53So these are completely encoded values in heart data set.
00:57So we will use this data set.
00:59So we will do first basic EDA checks.
01:02So the shape.
01:03So there are actually 303 rows and 14 columns.
01:06Then, if you check information,
01:08there are 303 normal values.
01:11So there are missing values.
01:12So in basic EDA checks, univariate analysis.
01:17So in univariate analysis, his plot, chest pain type, we will compare.
01:23Then, similarly, we have relationship plot with respect to chest pain and target.
01:28So our target is 0 and 1.
01:31So in 0 and 1, we will plot the chest pain types.
01:36Then, correlation analyze.
01:38So correlation on the target column,
01:40the highest set, we will contribute to the highest set.
01:43Like 0.43, minus 0.43, and minus 0.43.
01:48So this is X, old peak, and chest pain.
01:51So in the three columns,
01:52we will contribute to higher.
01:54Then, followed by that,
01:55we have CA thalassemia.
01:58CA thalassemia and slope.
02:00Then, we will check missing values.
02:02Then, we will check missing values.
02:04We will use null.sum.
02:06We will check missing values.
02:08We will check information already.
02:10In the data set,
02:11we will use duplicate value in this data set.
02:13That means, 14 columns of value
02:15are similar to replicate.
02:17So that's the duplicates value.
02:19So in hard.duplicate.sum,
02:21we will represent one data.
02:23So when we remove the data,
02:25we will use hard.dropduplicates.
02:28In place equal true, true,
02:30we will check the original data set.
02:33It will be affected.
02:38In the original data set,
02:39there will be changes.
02:40If we have 303 rows,
02:42we will check the duplicate value.
02:44We will check the shape.
02:46We will check the shape.
02:48Next,
02:49we will check the duplicate value.
02:51We will check the duplicate value.
02:53Then, his plot,
02:54we will analyze.
02:55This is right skewed data.
02:57Most people,
02:58in the range,
02:59we will analyze.
03:01Like 150,
03:03350,
03:05350.
03:07Then,
03:08we will analyze.
03:09With respect to
03:10gender and age.
03:12Gender and age.
03:13And with respect to
03:14target column.
03:15So target column provide.
03:16Legend box also.
03:17So here,
03:18we have 0,
03:19female and 1 male.
03:23And 0,
03:25person not having heart disease.
03:270 not having heart disease.
03:281 person having heart disease.
03:29So we will split up.
03:31So compare two.
03:32We will compare.
03:33Person not having heart disease.
03:352 gender is higher.
03:37Compared with person having heart disease.
03:42Next,
03:43we will check the decision tree.
03:45We will check the decision tree.
03:47So x axis is the target column.
03:49So x axis is the target column.
03:50Last column is the target column.
03:51So that we remove x.
03:52So x is equal to heart.i log.
03:53So x axis is the target column.
03:54Last column is the last column.
03:55So that we remove x.
03:56So x is equal to heart.i log.
03:58So all rows are going to be left.
03:59And last column is the last column.
04:01So colon minus 1 is the last column.
04:04Then y is the last column is going to be left.
04:06So heart.i log of all rows,
04:09minus 1.
04:10So if we check the x.columns,
04:13one of the target column is the target column.
04:15Then,
04:16we will try to train test.
04:18So we will split the independent and dependent features.
04:20Next,
04:21train test split use.
04:23X train x test.
04:24Y train y test.
04:25Split it.
04:26So test size is 25%.
04:29So 75-25% split.
04:31We will check ytrain.value count.
04:34That is,
04:35person having hard decision,
04:36123 repair.
04:37Person not having hard decision,
04:39103 repair.
04:40That is,
04:42we will check the individual.
04:43Because we will use the balancing.
04:45That is,
04:46we will check the concept.
04:48First,
04:49decision tree classifier.
04:50We will normally run.
04:51So that is,
04:52from
04:53sqlearn.tree,
04:54import decision tree classifier.
04:56So this is tree based algorithm.
04:58We will import decision tree classifier.
05:00This is classification problem.
05:02This is regression deal.
05:04Decision tree regressor use.
05:06Then,
05:07metrics import.
05:09Because accuracy check.
05:10Then,
05:11model equal to
05:12decision tree classifier.
05:14Random set equal to
05:1542.
05:16Just to provide.
05:17Here,
05:18criterion says,
05:19one keyword.
05:20So criterion,
05:21we have already
05:22two criterion.
05:23One,
05:24Guinea.
05:25Second,
05:26entropy.
05:27So criterion equal to
05:28Guinea.
05:29That is,
05:30we will provide.
05:31So,
05:32we will change.
05:34Criterion.
05:35equal to
05:42Guinea.
05:43And then,
05:44followed by splitter.
05:45Splitter,
05:46we will provide.
05:47We will provide.
05:48Then,
05:49followed by splitter.
05:50Splitter,
05:51we will provide.
05:56So,
05:57we will run.
06:00Okay.
06:01So,
06:02we have the same accuracy.
06:03The most are.
06:04So,
06:05we will do this.
06:07Okay.
06:08So,
06:09Decision tree of criterion.
06:10Guinea based.
06:11Splitting on the best.
06:12Random state.
06:13We have 42.
06:14Okay.
06:15Then,
06:16we provide training data.
06:17That is,
06:18x-train and y-train.
06:19Then,
06:20model predict.
06:21x-test use.
06:22That is,
06:23y-prediction.
06:24Then,
06:25accuracy score,
06:26we will compare.
06:27y-test to y-prediction.
06:28If we compare.
06:2980.2%
06:30we will get.
06:31Okay.
06:32Next,
06:33we will do heatmap analysis.
06:35So,
06:36heatmap analysis.
06:37y-test
06:38and y-prediction.
06:39So,
06:40y-test and y-prediction.
06:41Confusion matrix.
06:42we will compare.
06:4361.
06:44correctly classified data.
06:45So,
06:46diagonal elements.
06:47correctly classified data.
06:48So,
06:4915.
06:50misclassified data.
06:51So,
06:52precision,
06:53recall,
06:54f-1 scores.
06:55next.
06:56Next,
06:57we will compare.
06:58Smote analysis.
06:59So,
07:00smote analysis.
07:01Synthetic.
07:03stands for synthetic.
07:09Minority.
07:13Oversampling technique.
07:15basic.
07:16What we need to do is
07:19target column.
07:20For example,
07:21target column.
07:22Person not having heart disease.
07:24Having heart disease.
07:25Consider.
07:26So,
07:27person not having heart disease.
07:28200.
07:29Person having heart disease.
07:31100.
07:32That's the same.
07:33As you can see.
07:34So,
07:35we can see.
07:36In other words,
07:38we can see.
07:39duplicate data.
07:40That's the same.
07:41duplicate data.
07:42Supporting.
07:43In the person having heart disease.
07:44To generate.
07:45If we check in 0, we will check in 200.
07:49If we check in 100, we will be able to analyze synthetic data.
07:54If we have a person having heart disease, we will be able to generate almost 190 data.
08:02If we have 0 person not having heart disease, we will generate.
08:08We will create a balanced learning.
08:12First, we import from imbelearn.oversampling, import smote.
08:19Then smote import from sklearn.tree, decision tree classifier import.
08:26Then smote create.
08:29First smote equal to, smote of random state equal to 42.
08:33Then we create a model.
08:36Xtrain resample and ytrain resample.
08:39First, we will analyze the training phase.
08:44Because in the training phase, we will generate synthetic data and learn.
08:48What do we do?
08:49Xtrain and ytrain directly parse.
08:52Xtrain resample and ytrain resample create.
08:56We will create two keywords.
08:58What do we do?
08:59What do we do?
09:00Smart.fit.resample, xtrain, ytrain.
09:04So, when we apply smote apply, we will balance everything.
09:08This is the actual data.
09:10The actual data means that 123 people are not having heart disease.
09:15103 people are having heart disease.
09:17So, we will balance this.
09:20So, 0, 123.
09:211 is almost 123.
09:221 is almost 123.
09:23We will generate 130 samples.
09:26So, almost closer samples.
09:28We will generate training phase using smart.
09:32Then, if we use smart,
09:35we will fit the model.
09:37Then, xtrain resample and ytrain resample.
09:40So, first model equal to decision tree classifier create.
09:44You can classify it equal to balance.
09:46So, we will balance classification.
09:48Then, random weight equal to 42 provide.
09:51Then, model.fit.off.
09:53What do we use fit?
09:54That is xtrain and ytrain resample values.
09:58Smart analyze the variables.
10:01Then, xtrain predict accuracy check.
10:05First time, 80.2.
10:08Small analysis is 82.8.
10:11So, 1.3% rise.
10:13Okay.
10:14So, we will use small technique.
10:17Next, we will check confusion matrix.
10:21Next, we will check hyperparameter tuning.
10:26Hyperparameter tuning.
10:27So, hyperparameter tuning is decision tree classifier.
10:30What do we pass?
10:32Hyperparameter tuning is basically best parameters.
10:36Randomized search cv.
10:38So, grid search cv.
10:39Basically, we have different parameters.
10:40So, grid search cv.
10:41So, grid search cv.
10:42Basically, we have different parameters.
10:44We have different Cartesian products.
10:46We have different possibilities.
10:48Check the best parameters.
10:49So, first.
10:50Decision tree classifier model.
10:51So, first.
10:52So, first.
10:53So, first.
10:54Decision tree classifier model.
10:55So, first.
10:56Create Cv.
10:57So, first.
10:59Then, we will pass the parameters.
11:00So, that's the decision tree classifier model.
11:02Okay.
11:03So, the first argument.
11:04Rig search cv of tree underscore clf.
11:07That's the decision tree model.
11:08Okay.
11:09That is the first argument.
11:10Then, params.
11:11Params.
11:12Params on the path.
11:13Params. Params, we create decision tree.
11:16So tree create, we check what criteria we have,
11:19what parameters we have,
11:21like criteria, spitting criteria we have,
11:23we need to enter of here.
11:25Then spitting, best and random.
11:28Maximum tip, we provide lists,
11:301-10 pull.
11:32Then minimum sample spit.
11:34Sample spit is now,
11:36we spread samples.
11:38If we control this,
11:39we provide minimum sample spit.
11:41Then final leaf node,
11:43we control minimum samples leaf.
11:45Okay.
11:46So five parameters,
11:48we pass.
11:49This is the second argument.
11:52Then third argument is,
11:53classification problem deal.
11:55So scoring equal to accuracy,
11:57we provide accuracy.
11:58So accuracy paste,
11:59we provide best parameters.
12:01Then end jobs equal to minus,
12:03this basic parameters,
12:05so parameters first,
12:09we have to consider.
12:10Guinea, best.
12:11Okay.
12:12Then,
12:13Guinea, random.
12:15Then entropy,
12:19best.
12:21Entrophy, random.
12:24So different possible combinations.
12:26So different possible combinations.
12:28Now,
12:29first two categories,
12:30we provide different possible categories.
12:32Next three categories,
12:34Guinea,
12:35best.
12:36Depth,
12:37we provide from 1 till 10.
12:39So depth 1,
12:40then 2,
12:413,
12:42till 10.
12:43Then,
12:44Guinea,
12:45randomly,
12:461,
12:472,
12:48till 10.
12:49So different possibilities,
12:50values,
12:51consider.
12:52parameters,
12:53choose.
12:54Decision tree,
12:55create.
12:56Decision tree,
12:57create.
12:58Accuracy based,
13:00result.
13:01High or low,
13:02or low,
13:03we choose.
13:05Next,
13:06end jobs equal to minus,
13:08different combinations,
13:09try.
13:10Hardware support,
13:12so end jobs equal to minus,
13:14provide.
13:155,
13:16provide.
13:17So,
13:18actually,
13:19lines,
13:20provide.
13:21O was.
13:22Then,
13:23cv equal to 5,
13:24cross validation.
13:25Cross validation,
13:26entire data set,
13:275,
13:28divide.
13:29So,
13:30first time,
13:31first block,
13:32testing phase,
13:33training phase.
13:35Then,
13:36second time,
13:37run now,
13:38training phase,
13:39testing phase,
13:40training phase,
13:41training phase.
13:42in the possible combinations,
13:50with respect to accuracy.
13:52Then,
13:53x-train and y-train
13:54pass,
13:55best parameters,
13:56extract.
13:57Best parameters,
13:58criterion entropy,
13:59maximum depth,
14:00minimum samples,
14:018.
14:02So,
14:03decision tree,
14:04classify,
14:05in the dictionary,
14:06point,
14:07double pointer method,
14:08use the best parameters,
14:09extract.
14:10Then,
14:11training data,
14:12testing data,
14:13and accuracy.
14:14So,
14:15accuracy check,
14:1682.89.
14:17Then,
14:18we have different best parameters,
14:22so,
14:23actually,
14:24highlighted values,
14:2688%
14:27so,
14:28we will comment,
14:30next time,
14:31run now,
14:32directly,
14:33grid sets,
14:34run now,
14:35these parameters,
14:36run now.
14:37So,
14:38here,
14:39best parameters,
14:40acquire,
14:41here,
14:43complete decision tree,
14:45so,
14:46complete decision tree,
14:47hyper parameter tuning,
14:48more technique,
14:49here,
14:50implementation of decision tree,
14:51in python,
14:52next video,
14:53thank you.

Recommended