我有此代码:
door, window, occupancy_data = [],[],[]
file = open("data.txt",'r')
Title = file.readline()
for line in file:
line_token = line.split(";")
door.append(float(line_token[0])),
window.append(float(line_token[1])),
occupancy_data.append(float(line_token[2])) # store the values of each column in information_gain.txt in 3 seperate lists
file.close()
print(occupancy_data)
def information_gain(feature_data, occupancy_data):
occupancy_data0,occupancy_data1,feature_data0,feature_data1 = [],[],[]
for i in range(len(occupancy_data)):
if feature_data[i] == 0:
feature_data().append(feature_data[i])
occupancy_data().append(occupancy_data[i])
else:
feature_data1.append(feature_data[i])
occupancy_data1.append(occupancy_data[i])
entropy0, entropy1 = entropy(occupancy_data0), entropy(occupancy_data1)
return entropy(occupancy_data) - (len(feature_data0)/len(occupancy_data)) * entropy0 - (len(feature_data1)/len(occupancy_data)) * entropy1
我一直得到这个答案:
回溯(最近通话最近一次):
文件
中的“ C:/Users/User/Dropbox/manage/example2.py”,第2行file = open(“ data.txt”,'r')
FileNotFoundError:[错误2]没有这样的文件或目录:'data.txt'