一、多元方程
x*theta=y =>
theta=x-1 * y =x-1 (xT )-1 xT *y=( (xTx )-1 xT *y
对比梯度下降法和方程:
如果xT x不可逆?
- redundant features(线性相关)
- too much features(m<=n) ->delete some features 或者使用正则化
二、向量化
三、分类
logistic regression:
如果使用线性回归帮助进行分类:
- 使用0.5作为阈值将结果分成两类(但是当增加一个远处的数据,会导致线性回归的参数发生改变,从而分类的结果发生改变)
- 使用线性回归会导致h(x)>1或<0(classification y=0 or 1)
logistic regression:0<=h(x)<=1
假设表示(logistic regression model):
决策界限:
根据以上的假设函数,(theta) T x =0 为decision boundary
注意:决策边界是假设函数的一个属性(如果确定theta值,可以确定决策边界;不同theta值,决策边界也是不同)
非线性决策边界:
如何拟合逻辑回归,确定theta的值:
使用cost function,但是由于sigmoid 函数是非线性的,导致出现很多局部极小值,很难取到全局极小值;导致cost function -> non-convex function
optimization algorithm
-
gradient descent
-
conjugate gradient(共轭梯度法)
-
BFGS
-
L-BFGS
advantage:
- no need to manually pick learning rate
- often faster than gradient descent
disadvantage:
- more complex
多元分类:
进行两两分类:
过拟合:
(1)欠拟合:与预测值有很大的偏差
(2)just right fit
(3)overfit 过拟合:由于过于贴近训练集,而无法预测之后的数据
如何解决过拟合问题:
1、reduce number of features
- manually select which features to keep
- model select algorithm
2、regularization正则化
- keep all the features,but reduce magnitude/values of parameters
- every features contribute a little bit to predict y
作为正则化的第一项:主要是为了拟合数据;第二项:主要是为了使参数更小。
正则化线性回归:
1、梯度下降
2、等式方程
正则化逻辑回归: