Week 7: Regression 第 7 周回归
Summary 摘要
Further NumPy: 进一步的 NumPy
array.reshape(shape)
array 矩阵.reshape(shape 形状)
np.linspace(start, end, number of values)
np.linspace(start, end, 数值个数)
np.linspace(start, end, 数值个数)
np.linspace(start, end, number of values)
np.linspace(start, end, 数值个数)
np.linspace(start, end, 数值个数)
np.ones(shape)
np.ones(shape 形状)
Linear algebra operations
线性代数运算transpose:
matrix
.T
转置:matrix
.T
dot product:
np.dot(
vector_1
, vector_2 )
点积:np.dot(
vector_1
, vector_2 )
multiplication:
np.matmul(
matrix_1
, matrix_2 )
ORmatrix_1 @ matrix_2
乘法:np.matmul(
matrix_1
, matrix_2 )
或matrix_1 @ matrix_2
inverse:
np.linalg.inv(
matrix )
逆:np.linalg.inv(
matrix )
np.vstack(( shape ))
np.hstack((
shape ))
np.concatenate((
array_1
, array_2 ))
np.append(
array_1
, array_2 )
Linear Regression: 线性回归
or
Ordinary least squares: analytic solution for regression coefficients
普通最小二乘法:回归系数的解析解
Scikit-Learn: Scikit-Learn
from sklearn.linear_model import LinearRegression
linear_reg = LinearRegression()
linear_reg.fit(features, target variable)
linear_reg.predict(features)
from sklearn.linear_model import LinearRegression
linear_reg = LinearRegression()
linear_reg.fit(features, target variable)
linear_reg.predict(features)
:
linear_reg
.intercept_
:
linear_reg
.coef_
Note: .coef_
is a list. This means that you will need to use .coef_[0]
to extract out the value of β1
注意: .coef_
是一个列表。这意味着您需要使用 .coef_[0]
提取出 β1 的值。