Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么Python2.7的性能(轮廓分数)比3.6更好?_Python_Python 3.x_Python 2.7_Cluster Analysis - Fatal编程技术网

为什么Python2.7的性能(轮廓分数)比3.6更好?

为什么Python2.7的性能(轮廓分数)比3.6更好?,python,python-3.x,python-2.7,cluster-analysis,Python,Python 3.x,Python 2.7,Cluster Analysis,我在SoF上读了很多关于Python2.7和3.6之间速度差异的文章。但我的问题更多的是关于两个版本之间的性能 我使用TF-IDF+KMeans和score剪影来评估我的集群的同质性 通过从Python 3.6切换到Python 2.7,我的轮廓分数增加了+0.20 **有人能解释一下吗?**谢谢 代码: tfidf = TfidfVectorizer( stop_words=my_stopwords_str, max_df=0.95, min_df=5,

我在SoF上读了很多关于Python2.7和3.6之间速度差异的文章。但我的问题更多的是关于两个版本之间的性能

我使用TF-IDF+KMeans和score剪影来评估我的集群的同质性

通过从Python 3.6切换到Python 2.7,我的轮廓分数增加了+0.20

**有人能解释一下吗?**谢谢

代码:

tfidf = TfidfVectorizer(
    stop_words=my_stopwords_str, 
    max_df=0.95, 
    min_df=5, 
    token_pattern=r'\w{3,}',
    max_features=20)

tfidf.fit(data_final.all_text)
data_vect = tfidf.transform(data_final.all_text)

num_clusters = 15

kmeans = KMeans(n_clusters=num_clusters, init='k-means++', 
max_iter=300).fit(data_vect_lsa)
kmeans_predict = KMeans(n_clusters=num_clusters, init='k-means++', max_iter=300).fit_predict(data_vect_lsa)


silhouette_score(data_vect, labels = kmeans_predict, metric='euclidean')
Python 2.7的输出为:

0.58234789374593758
Python 3.6的输出为:

0.37524101598378656    

再试一次。一个样本是不够的

K-均值从随机设置开始,可能只找到局部最优值


在多次运行时,经常会看到不同的结果。

如果没有更多的细节(最好包括代码),很难回答这个问题。谢谢你的建议,我编辑了我的帖子!
TFIDFvectorier
KMeans
来自哪个库?一般来说,需要寻找的可能是除法——除法运算符的行为在Python3中整数从floor改为true除法,如果代码中有一个隐藏的除法,其中包含两个整数,这可能解释了数值离散性,这个问题取决于您使用的库。什么版本?另一件事,尝试显式使用随机种子。特别是,不同版本的随机种子可能不同。好吧,现在种子根本不是固定的,所以每次运行都可能不同。当然,版本差异也会改变生成的随机值。