python線性迴歸 1

# -*- coding: utf-8 -*-
import numpy as np
from sklearn import linear_model
from sklearn.linear_model import LinearRegression

X = np.array([[1, 1], [1, 2], [2, 2], [2, 3]])
# y = 1 * x_0 + 2 * x_1 + 3
y = np.dot(X, np.array([1, 2])) + 3
reg = LinearRegression().fit(X, y)

print(reg.score(X, y))
print(reg.coef_)
print(reg.intercept_ )

print(reg.predict(np.array([[3, 5]])))
for i in range(0, X.shape[0]):
	#print(X[i].reshape(-1, 2))
	print(reg.predict(X[i].reshape(-1, 2)))

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章