免责声明:网站内容仅供个人学习记录,禁做商业用途,转载请注明出处。

版权所有 © 2017-2020 NEUSNCP个人学习笔记 辽ICP备17017855号-2

机器学习(3)

rick    2017年12月18日 10:49:29

太监,编写博客太累了,发现网上有很多斯坦福机器学习的学习博客和笔记。比较好的有这两篇。

http://blog.csdn.net/artprog/article/details/51280821

https://mooc.guokr.com/note/16274/

这里贴一个自己写的正规方程的python实现,利用numpy,很短

import numpy as np

# y = 3 + 2 * x1 + 1 * x2
x_train = np.array([[1, 2], [2, 1], [2, 3], [3, 5], [1, 3], [4, 2], [7, 3], [4, 5], [11, 3], [8, 7]])
y_train = np.array([7, 8, 10, 14, 8, 13, 20, 16, 28, 26])

X = np.mat(np.zeros((len(x_train), 3)))


# 形成新向量
def newArray(l):
    c = len(l) + 1
    newA = np.array(np.zeros(c))
    newA[0] = 1
    i = 1
    while i < c:
        newA[i] = l[i - 1]
        i += 1
    return newA

i = 0

# 化为矩阵
while i < np.shape(X)[0]:
    thisArray = newArray(x_train[i])
    X[i] = thisArray
    # a1[i][1] = x_train[i][0]
    # a1[i][2] = x_train[i][1]
    i += 1

Y = np.mat(y_train).T
XT = X.T

Theta = (XT * X).I * XT * Y
print(Theta)

 

浏览: 1.8K

[[total]] 条评论

添加评论
  1. [[item.time]]
    [[item.user.username]] [[item.floor]]楼
  2. 点击加载更多……
  3. 添加评论