ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## Tf-idf Transformer > Tf-idf是术语频率 - 逆文档频率的缩写,是一种数字统计,旨在反映单词对集合或语料库中的文档的重要程度。 ### 构造函数参数 `$samples`(array) - 适合tf-idf模型的样本 ``` use Phpml\FeatureExtraction\TfIdfTransformer; $samples = [ [1, 2, 4], [0, 2, 1] ]; $transformer = new TfIdfTransformer($samples); ``` ***** ### 转换 要转换文本样本集合,请使用`transform`方法。例: ``` use Phpml\FeatureExtraction\TfIdfTransformer; $samples = [ [0 => 1, 1 => 1, 2 => 2, 3 => 1, 4 => 0, 5 => 0], [0 => 1, 1 => 1, 2 => 0, 3 => 0, 4 => 2, 5 => 3], ]; $transformer = new TfIdfTransformer($samples); $transformer->transform($samples); /* $samples = [ [0 => 0, 1 => 0, 2 => 0.602, 3 => 0.301, 4 => 0, 5 => 0], [0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0.602, 5 => 0.903], ]; */ ```