import numpy as np
import random
# 线性数据集、过原点
def get_beans(counts):
xs = np.random.rand(counts)
xs = np.sort(xs)
ys = [1.2 * x + np.random.rand() / 10 for x in xs]
return xs, ys
# 线性数据集、过原点 带正负号
def get_beans2(counts):
xs = np.random.rand(counts) * 10 - 5
xs = np.sort(xs)
ys = [2.3 * x + np.random.rand() for x in xs]
return xs, ys
# 线性数据集、带截距
def get_beans3(counts):
xs = np.random.rand(counts)
xs = np.sort(xs)
ys = np.array([(0.7 * x + (0.5 - np.random.rand()) / 5 + 0.5) for x in xs])
return xs, ys
#
def get_beans4(counts):
xs = np.random.rand(counts)
xs = np.sort(xs)
ys = np.zeros(counts)
for i in range(counts):
x = xs[i]
yi = 0.7 * x + (0.5 - np.random.rand()) / 50 + 0.5
if yi > 0.8:
ys[i] = 1
return xs, ys
def get_beans5(counts):
xs = np.random.rand(counts) * 2
xs = np.sort(xs)
ys = np.zeros(counts)
for i in range(counts):
x = xs[i]
yi = 0.7 * x + (0.5 - np.random.rand()) / 50 + 0.5
if yi > 0.8 and yi < 1.4:
ys[i] = 1
return xs, ys
def get_beans6(counts):
xs = np.random.rand(counts, 2) * 2
ys = np.zeros(counts)
for i in range(counts):
x = xs[i]
if (x[0] - 0.5 * x[1] - 0.1) > 0:
ys[i] = 1
return xs, ys
def get_beans7(counts):
xs = np.random.rand(counts, 2) * 2
ys = np.zeros(counts)
for i in range(counts):
x = xs[i]
if (np.power(x[0] - 1, 2) + np.power(x[1] - 0.3, 2)) < 0.5:
ys[i] = 1
return xs, ys
# 定义函数get_house_prices,参数为样本数量counts
def get_house_prices(counts):
# 生成counts个随机数表示房屋的面积,并赋值给sizes(假设面积在50到200平方米之间)
sizes = np.random.uniform(50, 200, counts)
# 对sizes进行排序
sizes = np.sort(sizes)
# 生成prices,其中每个值为3000倍的sizes加上一个在0到50000之间的随机数
prices = [3000 * size + np.random.uniform(0, 50000) for size in sizes]
# 返回sizes和prices
return sizes, prices
def get_beans8(counts):
posX, posY = genSpiral(int(counts / 2), 0, 1)
negX, negY = genSpiral(int(counts / 2), np.pi, 0)
X = np.vstack((posX, negX))
Y = np.hstack((posY, negY))
return X, Y
def genSpiral(counts, deltaT, label):
X = np.zeros((counts, 2))
Y = np.zeros(counts)
for i in range(counts):
r = i / counts * 5
t = 1.75 * i / counts * 2 * np.pi + deltaT;
x1 = r * np.sin(t) + random.uniform(-0.1, 0.1)
x2 = r * np.cos(t) + random.uniform(-0.1, 0.1)
X[i] = np.array([x1, x2])
Y[i] = label
return X, Y
def dist(a, b):
dx = a['x'] - b['x'];
dy = a['y'] - b['y'];
return np.sqrt(dx * dx + dy * dy);
def getCircleLabel(p, center):
radius = 1;
if dist(p, center) < (radius * 0.5):
return 1
else:
return 0
def randUniform(a=-1, b=1):
return np.random.rand() * (b - a) + a;
def classifyCircleData(numSamples=100, noise=0):
points = [];
Y = []
X = []
radius = 1;
num = int(numSamples / 2)
for i in range(num):
r = randUniform(0, radius * 0.5);
angle = randUniform(0, 2 * np.pi);
x = r * np.sin(angle);
y = r * np.cos(angle);
noiseX = randUniform(-radius, radius) * noise;
noiseY = randUniform(-radius, radius) * noise;
label = getCircleLabel({'x': x + noiseX, 'y': y + noiseY}, {'x': 0, 'y': 0});
X.append([x + 1, y + 1])
Y.append(label)
for i in range(num):
r = randUniform(radius * 0.7, radius);
angle = randUniform(0, 2 * np.pi);
x = r * np.sin(angle);
y = r * np.cos(angle);
noiseX = randUniform(-radius, radius) * noise;
noiseY = randUniform(-radius, radius) * noise;
label = getCircleLabel({'x': x + noiseX, 'y': y + noiseY}, {'x': 0, 'y': 0});
X.append([x + 1, y + 1])
Y.append(label)
X = np.array(X)
Y = np.array(Y)
return X, Y
物联通信社区
- 粉丝: 54
- 资源: 3
最新资源
- 卡通手绘小太阳女孩城市元素小学生家长会模板.pptx
- 蓝色天空少年彩虹小学家长会模板.pptx
- 可爱卡通手绘树木花朵幼儿园家长会模板.pptx
- 小学新学期家长会模板.pptx
- 上海中小学新学年家长会模板.pptx
- 手绘铅笔纸飞机元素小学生家长会模板.pptx
- 中学八年级新学期家长会模板.pptx
- 大数据自动化部署,包括自动化部署hadoop、hive、hbase、spark、storm等等一系列组件.zip
- 模糊控制SOC主动均衡,模糊控制(FLC)电池SOC均衡,四节电池,电路拓扑为buck- boost,控制方法为差值-平均值模糊控制,用于控制均衡电流大小,加快电池均衡,另外有与传统仿真对比实验
- 大数据验收项目.zip
- 天池大数据淘宝穿衣搭配算法.zip
- 天池大数据竞赛《广东省政务数据创新大赛-智能算法赛》 数据切分.zip
- 广东工业大学课程设计 数据库课程设计 平行志愿录取系统(后端代码,广东工业大学数据库大作业) 基于java、spring、MySQL数据库、vue.js的课程设计.zip
- 微信大数据赛初赛10th,复赛14th.zip
- 基于Python与Tkinter的多功能商品信息管理系统的开发及应用(文档包括可运行代码)
- 数据可视化,大屏, 支持Echarts,SQL,API,VUE,可用于Jupyter, 比pyecharts容易, 极低门槛,拿来即用,比拖拽方便,项目插件或独立平台皆可, 简单, 敏捷, 高.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈