1
在Weka中,類StringToWordVector定義了一種稱爲setNormalizeDocLength的方法。它規範了文檔的詞頻。我的問題是:如何正常化Weka文檔的詞頻率
- 「正常化文檔的詞頻」是什麼意思?
- Weka如何做到這一點?
一個實際的例子會幫助我。提前致謝。
在Weka中,類StringToWordVector定義了一種稱爲setNormalizeDocLength的方法。它規範了文檔的詞頻。我的問題是:如何正常化Weka文檔的詞頻率
一個實際的例子會幫助我。提前致謝。
尋找另外WEKA源,這是做歸一化的方法:
private void normalizeInstance(Instance inst, int firstCopy) throws Exception
{
double docLength = 0;
if (m_AvgDocLength < 0)
{
throw new Exception("Average document length not set.");
}
// Compute length of document vector
for(int j=0; j<inst.numValues(); j++)
{
if(inst.index(j)>=firstCopy)
{
docLength += inst.valueSparse(j) * inst.valueSparse(j);
}
}
docLength = Math.sqrt(docLength);
// Normalize document vector
for(int j=0; j<inst.numValues(); j++)
{
if(inst.index(j)>=firstCopy)
{
double val = inst.valueSparse(j) * m_AvgDocLength/docLength;
inst.setValueSparse(j, val);
if (val == 0)
{
System.err.println("setting value "+inst.index(j)+" to zero.");
j--;
}
}
}
}
它看起來像最相關的部分是
double val = inst.valueSparse(j) * m_AvgDocLength/docLength;
inst.setValueSparse(j, val);
所以看起來正常化是value = currentValue * averageDocumentLength/actualDocumentLength
。