경기도미래기술학교 AI개발자 부트캠프 30일차 TIL- Decision Tree의 한계. ratio와 지니인덱스
2023. 6. 20. 16:23ㆍpython
반응형
https://tyami.github.io/machine%20learning/decision-tree-3-c4_5/
https://tyami.github.io/machine%20learning/decision-tree-1-concept/
여기서 순서대로 공부해보자.
확률은 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
'python' 카테고리의 다른 글
경기도미래기술학교 AI개발자 부트캠프 33일차 TIL- 혼자서 예측 프로그램 만들어보기. (0) | 2023.06.26 |
---|---|
머신러닝 용어, 기본 개념. 학습데이터? 테스트 데이터? 머신러닝 계의 Hello World인 붓꽃(load_iris) 연습하기. (0) | 2023.06.25 |
경기도미래기술학교 AI개발자 부트캠프 29일차 TIL- Decision tree란? 엔트로피란? 개념 알고 실습하기. (1) | 2023.06.19 |
경기도미래기술학교 AI개발자 부트캠프 28일차 TIL-파이썬으로 하는 벡터공부 계속. Mean subtraction 하는 이유, 편차 만들기, 분산, 표준편차 등. (0) | 2023.06.16 |
경기도미래기술학교 AI개발자 부트캠프 27일차 TIL- 벡터 공부 (0) | 2023.06.15 |