房价预测代码跑错误
Created by: luckeriam
环境:GPU-T4 CPU-2C 内存-4G paddle版本:1.7.1 python:3
出现问题的代码: feature_names = [ 'CRIM', 'ZN', 'INDUS', 'CHAS', 'NOX', 'RM', 'AGE', 'DIS', 'RAD', 'TAX', 'PTRATIO', 'B', 'LSTAT', 'convert' ] feature_num = len(feature_names) data = numpy.fromfile(filename, sep=' ') # 从文件中读取原始数据 data = data.reshape(data.shape[0] // feature_num, feature_num) maximums, minimums, avgs = data.max(axis=0), data.min(axis=0), data.sum(axis=0)/data.shape[0]
for i in six.moves.range(feature_num-1): data[:, i] = (data[:, i] - avgs[i]) / (maximums[i] - minimums[i]) # six.moves可以兼容python2和python3
ratio = 0.8 # 训练集和验证集的划分比例 offset = int(data.shape[0]*ratio) train_data = data[:offset] test_data = data[offset:]
def reader_creator(train_data):
def reader():
for d in train_data:
yield d[:-1], d[-1:]
return reader
train_reader = paddle.batch( paddle.reader.shuffle( reader_creator(train_data), buf_size=500), batch_size=BATCH_SIZE)
test_reader = paddle.batch( paddle.reader.shuffle( reader_creator(test_data), buf_size=500), batch_size=BATCH_SIZE)
出现的报错信息:
NameError Traceback (most recent call last) in 4 ] 5 feature_num = len(feature_names) ----> 6 data = numpy.fromfile(filename, sep=' ') # 从文件中读取原始数据 7 data = data.reshape(data.shape[0] // feature_num, feature_num) 8 maximums, minimums, avgs = data.max(axis=0), data.min(axis=0), data.sum(axis=0)/data.shape[0]
NameError: name 'filename' is not defined