O'Reilly logo

Ensemble Machine Learning by Ankit Dixit

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Code of the CART algorithm

import pprintimport sysfrom csv import readerimport numpy as np
#Function to read csv filedef load_csv(filename):     dataset = list()     with open(filename, 'r') as file:         csv_reader = reader(file)         for row in csv_reader:             if not row:                 continue             dataset.append(row)     return dataset
#Function to create Train and Test set from the original datasetdef getTrainTestData(dataset,split):      training = []     testing = []       shape = np.shape(dataset)     trainlength = np.uint16(np.floor(split*shape[0]))      for i in range(trainlength):          training.append(dataset[i])      for i in range(trainlength,shape[0]):          testing.append(dataset[i])      return training,testing
#Create splits to validate gini scoredef createSplit(attribute,threshold,dataset):  #Initialize ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required