2

こんにちは、私はこの関数を作成するために助けを得ましたが、今は非常に立ち往生しています。

        from scipy.stats import ttest_ind
    def input_file_to_dict(f):
            return dict((key, int(value)) for value, key in map(lambda line:line.split(), f))

    with open("count-pos.txt") as f:
            word_counts1 = input_file_to_dict(f)

    with open("count-neg.txt") as f:
            word_counts2 = input_file_to_dict(f)

list1 と list2 にあるすべての単語を見つける

    out = open('t-test_output.txt', 'w')
    common_words = set.intersection(set(word_counts1.keys()),    set(word_counts2.keys()))
    for line in common_words:

        t,p = ttest_ind([word_counts1[k] for k in common_words], [word_counts2[k] for k in common_words])

        print >> out, (t,p)

ご覧のとおり、単語の頻度を含む 2 つのリストを比較しようとしていますが、一部の単語は両方のサンプル サイズに表示されません。各単語ペアに対して t 検定を実行して、それらの分散を判断したいと考えています。ただし、これにより、同じ t 値と p 値のペアが何度も返されます。

アイデアはありますか?

サンプル ファイルは次のようになります: count-pos.txt

529 the
469 want
464 it
449 de
4

1 に答える 1

0

common_words毎回すべてのカウントを渡すため、この行はループ内で毎回同じ値を計算しています。

t,p = ttest_ind([word_counts1[k] for k in common_words], [word_counts2[k] for k in common_words])

すべてをループする必要がありますcommon_wordsか?

于 2013-06-06T16:39:49.627 に答える