首先是较为简单的梯度上升算法的回归函数
具体原理啥的不介绍了
直接看代码:
刚开始是导入数据集的操作
总的来说很简单
输出的结果为:
下一个函数是sigmoid函数,这个函数很好写
最后一个函数就是gradAscent函数
这个函数我错了很多次
首先看几个函数
首先是mat函数,功能大概就是将一个输入转换成矩阵类型
只有转换成矩阵类型后,才可以使用相应的函数
python文档为:
>>> help(numpy.mat)
Help on function asmatrix in module numpy.matrixlib.defmatrix:
asmatrix(data, dtype=None)
Interpret the input as a matrix.
Unlike `matrix`, `asmatrix` does not make a copy if the input is already
a matrix or an nd