경기도미래기술학교 AI개발자 부트캠프 30일차 TIL- Decision Tree의 한계. ratio와 지니인덱스

2023. 6. 20. 16:23python

반응형

https://tyami.github.io/machine%20learning/decision-tree-3-c4_5/

 

의사결정 나무 (Decision Tree) C4.5 알고리즘 설명

의사결정 나무의 기본 알고리즘 중 하나인 C4.5 를 공부해봅시다

tyami.github.io

 

 

https://tyami.github.io/machine%20learning/decision-tree-1-concept/

 

의사결정 나무 (Decision Tree) 기본 설명

Machine learning 알고리즘 중 하나인 의사결정 나무를 공부해봅시다

tyami.github.io

여기서 순서대로 공부해보자.

 

확률은 probability.

 

 

지니 인덱스 :

Gini Index = 1 - Σ (p_i)^2

p_i 클래스 i 대한 확률이다.

 

print('----------Gini index start--------')
root_gini = 1 - (((3/7)**2)+((2/7)**2)*2)
print('root_gini: ',root_gini)
print('----------Gini index first--------')
print('----------Gini index Stream first--------')

stream_false_gini=1 - (((2/3)**2)+((1/3)**2))
print('stream_false_gini: ',stream_false_gini)

stream_false_weight_gini = 3/7*stream_false_gini

print('stream_false_weight_gini: ',stream_false_weight_gini)

stream_true_gini=1 - (((2/4)**2)+((1/4)**2)*2)
print('stream_true_gini: ',stream_true_gini)

stream_true_weight_gini = 4/7*stream_true_gini

print('stream_true_weight_gini: ',stream_true_weight_gini)

print(stream_false_weight_gini+stream_true_weight_gini)

stream_gini = root_gini-(stream_false_weight_gini+stream_true_weight_gini)

print('stream_gini_ig: ',stream_gini)

print('----------Gini index Slope first--------')

slope_steep_gini = 1 - (((3/5)**2)+((1/5)**2)*2)
print('slope_steep_gini: ',slope_steep_gini)

slope_steep_weight_gini = 5/7*slope_steep_gini

print('slope_steep_weight_gini: ',slope_steep_weight_gini)

slope_moderate_gini=1 - ((1/1)**2)
print('slope_moderate_gini: ',slope_moderate_gini)

slope_moderate_weight_gini = 1/7*slope_moderate_gini

print('slope_moderate_weight_gini: ',slope_moderate_weight_gini)

slope_flat_gini=1 - ((1/1)**2)
print('slope_flat_gini: ',slope_flat_gini)

slope_flat_weight_gini = 1/7*slope_flat_gini

print('slope_flat_weight_gini: ',slope_flat_weight_gini)


slope_gini = root_gini-(slope_steep_weight_gini+slope_moderate_weight_gini+slope_flat_weight_gini)

print('slope_gini_ig: ',slope_gini)

print('----------Gini index Elevation first--------')

elevation_high_gini = 1 - (((2/3)**2)+((1/3)**2))
print('elevation_high_gini: ',elevation_high_gini)

elevation_high_weight_gini = 3/7*elevation_high_gini

print('elevation_high_weight_gini: ',elevation_high_weight_gini)

elevation_low_gini=1 - ((1/1)**2)
print('elevation_low_gini: ',elevation_low_gini)

elevation_low_weight_gini = 1/7*elevation_low_gini

print('elevation_low_weight_gini: ',elevation_low_weight_gini)

elevation_medium_gini=1 - (((1/2)**2)+((1/2)**2))
print('elevation_medium_gini: ',elevation_medium_gini)

elevation_medium_weight_gini = 2/7*elevation_medium_gini

print('elevation_medium_weight_gini: ',elevation_medium_weight_gini)

elevation_highest_gini=1 - ((1/1)**2)
print('elevation_highest_gini: ',elevation_highest_gini)

elevation_highest_weight_gini = 1/7*elevation_highest_gini

print('elevation_highest_weight_gini: ',elevation_highest_weight_gini)


elevation_gini_ig = root_gini-(elevation_high_weight_gini+elevation_low_weight_gini+elevation_medium_weight_gini+elevation_highest_weight_gini)

print('elevation_gini_ig: ',elevation_gini_ig)

print('----------Gini index Elevation choice--------')
elevation_high_gini = 1 - (((2/3)**2)+((1/3)**2))
print('elevation_high_gini: ',elevation_high_gini)
print('----------Gini index Stream Second!!--------')

elevation_stream_true_gini = (((1/2)**2)+((1/2)**2))

print('elevation_stream_true_gini: ',elevation_stream_true_gini)

elevation_stream_true_weight_gini = 2/3*elevation_stream_true_gini

print('elevation_stream_true_weight_gini: ',elevation_stream_true_weight_gini)

elevation_stream_false_gini=1 - ((1/1)**2)

elevation_stream_false_weight_gini = 1/3*elevation_stream_false_gini

print('elevation_stream_false_weight_gini: ',elevation_stream_false_weight_gini)

print('stream ig: ',elevation_high_gini-(elevation_stream_true_weight_gini+elevation_stream_false_weight_gini))

print('----------Gini index Slope Second!!--------')

elevation_slope_steep_gini = 1 - ((1/1)**2)

print('elevation_slope_steep_gini: ',elevation_slope_steep_gini)

elevation_slope_steep_weight_gini = 2/3*elevation_slope_steep_gini

print('elevation_slope_steep_weight_gini: ',elevation_slope_steep_weight_gini)

elevation_slope_flat_gini=1 - ((1/1)**2)

elevation_slope_flat_weight_gini = 1/3*elevation_slope_flat_gini

print('elevation_slope_flat_weight_gini: ',elevation_slope_flat_weight_gini)


print('elevation_high_gini: ',elevation_high_gini)
print('slope ig: ',elevation_high_gini-(elevation_slope_steep_weight_gini+elevation_slope_flat_weight_gini))

 

728x90