《상무와 경제통계》 파이톤 구현 노트(4)
2479 단어 데이터 분석
import pandas as pd
import numpy as np
import statsmodels.api as sm
# import statsmodels.formula.api as smf
x = np.array([2,6,8,8,12,16,20,20,22,26])
y = np.array([58,105,88,118,117,137,157,169,149,202])
# s = pd.DataFrame()
# s['x'] = x
# s['y'] = y
# model2 = smf.ols(formula='y ~ x',data = s).fit()
# model2.summary()
X = sm.add_constant(x) #
model = sm.OLS(y,X).fit()
model.summary()
분류 변수
import pandas as pd
import numpy as np
import statsmodels.formula.api as smf
import matplotlib.pyplot as plt
re = np.array([2,6,8,3,2,7,9,8,4,6])
# typ = np.array([" "," "," "," "," "," "," "," "," "," "])
typ = np.array([1,0,1,0,1,1,0,0,1,1]) # k-1
# pd.get_dummies()
time = np.array([2.9,3.0,4.8,1.8,2.9,4.9,4.2,4.8,4.4,4.5])
data = pd.DataFrame([re,typ,time]).T
model = ols('time ~ re+typ',data).fit()
model.summary()
잔차 분석
outliers = model.get_influence()
# outliers.summary_table()
#
# ( )
leverage = outliers.hat_matrix_diag
#dffits
dffits = outliers.dffits[0]
#
resid_stu = outliers.resid_studentized_external
#cook
cook = outliers.cooks_distance[0]
그림을 그리다
#
import matplotlib.pyplot as plt
plt.scatter(x,y)
Y = model.predict(X)
plt.plot(x,Y,"r-")
plt.show()
# x
plt.scatter(x,y-Y)
plt.axhline(0)
#
model.resid.plot.density()
#
plt.scatter(x,resid_stu)
plt.axhline(0)
plt.axhline(2)
plt.axhline(-2)# (-2,2) ,
plt.show()
로지스틱 컴백.
import pandas as pd
import numpy as np
import statsmodels.api as sma
# data = pd.read_excel(r"C:\Users\liuhao\Desktop\a.xls")
data = pd.read_excel(r"C:\Users\liuhao\Desktop\python_work\Python \chapter5\demo\data\bankloan.xls")
x = data[[" "," "," "," "]].values
y = data.iloc[:,8].values
# x = data[[" "," "]].values
# y = data.iloc[:,-1].values
X = sma.add_constant(x)
logit = sma.Logit(y,X)
result = logit.fit()
result.summary2()
from sklearn.linear_model import LogisticRegression
modelLR=LogisticRegression()
modelLR.fit(x,y)
b=modelLR.coef_
a=modelLR.intercept_
print(a,b)
modelLR.score(x,y)
두 가지 방법으로 계산된 매개 변수는 작은 차이가 존재할 수 있다
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
형태소 분석은 데스크톱을 구성하는 데 도움이?문자×기계 학습에 흥미를 가져와 개인 범위의 용도를 생각해, 폴더 정리에 사용할 수 있을까 생각해 검토를 시작했습니다. 이번 검토에서는 폴더 구성 & text의 읽기 → mecab × wordcloud를 실시하고 있...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.