【问题标题】:Dataframes, csv, and CNTK数据帧、csv 和 CNTK
【发布时间】:2017-02-28 00:37:56
【问题描述】:

我一直在玩 CNTK,发现只能使用 numpy 数组来训练模型。这是正确的吗?

这对图像识别等有意义。

如何将我的整洁数据集(使用 pandas 作为数据框读入)转换为可以训练逻辑回归的格式?我试图将它读入一个 numpy 数组

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

我也尝试用

包装变量
np.array.MyVeriable.astype('float32')

但我没有得到我希望能够为模型提供数据的结果。

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

不支持吗?

【问题讨论】:

    标签: pandas dataframe cntk


    【解决方案1】:

    【讨论】:

    • 如果你真的看那里,CNTK 106B 使用 df = pd.read_csv。所以你的答案实际上只是“1.使用熊猫。2.使用熊猫。”
    【解决方案2】:

    感谢这些链接。这就是我最终在 csv 中阅读的方式,它似乎有效,但 Sayan 请根据需要进行更正:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-18
      • 2018-08-11
      • 1970-01-01
      • 2018-11-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多