猫史档案馆


四九圣尊

四九圣尊

Lv.1

获赞:3262收藏:1354浏览:123801作品收藏:2805
回复帖子评论
上一页15 页 / 共 15下一页

【优化方法】线性最小二乘 中回复

import numpy as np
import warnings
from matplotlib import pyplot as plt
class least_square():
def __init__(self):
self.number = 2
self.data = []
self.datax = []
self.label = []
self.labely = []
self.p = 0
self.prediction = []
def fit_function_number(self,x):
if x < 2 or int(x) != x:
raise Exception("fit_function's Number can't be this:(Int and larger than 1)", x)
self.number = x
def input_data(self,data,label):
self.datax = data
self.labely = label
data_memroy = []
xdata_memroy = []
for a in range(len(data)):
xdata_memroy = []
for b in range(self.number):
xdata_memroy.append(data[a]**b)
data_memroy.append(xdata_memroy)
self.data = np.array(data_memroy)
self.label = np.array([label]).T
def fit(self):
self.p = np.linalg.inv(self.data.T.dot(self.data))*(self.data.T.dot(self.label))
prediction = np.zeros((len(self.p),self.number))
for a in range(len(self.p)):
prediction += self.p[a]
self.prediction = prediction[0]
warnings.warn('Result is from b-->kn')
return prediction[0]
def predict(self,x):
result = 0
for i in range(self.number):
result += self.prediction[i] * (x**i)
return result
if __name__ == '__main__':
least_square = least_square()
x = [1,2,3,4,5]
y = [7,13,28,40,68]
least_square.fit_function_number(20)
least_square.input_data(x,y)
a = least_square.fit()
plt.scatter(x,y)
x1 = np.linspace(1,6,100)
y1 = least_square.predict(x1)
plt.plot(x1,y1)
plt.show()

2018-11-24T12:09:11 点赞:0

【影评——西虹市首富】之喜剧背后惨不忍睹的真相 中回复

http://www.le.com/ptv/vplay/1938988.html?ch=360_kan

2018-11-30T23:01:23 点赞:0

【梯度下降,最终章】线性回归 中回复

补一下链式求导法则证明:

2018-12-01T11:07:14 点赞:0

【优化方法】神经网络 中回复

import numpy as np
from matplotlib import pyplot as plt
import tqdm
data = np.array([[1,0,1],
[0,0,1],
[1,1,1],
[0,1,1],
[1,1,0]])
label = np.array([[1,0,1,0,1]]).T
np.random.seed(1)
def sigmod(x,der=False):
result = 1/(1+np.exp(-x))
if not der:
return result
else:
return x*(1-x)
lr = 0.1
l0 = 2*np.random.random((3,3))-1
l1 = 2*np.random.random((3,1))-1

for i in tqdm.tqdm(range(100000)):
out0 = sigmod(data.dot(l0))
out1 = sigmod(out0.dot(l1))
loss = np.sum((out1 - label) ** 2)
l1_c = np.dot(out0.T, (label - out1) * sigmod(out1, der=True))
l1 += l1_c*lr
l0 += np.dot(data.T,l1_c.T*sigmod(out0,der=True))*lr
print(out1)

2层神经网络

2018-12-07T21:45:06 点赞:0

【优化方法】神经网络 中回复

多层神经网络对数据的模式有更高的见解,但是它也有很多问题,比如:center_imagecenter_image就很难分辨出(0,1,1)和(1,1,0)的区别。因为它对数据分类的标准不再是公式化的了,而是抽象到了一个更高的层次。

很显然神经网络把1的个数与结果联系在了一次,同时还有一些1的位置关系。但单层神经网络却只能考虑1的位置关系。

2018-12-07T22:26:34 点赞:0

【优化方法】神经网络 中回复

如果想获得更快的收敛速度,可以把损失函数换成交叉熵损失。

2018-12-07T22:27:18 点赞:0

【编程一小时】两行命令教你把.py转为.exe 中回复

点赞

2018-12-08T21:17:38 点赞:0

python库pykit 中回复

请问一下你是怎么把你做的发到pip上去的?

2018-12-09T10:56:16 点赞:0

【优化方法】神经网络 中回复

import numpy as np
from matplotlib import pyplot as plt
import tqdm
data = np.array([[0,0,1],
[0,1,1],
[1,0,1],
[1,1,1]])
label = np.array([[0],
[1],
[1],
[0]])
np.random.seed(1)
layer0 = 2*np.random.random((3,4))-1
l0_b = 1
layer1 = 2*np.random.random((4,1))-1
l1_b = 1

def sigmod(x,deriv=False):
output = 1/(1+np.exp(-x))
if deriv:
return output*(1-output)
else:
return output
lr = 1

for i in tqdm.tqdm(range(100000)):
out1 = sigmod(data.dot(layer0)+l0_b)
out2 = sigmod(out1.dot(layer1)+l1_b)

layer1_error = (label - out2)
layer1_deriv = layer1_error*sigmod(out2,True)

layer0_error = layer1_deriv.dot(layer1.T)
layer0_deriv = layer0_error*sigmod(out1,True)

layer1 += out1.T.dot(layer1_deriv)*lr
l1_b += layer1_deriv
layer0 += data.T.dot(layer0_deriv)*lr
l0_b += layer0_deriv

print(out2)

之前的两层有个地方写错了,忘记加乘l1了,改了一下现在,然后加了一个偏置单元

2018-12-14T20:23:34 点赞:0

【优化方法】神经网络 中回复

用这个算法分类之前的鸢尾花:

import numpy as np
from matplotlib import pyplot as plt
import tqdm
from sklearn.datasets import load_iris

data_f = load_iris()
target = data_f.target.tolist()
data = data_f.data
data = [x.tolist() for x in data]
del data[90:150]
del target[90:150]
for i in range(len(data)):
del data[i][2:4]
data = np.array(data)
label = np.array([target]).T

np.random.seed(1)
layer0 = 2*np.random.random((2,30))-1
l0_b = 1
layer1 = 2*np.random.random((30,1))-1
l1_b = 1

def sigmod(x,deriv=False):
output = 1/(1+np.exp(-x))
if deriv:
return output*(1-output)
else:
return output
lr = 0.01

for i in range(100000):
out1 = sigmod(data.dot(layer0)+l0_b)
out2 = sigmod(out1.dot(layer1)+l1_b)


layer1_error = (label - out2)
layer1_deriv = layer1_error*sigmod(out2,True)

layer0_error = layer1_deriv.dot(layer1.T)
layer0_deriv = layer0_error*sigmod(out1,True)

layer1 += out1.T.dot(layer1_deriv)*lr
l1_b += layer1_deriv
layer0 += data.T.dot(layer0_deriv)*lr
l0_b += layer0_deriv
print("Loss:" + str(np.mean(layer1_error)) + " 第" + str(i) + "/100000轮")

print(out2)

2018-12-14T20:33:09 点赞:0

【强化学习】寻路 中回复

2018-12-23T16:41:47 点赞:1

【数据分析】pca 中回复

这个有点儿笼统。如果想听详细过程:http://open.163.com/movie/2008/1/M/E/M6SGF6VB4_M6SGKIEME.html(珍惜生命从38分钟开始)

2019-01-21T21:08:13 点赞:0

【py超级大事件】作品盗版监测器正式版发布!(为exe格式,兼容全部电脑) 中回复

多老的东西了。。。

不过现在应该还可以用,因为现在盗版都很不走心,随便抄。

2019-01-24T22:25:15 点赞:0

【MC服务器】RE:从零开始的基于Bukkit服务器制作生活 1.服务器准备 中回复

外网电脑能连进来吗?

2019-01-25T21:19:51 点赞:0

【MC服务器】RE:从零开始的基于Bukkit服务器制作生活 1.服务器准备 中回复

顶!

2019-01-25T21:29:08 点赞:0

【MC服务器】RE:从零开始的基于Bukkit服务器制作生活 1.服务器准备 中回复

max的起床战争服务器,宣传一下:

ip:111.231.202.126

版本:1.8.x

又要来的小伙伴快来!!

2019-01-26T12:40:01 点赞:0

【MC服务器】RE:从零开始的基于Bukkit服务器制作生活 2.安装开发工具(IDE) 中回复

顶!!

2019-01-26T15:07:55 点赞:0

硅谷游第一天 中回复

老弟,去年我最后几天才去哪里呢!

2019-01-27T12:30:53 点赞:0

硅谷游第一天 中回复

玩的愉快!替我向一个叫lhy的人问好!

2019-01-27T12:31:08 点赞:0

【编程猫硅谷游第一天】游玩感想 中回复

emotion_编程猫_点赞

2019-01-27T12:36:10 点赞:0

编程猫2019硅谷游游记(<_<) 中回复

emotion_编程猫_点赞

2019-01-27T12:42:41 点赞:0

过去这一年【tc的随笔】 中回复

小时候看都没看懂过里面主人公及其炫酷的解题过程。。。emotion_编程猫_搓头

2019-01-28T20:03:58 点赞:0

【2019喵硅谷游学第三天——李辛泓(是人就来看)】 中回复

听说你们在看电影时又都睡着了!哈哈哈哈!去年我也睡着了,那个椅子是真的舒服!

2019-01-29T11:39:26 点赞:0

硅谷游第三天 中回复

这只鳄鱼还活着a!

2019-01-29T11:42:46 点赞:0

喵编辑器怎么自定义积木 中回复

008大佬。祝我好运连连

2019-01-29T21:15:58 点赞:0

游斯坦福大学有感 中回复

写得好!

2019-01-30T21:32:27 点赞:0

【新人报道】这里是江南游戏开发社! 中回复

大佬您开发的游戏把我们之前的写的打得渣都不剩,厉害!

请问你初几?

2019-01-31T11:02:31 点赞:0

【萌新】如何制作一个Game AI? 中回复

https://shequ.codemao.cn/community/172512

2019-02-04T19:46:10 点赞:0

【机器学习基础】10分钟让你了解微积分中的微分 中回复

2019-02-04T19:50:48 点赞:0