Azure ML CLI v2使用MLTable创建数据资产

vzgqcmou  于 2022-11-17  发布在  其他
关注(0)|答案(2)|浏览(157)

我通过Azure ML GUI将 parquet 文件上传到blobstorage并创建了数据资产。步骤精确清晰,结果如预期。为了将来使用,我希望使用CLI创建数据资产及其新版本。
基本命令为az ml create data -f <file-name>.yml。文档提供了一个 MLTable 文件的最小示例,该文件应位于 parquet 文件旁边。

# directory in blobstorage
├── data
│   ├── MLTable
│   ├── file_1.parquet
.
.
.
│   ├── file_n.parquet

我仍然不确定如何正确地指定这些文件,以便创建具有列转换的表格数据集。
我需要在yml文件中指定完整路径还是模式?

$schema: https://azuremlschemas.azureedge.net/latest/data.schema.json

type: mltable
name: Test data
description: Basic example for parquet files
path: azureml://datastores/workspaceblobstore/paths/*/*.parquet # pattern or path to dir?

我对 MLTable 文件有更多的困惑:

type: mltable

paths:
  - pattern: ./*.parquet
transformations:
  - read_parquet:
      # what comes here?

例如,我有一个日期格式为%Y-%m%d %H:%M:%S的列,应该将其转换为时间戳。(我至少可以在GUI中提供此信息!)
任何关于此主题的帮助或指向文档的隐藏链接都是很好的。

vnjpjtjt

vnjpjtjt1#

用于从parquet文件转换字符串列的工作MLTable文件如下所示:

--- 
type: mltable
paths: 
  - pattern: ./*.parquet
transformations: 
  - read_parquet: 
      include_path_column: false
  - convert_column_types:
      - columns: column_a
        column_type:
          datetime:
            formats:
              - "%Y-%m-%d %H:%M:%S"
  - convert_column_types:
    - columns: column_b
      column_type:
        datetime:
          formats:
            - "%Y-%m-%d %H:%M:%S"

(By在写入时,将多个列指定为数组的方式不起作用,例如columns: [column_a, column_b]

k97glaaz

k97glaaz2#

若要执行此操作,我们需要检查实验的安装和要求。我们需要具有有效的订阅和工作区。
安装所需得mltable库.
Azure ML中支持4种不同的路径作为参数
·本地计算机路径
·公共服务器上的路径,如HTTP/HTTPS
·Azure存储上的路径(本例中为blob)
·数据存储上的路径
在创建为assert的文件夹中创建一个YAML文件。文件名可以是任何内容(filename.yml)

$schema: https://azuremlschemas.azureedge.net/latest/data.schema.json
type: uri_folder
name: <name_of_data>
description: <description goes here>
path: <path>
to create the data assert using CLI. 
az ml data create -f filename.yml

创建特定文件作为数据资源

$schema: https://azuremlschemas.azureedge.net/latest/data.schema.json
# Supported paths include:
# local: ./<path>/<file>
# blob:  https://<account_name>.blob.core.windows.net/<container_name>/<path>/<file>
# ADLS gen2: abfss://<file_system>@<account_name>.dfs.core.windows.net/<path>/<file>
# Datastore: azureml://datastores/<data_store_name>/paths/<path>/<file>
type: uri_file
name: <name>
description: <description>
path: <uri>

需要根据您的工作区凭据提及所有路径。
创建MLTable文件作为数据资产。
创建一个带有如下数据模式的yml文件,其中包含您案例中的数据

type: mltable
paths:
  - pattern: ./*.filetypeextension
transformations:
  - read_delimited:
      delimiter: ,
      encoding: ascii
      header: all_files_same_headers

使用下面的python代码来使用MLTable

import mltable
table1 = mltable.load(uri="./data")
df = table1.to_pandas_dataframe()

创建MLTable数据资产。使用下面的代码块。

$schema: https://azuremlschemas.azureedge.net/latest/data.schema.json
# path must point to **folder** containing MLTable artifact (MLTable file + data
# Supported paths include:
# blob:  https://<account_name>.blob.core.windows.net/<container_name>/<path>
type: mltable
name: <name_of_data>
description: <description goes here>
path: <path>

Blob是当前需求中的存储机制。
使用相同的过程创建MLTable数据资产

az ml data create -f <file-name>.yml

相关问题