2017-02-28 66 views
0

我一直在玩弄CNTK,并发现模型只能使用numpy数组进行训练。它是否正确?Dataframes,csv和CNTK

这是有道理的,图像识别等

我怎么会变成我的整洁数据集(读如使用熊猫一个数据帧)转换为可以锻炼逻辑回归与格式?我曾试图把它读成numpy的阵列

np.genfromtxt(“My.csv",delimiter=',' , dtype=float) 

,我也试图与

np.array.MyVeriable.astype('float32') 

包裹变量,但我没有得到我想要能够养活一个模型结果。

我也找不到教程中有关如何在CNTK中的表格数据框上执行ML的任何内容。

不支持?

回答

1

感谢您使用这些链接。这是我最后读的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