티스토리 뷰

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import numpy as np
= np.arange(-10101)
x
= 2*- 1
y
import matplotlib.pyplot as plt
plt.plot(x, y)
print("x 배열의 원소 개수: ", x.shape[0])
idx = np.arange(x.shape[0])
print("기존 인덱스: ", idx)
np.random.shuffle(idx)
print("섞인 인덱스: ", idx)
x_new = x.reshape(-1,1)
x_new
from sklearn.linear_model import LinearRegression
lr = LinearRegression(fit_intercept=False, n_jobs=-1)
lr.fit(x_new, y)
print("기울기: ", lr.coef_)
print("y절편: ", lr.intercept_)
cs

[16] fit_intercept=False인 경우

기울기:  [2.01492537]
y절편:  0.0

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import numpy as np
= np.arange(-10101)
x
= 2*- 1
y
import matplotlib.pyplot as plt
plt.plot(x, y)
print("x 배열의 원소 개수: ", x.shape[0])
idx = np.arange(x.shape[0])
print("기존 인덱스: ", idx)
np.random.shuffle(idx)
print("섞인 인덱스: ", idx)
x_new = x.reshape(-1,1)
x_new
from sklearn.linear_model import LinearRegression
lr = LinearRegression(fit_intercept=True, n_jobs=-1)
lr.fit(x_new, y)
print("기울기: ", lr.coef_)
print("y절편: ", lr.intercept_)
cs

[16] fit_intercept=True인 경우

기울기:  [2.]
y절편:  -0.9999999999999998

 

 

궁금증 1. y절편을 계산하지 않거나/계산하는 것으로 인해 기울기 값의 표시가 달라지는 이유는?