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

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 )#<class 'numpy.ndarray'>
weights=ones(5)#[1. 1.]
# print(type(weights))#<class 'numpy.ndarray'>
# print(type(datematrix ))#ay'><class 'tuple'>
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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容