import csv import numpy as np boston_dir_path = r'D:\annconda\Lib\site-packages\sklearn\datasets\data\boston_house_prices.csv' def load_boston(): with open(boston_dir_path) as f: data_file = csv.reader(f) temp = next(data_file) n_simples = int(temp[0]) n_features = int(temp[1]) data = np.empty((n_simples,n_features)) target = np.empty((n_simples,)) temp = next(data_file) features_name = np.array(temp) for i,d in enumerate(data_file): data[i] = np.asarray(d[:-1],dtype=np.float64) target[i] = np.asarray(d[-1],dtype=np.float64) return data,target if __name__ == '__main__': data,target = load_boston() print(target)
读取csv文档
最新推荐文章于 2023-08-24 16:37:41 发布