類別:機器學習類別資料轉換

在訓練模型之前,您可以在資料上執行類別轉換。

使用方式

  categorical(vars, outputKind = "ind", maxNumTerms = 1e+06, terms = "",
    ...)

引數

vars

要轉換的字元向量或變數名稱清單。 如果命名,則名稱代表要建立的新變數名稱。

outputKind

指定輸出種類的字元字串。

  • "ind":輸出指標向量。 輸入資料行是類別的向量,而輸出會在輸入資料行中每個位置包含一個指標向量。
  • "bag":輸出多集合向量。 若輸入資料行是類別的向量,則輸出會包含一個向量,其中每個位置中的值都是輸入向量中類別的出現次數。 如果輸入資料行包含單一類別,則指標向量和包向量相等
  • "key":輸出索引。 輸出是類別的整數識別碼 (介於 1 和目錄中的類別數目之間)。
    預設值是 "ind"

maxNumTerms

指定要包含在字典中類別數目上限的整數。 預設值為 1000000。

terms

詞彙或類別的選擇性字元向量。

...

傳送至計算引擎的其他引數。

詳細資料

categorical 轉換會透過資料集傳遞,並在文字資料行上運作以建置類別的字典。 針對每個資料列,輸入資料行中出現的整個文字字串會定義為類別。 類別轉換的輸出是指標向量。 此向量中的每個位置都會對應至字典中的類別,因此其長度是所建置字典的大小。 類別轉換可套用至一或多個資料行,在此情況下,其會針對套用的每個資料行建置個別的字典。

categorical 目前不支援處理因數資料。

定義轉換的 maml 物件。

作者

Microsoft Corporation Microsoft Technical Support

另請參閱

rxFastTreesrxFastForestrxNeuralNetrxOneClassSvmrxLogisticRegression

範例


 trainReviews <- data.frame(review = c( 
         "This is great",
         "I hate it",
         "Love it",
         "Do not like it",
         "Really like it",
         "I hate it",
         "I like it a lot",
         "I kind of hate it",
         "I do like it",
         "I really hate it",
         "It is very good",
         "I hate it a bunch",
         "I love it a bunch",
         "I hate it",
         "I like it very much",
         "I hate it very much.",
         "I really do love it",
         "I really do hate it",
         "Love it!",
         "Hate it!",
         "I love it",
         "I hate it",
         "I love it",
         "I hate it",
         "I love it"),
      like = c(TRUE, FALSE, TRUE, FALSE, TRUE,
         FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE,
         FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, 
         FALSE, TRUE, FALSE, TRUE), stringsAsFactors = FALSE
     )

     testReviews <- data.frame(review = c(
         "This is great",
         "I hate it",
         "Love it",
         "Really like it",
         "I hate it",
         "I like it a lot",
         "I love it",
         "I do like it",
         "I really hate it",
         "I love it"), stringsAsFactors = FALSE)


 # Use a categorical transform: the entire string is treated as a category
 outModel1 <- rxLogisticRegression(like~reviewCat, data = trainReviews, 
     mlTransforms = list(categorical(vars = c(reviewCat = "review"))))
 # Note that 'I hate it' and 'I love it' (the only strings appearing more than once)
 # have non-zero weights
 summary(outModel1)

 # Use the model to score
 scoreOutDF1 <- rxPredict(outModel1, data = testReviews, 
     extraVarsToWrite = "review")
 scoreOutDF1