0
파이썬으로 생성 된 지수 함수에 대한 선형 회귀 모형을 해석하는 법을 배우려합니다. 자연 로그를 취하여 지수 Y 데이터를 직선으로 변환하여 모델을 만듭니다. 그런 다음 선형 모델을 작성하고 기울기와 절편을 기록합니다. 마지막으로 기울기와 절편을 사용하여 샘플 값을 계산하려고합니다. 특히 X = 1.1 인 경우 Y를 계산하려고합니다. Y는 ~ 2.14이어야하지만 내 모델 해석은 3.78의 Y 값을 산출합니다.파이썬에서 회귀선을 지수 함수에 맞추기
질문 1 : 모델을 해석 할 때 내가 잘못한 점은 무엇입니까?
질문 2 : X 배열을 변형해야하거나 regr.fit에서 오류가 발생합니다. 왜 X 배열을 변형해야합니까?
코드는 다음과 같습니다
import matplotlib.pyplot as plt
import numpy as np
from sklearn import datasets, linear_model
# create some exponential data
X = np.arange(1, 10, 0.1)
print(X)
Y = np.power(2, X)
print(Y)
# transform the exponential Y data to make it a straight line
ln_Y = np.log(Y)
# show the exponential plot
plt.scatter(X, Y)
plt.show()
# Create linear regression object
regr = linear_model.LinearRegression()
# reshape the X to avoid regr.fit errors
X = np.reshape(X, (X.size, 1))
# Train the model using the training sets
regr.fit(X,ln_Y)
# The coefficients
print('Slope: \n', regr.coef_)
print('Intercept: \n', regr.intercept_)
# predict Y when X = 1.1 (should be approximately 2.14354693)
# equation = e^(0.00632309*1.1) + 2.7772517886
print("predicted val = ", np.exp(0.00632309*1.1) + 2.7772517886)
이 대단히 maxymoo 감사드립니다. 나는 내 scikit을 업데이트했고 당신과 같은 계수를 가졌습니다. 전체 표현식의 exp를 취하여 모델을 해석하는 방법에 대한 팁과 구체적인 예를 가져 주셔서 감사합니다. 당신은 학자이고 신사입니다! – user3457456