Python 从同一程序中获得不同精度的原因是什么?

Python 从同一程序中获得不同精度的原因是什么?,python,machine-learning,scikit-learn,logistic-regression,Python,Machine Learning,Scikit Learn,Logistic Regression,我试着计算我的标签的准确度。但是,尽管我使用相同的培训和发展数据,但在运行程序时,我总是获得不同的准确性。这一结果背后的原因是什么?提前谢谢 with open('train.txt') as f: training_sentences = list(splitter(f)) with open('develop.txt') as f: test_sentences = list(splitter(f)) . . . SOME FEATURES AS A LIST OF DICTS . .

我试着计算我的标签的准确度。但是,尽管我使用相同的培训和发展数据,但在运行程序时,我总是获得不同的准确性。这一结果背后的原因是什么?提前谢谢

with open('train.txt') as f:
training_sentences = list(splitter(f))

with open('develop.txt') as f:
test_sentences = list(splitter(f))

.
.
.
SOME FEATURES AS A LIST OF DICTS
.
.
.

def transform_to_dataset(training_sentences):
    X, y = [], []
    for tagged in training_sentences:
        for index in range(len(tagged)):
            X.append(features(untag(tagged), index))
            y.append(tagged[index][1])
    return X, y

X, y = transform_to_dataset(training_sentences)


clf = Pipeline([
    ('vectorizer', DictVectorizer(sparse=False)),
    ('classifier', DecisionTreeClassifier(criterion='entropy'))
])

clf.fit(X, y)  

X_test, y_test = transform_to_dataset(test_sentences)

print "Accuracy:", clf.score(X_test, y_test)

sklearn
DecisionTreeClassifier
使用随机数生成器来确定其属性。如果要保证每次运行的结果相同,请将分类器的参数设置为固定值

将随机种子设置为固定值?我是否使用随机种子?是的,您可能是:per这种算法不能保证返回全局最优的决策树。这可以通过在集成学习器中训练多棵树来缓解,其中特征和样本是随机抽样的,并进行替换。“哦,谢谢,我忘了将DecisionTreeClassifier更改为LogisticRegression()。