로지스틱 회귀 계수 탐색
이제 로지스틱 회귀의 계수를 탐색하여 이탈(churn)을 증가시키거나 감소시키는 요인이 무엇인지 살펴보겠습니다. 이 연습에서는 적합된 모델에서 로지스틱 회귀 계수를 추출하고, 해석을 쉽게 하기 위해 그 지수를 계산합니다.
적합된 로지스틱 회귀 인스턴스는 logreg로, 스케일된 특성은 train_X라는 pandas DataFrame으로 로드되어 있습니다. numpy와 pandas 라이브러리는 각각 np, pd로 로드되어 있습니다.
이 연습은 강의의 일부입니다
Python으로 배우는 마케팅용 Machine Learning
연습 안내
- 특성 이름과 계수를 결합해
pandasDataFrame을 만드세요. - 로지스틱 회귀 계수의 지수를 계산하세요.
- 0과 같은 계수를 제거하고, 지수 계수로 정렬해 출력하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Combine feature names and coefficients into pandas DataFrame
feature_names = pd.DataFrame(___.columns, columns = ['Feature'])
log_coef = pd.DataFrame(np.transpose(logreg.coef_), columns = ['Coefficient'])
coefficients = pd.concat([feature_names, ___], axis = 1)
# Calculate exponent of the logistic regression coefficients
coefficients['Exp_Coefficient'] = np.___(coefficients['Coefficient'])
# Remove coefficients that are equal to zero
coefficients = coefficients[coefficients['Coefficient']!=___]
# Print the values sorted by the exponent coefficient
print(coefficients.sort_values(by=['___']))