반응형
Notice
Recent Posts
Recent Comments
Link
관리 메뉴

bro's coding

sklearn.linear_model.Ridge.alpha에 따른 회귀선 변화 관찰 본문

[AI]/python.sklearn

sklearn.linear_model.Ridge.alpha에 따른 회귀선 변화 관찰

givemebro 2020. 4. 19. 21:34
반응형

from sklearn.linear_model import LinearRegression, Ridge, Lasso

from sklearn.linear_model import LinearRegression, Ridge, Lasso

 

from sklearn.datasets import load_iris

iris = load_iris()
X = iris.data[:, [0]]
y = iris.data[:, 2]

 

plt.scatter(X, y)
plt.axis('equal')

model = LinearRegression()
model.fit(X, y)
w = model.coef_[0]
b = model.intercept_
print(model.score(X, y), model.coef_)

# 0.7599553107783261 [1.85750967]

 

plt.scatter(X, y)
plt.axis('equal')

x = np.array([4,8])
plt.plot(x, w*x+b)

model = Ridge(alpha=100)
model.fit(X, y)
w = model.coef_[0]
b = model.intercept_
print(model.score(X, y), model.coef_)

# 0.5740200348062152 [0.93871609]

 

plt.scatter(X, y)
plt.axis('equal')

x = np.array([4,8])
plt.plot(x, w*x+b)

model = Lasso(alpha=1000)
model.fit(X, y)
w = model.coef_[0]
b = model.intercept_
print(model.score(X, y), model.coef_)

# 0.0 [0.]

 

plt.scatter(X, y)
plt.axis('equal')

x = np.array([4,8])
plt.plot(x, w*x+b)

alpha 값에 커질 수록 회귀선이 점들을 잘 표현 하지 못 한다.

반응형
Comments