感謝您使用這些鏈接。這是我最後讀的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