Python을 이용한 Decision Tree (4)
DT Assignment2
과
Entropy를 구하고, 각 변수에 대한 Gain을 구하는 함수를 구현하는 과제입니다.
DT_Assignment2.ipynb 파일에 있는 두가지 함수를 만들어 주시면 됩니다. 결과는 주어져 있습니다.
두번째 함수는 출력값이 꼭 주어진 형태와 일치할 필요는 없습니다. 봤을 때 각 변수에 대한 Gain을 알아볼 수 있도록 구성해 주세요.
마찬가지로 주석 꼼꼼히 달아주세요!
우수과제 선정이유
코드 한줄한줄 주석을 굉장히 자세하게 정성스레 적어주셔서 다른 분들이 참고하기 좋기 때문에 우수과제로 선정되었습니다.
import pandas as pd
import numpy as np
df = pd.read_csv('https://raw.githubusercontent.com/AugustLONG/ML01/master/01decisiontree/AllElectronics.csv')
df.drop("RID",axis=1, inplace = True) #RID는 그냥 Index라서 삭제In [2]:
dfOut[2]:
age
income
student
credit_rating
class_buys_computer
0
youth
high
no
fair
no
1
youth
high
no
excellent
no
2
middle_aged
high
no
fair
yes
3
senior
medium
no
fair
yes
4
senior
low
yes
fair
yes
5
senior
low
yes
excellent
no
6
middle_aged
low
yes
excellent
yes
7
youth
medium
no
fair
no
8
youth
low
yes
fair
yes
9
senior
medium
yes
fair
yes
10
youth
medium
yes
excellent
yes
11
middle_aged
medium
no
excellent
yes
12
middle_aged
high
yes
fair
yes
13
senior
medium
no
excellent
no
함수 만들기
In [3]:
In [4]:
Out[4]:
In [5]:
In [6]:
Out[6]:
결과 확인하기
In [7]:
Last updated
Was this helpful?