categoricalHash:Machine Learning 類別雜湊資料轉換

在定型模型之前,您可以在資料上執行類別雜湊轉換。

使用方式

  categoricalHash(vars, hashBits = 16, seed = 314489979, ordered = TRUE,
    invertHash = 0, outputKind = "Bag", ...)

引數

vars

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

hashBits

整數,指定要雜湊的位元數。 必須介於 1 到 30 (含) 之間。 預設值為 16。

seed

指定雜湊種子的整數。 預設值為 314489979。

ordered

TRUE 會在雜湊中包含每個字詞的位置。 否則為 FALSE。 預設值是 TRUE

invertHash

指定可用來產生位置名稱索引鍵數目限制的整數。 0 表示沒有反轉雜湊;-1 表示沒有限制。 雖然零值可提供更好的效能,但需要非零值才能取得有意義的係數名稱。 預設值是 0

outputKind

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

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

...

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

詳細資料

categoricalHash 會透過雜湊值及將雜湊用為包中的索引,將類別值轉換成指標陣列。 如果輸入資料行是向量,則會為其傳回單一指標包。

categoricalHash 目前不支援處理因子資料。

定義轉換的 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 hash transform
 outModel2 <- rxLogisticRegression(like~reviewCatHash, data = trainReviews, 
     mlTransforms = list(categoricalHash(vars = c(reviewCatHash = "review"))))
 # Weights are similar to categorical
 summary(outModel2)

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