작성
·
50
0
기출변형문제를 푸는데
1번방식,2번방식 실행했을때 같은 결과가 나와야하지않나요?
서로 다르게나와 혼돈이 옵니다 ㅠ 강의에서는 1번방식으로 배웠는데 말이죠.. ㅠ
공통
import pandas as pd
import numpy as np
df= pd.read_csv('https://raw.githubusercontent.com/Datamanim/datarepo/main/krdatacertificate/e7_p3_t.csv')
df.head()
print(df.shape)
train = df.iloc[:210].reset_index(drop=True)
test = df.iloc[210:].reset_index(drop=True)
1번방식
from statsmodels.formula.api import logit
formula = "target ~ age + sex + cp + trestbps + chol + fbs + restecg + thalach + exang + oldpeak + slope + ca + thal"
model = logit(formula,data=train).fit()
model.summary()
np.exp(model.params['age'])
2번방식
# 종속변수와 독립변수 설정
X = train.drop('target', axis=1)
y = train['target']
# 로지스틱 회귀모형 적합
model = sm.Logit(y, X).fit()
# age의 weight 오즈비 계산
odds_ratios = np.exp(model.params['age'])
odds_ratios
답변