快速上手大模型:机器学习3
学习目的:
让线性回归更快、更强大。
1 多元线性回归(Multiple liner regression)
1.1 定义
:第j个特征;
n:特征总数;
:第i个训练样本的所有特征;
:第j个特征第i个训练样本。
多元线性回归(Multiple liner regression):多个输入特征的线性回归模型,表达式
。
1.2 向量化
1.2.1 例子
向量化使代码简洁、运行高效。
1.2.2 代码实现
使用Python编译,调用NumPy包
(1)引入模块/包
import numpy as np # it is an unofficial standard to use np for numpy import time
(2)数组创建
代码:
# NumPy routines which allocate memory and fill arrays with value a = np.zeros(4); print(f"np.zeros(4) : a = {a}, a shape = {a.shape}, a data type = {a.dtype}") a = np.zeros((4,)); print(f"np.zeros(4,) : a = {a}, a shape = {a.shape}, a data type = {a.dtype}") a = np.random.random_sample(4); print(f"np.random.random_sample(4): a = {a}, a shape = {a.shape}, a data type = {a.dtype}")
输出:
# NumPy routines which allocate memory and fill arrays with value a = np.zeros(4); print(f"np.zeros(4) : a = {a}, a shape = {a.shape}, a data type = {a.dtype}") a = np.zeros((4,)); print(f"np.zeros(4,) : a = {a}, a shape = {a.shape}, a data type = {a.dtype}") a = np.random.random_sample(4); print(f"np.random.random_sample(4): a = {a}, a shape = {a.shape}, a data type = {a.dtype}")
np.zeros(4)
:创建一个长度为4的数组,所有元素都是0.0
(浮点数);
a.shape
:数组形状(这里是(4,)
,表示一维数组长度 4;
a.dtype
:数据类型。