강의

멘토링

로드맵

인프런 커뮤니티 질문&답변

구본엽님의 프로필 이미지
구본엽

작성한 질문수

작업형 3번 문제 질문 logit 회귀

작성

·

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

답변

답변을 기다리고 있는 질문이에요
첫번째 답변을 남겨보세요!
구본엽님의 프로필 이미지
구본엽

작성한 질문수

질문하기