机器学习中回归分析的小知识点

1.随机梯度法用到的数组:
weights=ones(n) 这是与梯度法的不同,以下为知识点总结:
注意这是数组而不是矩阵

from numpy import *
import numpy as np
import math
def sigmoid(inX):
    # return 1/(1+math.exp(-inX))
    return 1/(1+np.exp(-inX))
# weights=(1,2,)
weights=(1,2,3)
mum=ones(3)
# mum=ones(2)
# a=((weights *mum))#[1. 2.]数组对应元素相乘,不是矩阵
a=sum(weights*mum)#3.0 对应元素相乘再家和 对应元素相乘,相当于一个1*2的矩阵乘以2*1的矩阵得到一个数
# a=sigmoid(sum(weights*mum))#0.9525741268224334
print(a)

2.元组array
元组和元组做运算

from numpy import *
import numpy as np

datematrix=(1,2,3,4,5)
datematrix =np.array(datematrix )#
weights=ones(5)#[1. 1.]
# print(type(weights))#
# print(type(datematrix ))#ay'>
weights=weights+0.01*0.03*datematrix 
# weights=weights+0.01*datematrix*0.03
print(weights)

参考:
[python中数组和矩阵乘法及使用总结]https://blog.csdn.net/manjhok/article/details/80017892

你可能感兴趣的:(机器学习中回归分析的小知识点)