현재 4 개의 변수가있는 데이터 세트에 대해 다항 회귀를 수행하는 다음 코드가 있습니다.
def polyreg():
dataset = genfromtxt(open('train.csv','r'), delimiter=',', dtype='f8')[1:]
target = [x[0] for x in dataset]
train = [x[1:] for x in dataset]
test = genfromtxt(open('test.csv','r'), delimiter=',', dtype='f8')[1:]
poly = PolynomialFeatures(degree=2)
train_poly = poly.fit_transform(train)
test_poly = poly.fit_transform(test)
clf = linear_model.LinearRegression()
clf.fit(train_poly, target)
savetxt('polyreg_test1.csv', clf.predict(test_poly), delimiter=',', fmt='%f')
Excel에서와 같이 회귀 요약을 출력하는 방법이 있는지 알고 싶었습니다. linear_model.LinearRegression ()의 속성 / 방법을 탐색했지만 아무것도 찾을 수 없었습니다.
이것은 scikit-learn에서 구현되지 않습니다. scikit-learn 생태계는 모델 평가를 위해 교차 검증을 사용하는쪽으로 편향되어 있습니다 (제 생각에 이것은 좋은 것입니다. 대부분의 테스트 통계는 컴퓨터가 교차 검증이 가능할만큼 강력하기 전에 필요에 따라 개발되었습니다).
사용할 수있는보다 전통적인 유형의 통계 분석을 위해 statsmodels
다음은 해당 문서에서 가져온 예입니다 .
import numpy as np
import statsmodels.api as sm
nsample = 100
x = np.linspace(0, 10, 100)
X = np.column_stack((x, x**2))
beta = np.array([1, 0.1, 10])
e = np.random.normal(size=nsample)
X = sm.add_constant(X)
y = np.dot(X, beta) + e
model = sm.OLS(y, X)
results = model.fit()
print(results.summary())
OLS Regression Results
==============================================================================
Dep. Variable: y R-squared: 1.000
Model: OLS Adj. R-squared: 1.000
Method: Least Squares F-statistic: 4.020e+06
Date: Sun, 01 Feb 2015 Prob (F-statistic): 2.83e-239
Time: 09:32:32 Log-Likelihood: -146.51
No. Observations: 100 AIC: 299.0
Df Residuals: 97 BIC: 306.8
Df Model: 2
Covariance Type: nonrobust
==============================================================================
coef std err t P>|t| [95.0% Conf. Int.]
------------------------------------------------------------------------------
const 1.3423 0.313 4.292 0.000 0.722 1.963
x1 -0.0402 0.145 -0.278 0.781 -0.327 0.247
x2 10.0103 0.014 715.745 0.000 9.982 10.038
==============================================================================
Omnibus: 2.042 Durbin-Watson: 2.274
Prob(Omnibus): 0.360 Jarque-Bera (JB): 1.875
Skew: 0.234 Prob(JB): 0.392
Kurtosis: 2.519 Cond. No. 144.
==============================================================================
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다