代码拉取完成,页面将自动刷新
#-*- coding = utf-8 -*-
#@Time : 2021/4/28 9:51
#@Author : Zyh
#@File : logic_zr.py
#@Software : PyCharm
import numpy as np
class logic_more:
def loaddata(self,fn):
x= []
y=[]
with open(fn,'r') as f:
file = f.readlines()
# print(file)
for line in file:
line = line.strip().split()
# print(line[0])
x.append([float(line[0]),float(line[1]),float(line[2]),float(line[3]),float(line[4]),
float(line[5])])
y.append(float(line[-1]))
npx = np.array(x)
maxv = npx.max(0)
minv = npx.min(0)
ranges = maxv - minv
m = npx.shape[0]
x = [1]
xxx = np.tile(x, (m, 1))
normData = npx - np.tile(minv, (m, 1))
normData = normData / np.tile(ranges, (m, 1))
normData = np.column_stack((xxx, normData))
xmat = np.mat(normData)
# print(type(xmat))
ymat = np.mat(y).T
# print(xmat)
# print(ymat)
return xmat,ymat
def w_calc(self,xmat,ymat,alpha=0.001,maxg = 500):
# w._int
w = np.mat(np.random.randn(7,1))
# w updata Tzhuanzhi
for i in range(maxg):
H = 1 /(1 + np.exp(-xmat*w))
dw = xmat.T*(H-ymat)
w -= alpha*dw
return w
def w_cl(self,xmat,ymat,w):
m = xmat.shape[0]
y_yc = xmat*w
y_yc = np.sum(y_yc,axis=1)
y = y_yc.tolist()
xm = 0
ym = 0
for item in y:
if item[0] > 0.5:
xm += 1
else:
ym += 1
sum_y = np.sum(ymat)
return xm/sum_y
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。