import numpy as np import pandas as pd data = pd.read_csv("data/预处理.csv", header=None); data = np.array(data) cluster = [] # 按第二个到第十四个标签分类 for i in range(178): if len(cluster) == 0: cluster.append([0]) else: m = 0 for j in range(len(cluster)): n = 0 for x in range(1, 14): if data[i][x] == data[j][x]: n = n + 1 if n == 2: cluster[j].append(i) m = 1 if m == 0: cluster.append([i]) for i in range(len(cluster)): for j in range(len(cluster)): if cluster[i] == cluster[j] and i != j: cluster[j] = 0 for i in range(len(cluster)): print( cluster[i]) xiu1 = [] for t in range(178): if data[t][0] ==1: xiu1.append(t) xiu2 = [] for t in range(178): if data[t][0] == 2: xiu2.append(t) xiu3 = [] for t in range(178): if data[t][0] == 3: xiu3.append(t) print(xiu1) print(xiu2) print(xiu3)修改并完善代码,只用简单的for循环不用decision,使他能分别输出xiu1,xiu2,xiu3在所有13个条件属性的下近似,
时间: 2024-04-13 19:29:28 浏览: 117
你可以使用以下代码来修改并完善你的代码,以输出xiu1、xiu2和xiu3在所有13个条件属性下的近似值:
```python
import numpy as np
import pandas as pd
data = pd.read_csv("data/预处理.csv", header=None)
data = np.array(data)
cluster = []
# 按第二个到第十四个标签分类
for i in range(178):
if len(cluster) == 0:
cluster.append([0])
else:
m = 0
for j in range(len(cluster)):
n = 0
for x in range(1, 14):
if data[i][x] == data[j][x]:
n = n + 1
if n == 2:
cluster[j].append(i)
m = 1
if m == 0:
cluster.append([i])
xiu1 = []
for t in range(178):
if data[t][0] == 1:
xiu1.append(t)
xiu2 = []
for t in range(178):
if data[t][0] == 2:
xiu2.append(t)
xiu3 = []
for t in range(178):
if data[t][0] == 3:
xiu3.append(t)
# 计算xiu1在所有13个条件属性下的近似值
approximations_xiu1 = []
for col in range(1, 14): # 遍历所有13个条件属性列
approx = sum(data[t][col] for t in xiu1) / len(xiu1) # 计算平均值作为近似值
approximations_xiu1.append(approx)
# 计算xiu2在所有13个条件属性下的近似值
approximations_xiu2 = []
for col in range(1, 14): # 遍历所有13个条件属性列
approx = sum(data[t][col] for t in xiu2) / len(xiu2) # 计算平均值作为近似值
approximations_xiu2.append(approx)
# 计算xiu3在所有13个条件属性下的近似值
approximations_xiu3 = []
for col in range(1, 14): # 遍历所有13个条件属性列
approx = sum(data[t][col] for t in xiu3) / len(xiu3) # 计算平均值作为近似值
approximations_xiu3.append(approx)
print("xiu1 近似值:", approximations_xiu1)
print("xiu2 近似值:", approximations_xiu2)
print("xiu3 近似值:", approximations_xiu3)
```
这样,你就可以得到xiu1、xiu2和xiu3在所有13个条件属性下的近似值。希望这能帮到你!
阅读全文