gpt4 book ai didi

python - 导入错误: cannot import name '_UnstableArchMixin' from 'sklearn.base'

转载 作者:太空宇宙 更新时间:2023-11-03 21:05:19 25 4
gpt4 key购买 nike

我的环境是anaconda3(python 3.7)。

我使用此代码来测试sklearn.cluster:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import matplotlib.pyplot as plt
from sklearn.cluster import KMeans
from sklearn import metrics
from sklearn.datasets.samples_generator import make_blobs
plt.figure()
X, y = make_blobs(n_samples=1000, n_features=2, centers=[[-1,-1], [0,0], [1,1], [2,2]], cluster_std=[0.4, 0.2, 0.2, 0.2], random_state =9) #生成测试数据
for index,k in enumerate((2,3,4,5)):
plt.subplot(2,2,index+1)
y_pred = KMeans(n_clusters=k, random_state=9).fit_predict(X)
score=metrics.calinski_harabaz_score(X, y_pred)
plt.scatter(X[:, 0], X[:, 1], c=y_pred,s=10,edgecolor='k')
plt.text(.99, .01, ('k=%d, score: %.2f' % (k,score)),transform=plt.gca().transAxes, size=10,horizontalalignment='right')
plt.show()

但是当我在pycharm中运行这段代码时,错误消息是:

Traceback (most recent call last):
File "E:/test/test1.py", line 5, in <module>
from sklearn.cluster import KMeans
File "E:\Anaconda37\lib\site-packages\sklearn\cluster\__init__.py", line 6, in <module>
from .spectral import spectral_clustering, SpectralClustering
File "E:\Anaconda37\lib\site-packages\sklearn\cluster\spectral.py", line 17, in <module>
from ..manifold import spectral_embedding
File "E:\Anaconda37\lib\site-packages\sklearn\manifold\__init__.py", line 5, in <module>
from .locally_linear import locally_linear_embedding, LocallyLinearEmbedding
File "E:\Anaconda37\lib\site-packages\sklearn\manifold\locally_linear.py", line 12, in <module>
from ..base import BaseEstimator, TransformerMixin, _UnstableArchMixin
ImportError: cannot import name '_UnstableArchMixin' from 'sklearn.base' (E:\Anaconda37\lib\site-packages\sklearn\base.py)

如何修复它?

最佳答案

我修改了这个文件E:\Anaconda37\Lib\site-packages\sklearn\manifold\locally_linear.py

from ..base import BaseEstimator, TransformerMixin, _UnstableArchMixi

更改为:

from ..base import BaseEstimator, TransformerMixin

class LocallyLinearEmbedding(BaseEstimator, TransformerMixin,_UnstableArchMixin):

更改为

class LocallyLinearEmbedding(BaseEstimator, TransformerMixin):

然后错误消失了。我在python3.6中检查了这个文件,文件中没有_UnstableArchMixin

关于python - 导入错误: cannot import name '_UnstableArchMixin' from 'sklearn.base' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55447538/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com