私はいくつかの結果を予測するためにテキストを使用する、非常に単純なML学習問題を実装しようとしています。 Rには、いくつかの基本的な例は次のようになります。私のテキストのスパース行列表現を得るためにH20:テキストデータのグラデーションブーストを使用する方法は?
輸入いくつかの偽物が、面白いテキストデータ
library(caret)
library(dplyr)
library(text2vec)
dataframe <- data_frame(id = c(1,2,3,4),
text = c("this is a this", "this is
another",'hello','what???'),
value = c(200,400,120,300),
output = c('win', 'lose','win','lose'))
> dataframe
# A tibble: 4 x 4
id text value output
<dbl> <chr> <dbl> <chr>
1 1 this is a this 200 win
2 2 this is another 400 lose
3 3 hello 120 win
4 4 what??? 300 lose
使用text2vec
#these are text2vec functions to tokenize and lowercase the text
prep_fun = tolower
tok_fun = word_tokenizer
#create the tokens
train_tokens = dataframe$text %>%
prep_fun %>%
tok_fun
it_train = itoken(train_tokens)
vocab = create_vocabulary(it_train)
vectorizer = vocab_vectorizer(vocab)
dtm_train = create_dtm(it_train, vectorizer)
> dtm_train
4 x 6 sparse Matrix of class "dgCMatrix"
what hello another a is this
1 . . . 1 1 2
2 . . 1 . 1 1
3 . 1 . . . .
4 1 . . . . .
(も
https://github.com/dselivanov/text2vec/blob/master/vignettes/text-vectorization.Rmdを参照してください)
最後に、私のスパース行列を使用してoutput
を予測するためにアルゴをトレーニングします(たとえば、caret
を使用)。
mymodel <- train(x=dtm_train, y =dataframe$output, method="xgbTree")
> confusionMatrix(mymodel)
Bootstrapped (25 reps) Confusion Matrix
(entries are percentual average cell counts across resamples)
Reference
Prediction lose win
lose 17.6 44.1
win 29.4 8.8
Accuracy (average) : 0.264
私の問題は、次のとおりです。
私はspark_read_csv
、rsparkling
とas_h2o_frame
を使用してh20
にデータをインポートする方法を参照してください。 しかし、上記2と3のポイントについては、私は完全に失われています。
このアプローチが可能であれば、ヒントを教えてもらえますか、それともh2o
で教えてください。
多くの感謝!
'it_train'変数とは何ですか?私はあなたのコードのステップを逃したと思う(ほとんど再現可能だが、まだ)。 –
ちょっと@ErinLeDellあなたは正しいです。 1秒間保持 –
@ErinLeDell質問が更新されました! –