microsoftml.rx_featurize:資料來源資料轉換

使用量

microsoftml.rx_featurize(data: typing.Union[revoscalepy.datasource.RxDataSource.RxDataSource,
    pandas.core.frame.DataFrame],
    output_data: typing.Union[revoscalepy.datasource.RxDataSource.RxDataSource,
    str] = None, overwrite: bool = False,
    data_threads: int = None, random_seed: int = None,
    max_slots: int = 5000, ml_transforms: list = None,
    ml_transform_vars: list = None, row_selection: str = None,
    transforms: dict = None, transform_objects: dict = None,
    transform_function: str = None,
    transform_variables: list = None,
    transform_packages: list = None,
    transform_environment: dict = None, blocks_per_read: int = None,
    report_progress: int = None, verbose: int = 1,
    compute_context: revoscalepy.computecontext.RxComputeContext.RxComputeContext = None)

說明

將輸入資料集轉換成輸出資料集。

論點

資料

例如 revoscalepy 的資料來源物件、資料框架,或檔案 .xdf 的路徑。

output_data

輸出文字或 xdf 檔名,或 RxDataSource 具備寫入功能以儲存轉換後的資料。 若 為 N,則回傳一個資料框。 預設值是 None

覆寫

Trueoutput_data則存在被覆寫;若Falseoutput_data存在未被覆寫。 預設值為 False

data_threads

一個整數,指定資料管線中所需的平行程度。 若 ,則執行緒數量由內部決定。 預設值是 None

random_seed

指定隨機種子。 預設值是 None

max_slots

最大回傳向量值欄位的槽位數(<=0 以返回全部)。

ml_transforms

指定一份在訓練前要對資料執行的 MicrosoftML 轉換清單,或是「若不執行轉換則 」。 參見 featurize_textcategoricalcategorical_hash和 ,以了解支援的轉換。 這些轉換會在指定的 Python 轉換後執行。 預設值是 None

ml_transform_vars

指定一個變數名稱的字元向量, ml_transforms 若不使用變數名稱,則指定為 None 。 預設值是 None

row_selection

不支援。 指定資料集中的列(觀察值),模型將使用資料集中的邏輯變數名稱(引號內)或使用資料集中變數的邏輯表達式。 例如:

  • row_selection = "old" 僅使用變數 old 值為 True的觀測值。

  • row_selection = (age > 20) & (age < 65) & (log(income) > 10)僅使用變數值age介於20至65之間且變數值logincome大於10的觀測值。

列選擇是在處理任何資料轉換後執行的(參見參數 transformstransform_function)。 與所有表達式一樣, row_selection 可以在函 expression 式呼叫之外使用函式定義。

變換

不支援。 代表第一輪變數轉換的表達式。 與所有表達式一樣, transforms (或 row_selection)可以在函式呼叫之外使用函 expression 式定義。 預設值是 None

transform_objects

不支援。 一個命名的清單,包含可被 transformstransform_functionrow_selection和 所引用的物件。 預設值是 None

transform_function

變數轉換函數。 預設值是 None

transform_variables

一個用於轉換函數所需的輸入資料集變數的字元向量。 預設值是 None

transform_packages

不支援。 一個字元向量,指定額外 Python 套件(除 在 中 RxOptions.get_option("transform_packages")指定的套件外)可供並預載,用於變數轉換函數。 例如,在 revoscalepy 函式中透過其 transformstransform_function 參數明確定義的函數,或是透過 their formularow_selection 參數隱含定義的函式。 transform_packages參數也可能是 None,表示外部沒有RxOptions.get_option("transform_packages")套件被預先載入。

transform_environment

不支援。 一個由使用者定義的環境,作為所有內部開發環境的父環境,並用於變量資料轉換。 如果 transform_environment = None,則會使用新的「雜湊」環境,父 revoscalepy.baseenv 為母節點,預設值為 None

blocks_per_read

指定從資料來源讀取的每一塊資料要讀取的區塊數量。

report_progress

一個整數值,用來指定對資料列處理進度的報告層級:

  • 0:沒有進展報告。

  • 1:已處理的列數會被列印並更新。

  • 2:處理的行數及時間報告。

  • 3:列數已處理,所有時間點都會被報告。

預設值為 1

詳細資訊

一個整數值,用來指定想要輸出的量。 若 0,則計算過程中不會印出冗長輸出。 整數值 來自 14 提供越來越多的資訊。 預設值為 1

compute_context

設定計算執行的上下文,並以有效的 revoscalepy 指定。RxComputeContext。 目前是局部且 revoscalepy。支援 RxInSqlServer 的運算上下文。

Returns

資料框架或 revoscalepy。RxDataSource 物件代表所建立的輸出資料。

範例

'''
Example with rx_featurize.
'''
import numpy
import pandas
from microsoftml import rx_featurize, categorical

# rx_featurize basically allows you to access data from the MicrosoftML transforms
# In this example we'll look at getting the output of the categorical transform
# Create the data
categorical_data = pandas.DataFrame(data=dict(places_visited=[
                "London", "Brunei", "London", "Paris", "Seria"]),
                dtype="category")
                
print(categorical_data)

# Invoke the categorical transform
categorized = rx_featurize(data=categorical_data,
                           ml_transforms=[categorical(cols=dict(xdatacat="places_visited"))])

# Now let's look at the data
print(categorized)

輸出:

  places_visited
0         London
1         Brunei
2         London
3          Paris
4          Seria
Beginning processing data.
Rows Read: 5, Read Time: 0, Transform Time: 0
Beginning processing data.
Beginning processing data.
Rows Read: 5, Read Time: 0, Transform Time: 0
Beginning processing data.
Elapsed time: 00:00:00.0521300
Finished writing 5 rows.
Writing completed.
  places_visited  xdatacat.London  xdatacat.Brunei  xdatacat.Paris  \
0         London              1.0              0.0             0.0   
1         Brunei              0.0              1.0             0.0   
2         London              1.0              0.0             0.0   
3          Paris              0.0              0.0             1.0   
4          Seria              0.0              0.0             0.0   

   xdatacat.Seria  
0             0.0  
1             0.0  
2             0.0  
3             0.0  
4             1.0