感谢您使用这些链接。这是我最后读的CSV它似乎工作,但萨彦请纠正需要:
def generate_data_from_csv():
# try to find the data file local. If it doesn't report "file does not exists" if it does report "using loacl file"
data_path = os.path.join("MyPath")
csv_file = os.path.join(data_path, "My.csv")
if not os.path.exists(data_path):
os.makedirs(data_path)
if not os.path.exists(data_file):
print("file does not exists")
else:
print("using loacl file")
df = pd.read_csv(csy_file, usecols = ["predictor1", "predictor2",
"predictor3", "predictor4", "dependent_variable"], dtype=np.float32)
return df
然后我保存的数据帧作为training_data
training_data = generate_data_from_csv()
然后我打开那个数据帧到numpy的阵列如下
training_features = np.asarray(training_data[[["predictor1",
"predictor2", "predictor3", "predictor4",]], dtype = "float32")
training_labels = np.asarray(training_data[["dependent_variable"]],
dtype="float32")
的训练我用这个代码的模型:
features, labels = training_features[:,[0,1,2,3]], training_labels