Question

1. Decision trees As part of this question you will implement and compare the Information Gain, Gini Index and CART evaluatio

(a) (10 pts. Implement the IG(D, index, value) function according to equation 1, where D is a dataset, inder is the index of

0 0
Add a comment Improve this question Transcribed image text
Answer #1

a)

  1. # importing libraries  
  2. import numpy as nm  
  3. import matplotlib.pyplot as mtp  
  4. import pandas as pd  
  5.   
  6. #importing datasets  
  7. data_set= pd.read_csv('user_data.csv')  
  8.   
  9. #Extracting Independent and dependent Variable  
  10. x= data_set.iloc[:, [2,3]].values  
  11. y= data_set.iloc[:, 4].values  
  12.   
  13. # Splitting the dataset into training and test set.  
  14. from sklearn.model_selection import train_test_split  
  15. x_train, x_test, y_train, y_test= train_test_split(x, y, test_size= 0.25, random_state=0)  
  16.   
  17. #feature Scaling  
  18. from sklearn.preprocessing import StandardScaler    
  19. st_x= StandardScaler()  
  20. x_train= st_x.fit_transform(x_train)    
  21. x_test= st_x.transform(x_test)
  22. output:
  23. data_set - DataFrame - O X Index Gender Age Purchased User ID 15624510 EstimatedSalary 19000 Male 15810944 Male 35 20000 1566

B)

  1. #Visulaizing the trianing set result  
  2. from matplotlib.colors import ListedColormap  
  3. x_set, y_set = x_train, y_train  
  4. x1, x2 = nm.meshgrid(nm.arange(start = x_set[:, 0].min() - 1, stop = x_set[:, 0].max() + 1, step  =0.01),  
  5. nm.arange(start = x_set[:, 1].min() - 1, stop = x_set[:, 1].max() + 1, step = 0.01))  
  6. mtp.contourf(x1, x2, classifier.predict(nm.array([x1.ravel(), x2.ravel()]).T).reshape(x1.shape),  
  7. alpha = 0.75, cmap = ListedColormap(('purple','green' )))  
  8. mtp.xlim(x1.min(), x1.max())  
  9. mtp.ylim(x2.min(), x2.max())  
  10. fori, j in enumerate(nm.unique(y_set)):  
  11. mtp.scatter(x_set[y_set == j, 0], x_set[y_set == j, 1],  
  12.         c = ListedColormap(('purple', 'green'))(i), label = j)  
  13. mtp.title('Decision Tree Algorithm (Training set)')  
  14. mtp.xlabel('Age')  
  15. mtp.ylabel('Estimated Salary')  
  16. mtp.legend()  
  17. mtp.show()  

Output:

Decision Tree Algorithm (Training set) : 1.1, Estimated Salary -2 -1 0 Age

Add a comment
Know the answer?
Add Answer to:
1. Decision trees As part of this question you will implement and compare the Information Gain,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • in Python Project 5: Payroll (Part 1) CS 1410 Background In this project you will implement...

    in Python Project 5: Payroll (Part 1) CS 1410 Background In this project you will implement a simple payroll system. For the first part of the assignment, you will submit a UML class diagram. The hypothetical company we are considering has 3 classifications of employees: 1. Hourly 2. Salaried 3. Commissioned There are 24 pay periods per year; 1/24th of a salary is paid each pay period to employees who receive a salary. We won't worry about taxes and other...

  • In this part, you will complete the code to solve a maze.

    - Complete the code to solve a maze- Discuss related data structures topicsProgramming-----------In this part, you will complete the code to solve a maze.Begin with the "solveMaze.py" starter file.This file contains comment instructions that tell you where to add your code.Each maze resides in a text file (with a .txt extension).The following symbols are used in the mazes:BARRIER = '-' # barrierFINISH = 'F' # finish (goal)OPEN = 'O' # open stepSTART = 'S' # start stepVISITED = '#' #...

  • What an Executive Summary Is An executive summary is a specific type of document that does...

    What an Executive Summary Is An executive summary is a specific type of document that does two things: it summarizes a research article, and it offers recommendations as to how information from the article can be used. Some long reports can contain an executive summary section, as indicated in the Pearson handbook. Write a 2 pahe Executive Summary In business contexts, an executive summary is always written for a specific purpose: to explain the information in the article to a...

  • 10. Write a one-page summary of the attached paper? INTRODUCTION Many problems can develop in activated...

    10. Write a one-page summary of the attached paper? INTRODUCTION Many problems can develop in activated sludge operation that adversely affect effluent quality with origins in the engineering, hydraulic and microbiological components of the process. The real "heart" of the activated sludge system is the development and maintenance of a mixed microbial culture (activated sludge) that treats wastewater and which can be managed. One definition of a wastewater treatment plant operator is a "bug farmer", one who controls the aeration...

  • All of the following questions are in relation to the following journal article which is available...

    All of the following questions are in relation to the following journal article which is available on Moodle: Parr CL, Magnus MC, Karlstad O, Holvik K, Lund-Blix NA, Jaugen M, et al. Vitamin A and D intake in pregnancy, infant supplementation and asthma development: the Norwegian Mother and Child Cohort. Am J Clin Nutr 2018:107:789-798 QUESTIONS: 1. State one hypothesis the author's proposed in the manuscript. 2. There is previous research that shows that adequate Vitamin A intake is required...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT