Task :
저장방법 : 파일열기 - 브라우저창으로 뜨면 우클릭 후 다른이름으로저장 - 확장자 모든 파일로 해서 파일명에 .ipynb 추가 후 저장
7조 기초 프로젝트 코드 합본
•
김재경
최종 파일
•
강선우
•
박동주
아래로 쭉 내리다 보면 ‘숫자형 지표 범주화’ 부분부터 인사이트를 위한 코드 입니다.
전처리 완료된 기본 코드에 ‘연평균성장률’ 컬럼만 추가한 다음에 해당 코드 진행하면 문제 없을 것 같습니다.
•
박미정
•
이기창
•
실행 및 진행 사항 정리
# 연평균성장률과 월별거래량 합산 지표를 사용하는건 어떨까? 월별거래량을 사용하게되면 연간 거래량을 사실 쓸모 없을 것 같음.
# 연평균 성장률 정규화 MinMax 정규화
growth_min = choice_df['연평균성장률(%)'].min()
growth_max = choice_df['연평균성장률(%)'].max()
choice_df['growth_norm'] = (choice_df['연평균성장률(%)'] - growth_min) / (growth_max - growth_min)
# 월별거래량 정규화
vol_min = choice_df['법정동별_총거래량'].min()
vol_max = choice_df['법정동별_총거래량'].max()
choice_df['volume_norm'] = (choice_df['법정동별_총거래량'] - vol_min) / (vol_max - vol_min)
choice_df
Python
복사
# 이기창 인사이트 MDD
# 기존의 안정성 지표로는 반드시 인구수 순서대로만 나와서 정확도가 떨어진다고 판단, MDD라는 추가 지표를 도입하기로 결정
# 상위 20% 매물의 평균가와 하위 20% 매물의 평균가의 차를 매년 평균 낸 없을 MDD로 설정하였음
# 안정적인 매물을 위해서 매물이 1000개 이하인 매물지역은 제외하였음.
# MDD 계산 코드가 아래에 포함되어 있음.
ef get_indicators(sub_df):
grouped = sub_df.groupby('계약연도')
top_20_prices = []
bottom_20_prices = []
years = []
for year, group in grouped:
if len(group) < 5:
continue
price_series = group['평단가']
top_20_mean = price_series[price_series >= price_series.quantile(0.8)].mean()
bot_20_mean = price_series[price_series <= price_series.quantile(0.2)].mean()
top_20_prices.append(top_20_mean)
bottom_20_prices.append(bot_20_mean)
years.append(year)
s_top = pd.Series(top_20_prices, index=years)
s_bot = pd.Series(bottom_20_prices, index=years)
mdd_top = calculate_mdd(s_top)
mdd_bot = calculate_mdd(s_bot)
avg_mdd = (mdd_top + mdd_bot) / 2
yearly_avg = sub_df.groupby('계약연도')['평단가'].mean().sort_index()
if len(yearly_avg) >= 2:
total_years = yearly_avg.index[-1] - yearly_avg.index[0]
if total_years > 0:
cagr_val = (yearly_avg.iloc[-1] / yearly_avg.iloc[0]) ** (1/total_years) - 1
else:
cagr_val = 0
else:
cagr_val = 0
volume = len(sub_df)
return pd.Series({'CAGR': cagr_val, 'MDD': avg_mdd, '매물량': volume})
Python
복사
결과
