Traceback (most recent call last): File "D:\anaconda\lib\site-packages\sklearn\utils\validation.py", line 879, in check_array array = _asarray_with_order(array, order=order, dtype=dtype, xp=xp) File "D:\anaconda\lib\site-packages\sklearn\utils\_array_api.py", line 185, in _asarray_with_order array = numpy.asarray(array, order=order, dtype=dtype) numpy.ComplexWarning: Casting complex values to real discards the imaginary part The above exception was the direct cause of the following exception: Traceback (most recent call last): File "C:\Users\86157\PycharmProjects\pythonProject8\6.py", line 54, in <module> clustering = SpectralClustering(n_clusters=n_clusters, assign_labels="discretize", random_state=0).fit(Y) File "D:\anaconda\lib\site-packages\sklearn\cluster\_spectral.py", line 706, in fit X = self._validate_data( File "D:\anaconda\lib\site-packages\sklearn\base.py", line 546, in _validate_data X = check_array(X, input_name="X", **check_params) File "D:\anaconda\lib\site-packages\sklearn\utils\validation.py", line 881, in check_array raise ValueError( ValueError: Complex data not supported [[-0.00667798+0.j -0.00050094+0.j] [-0.00679108+0.j 0.00760181+0.j] [-0.0068003 +0.j -0.00274455+0.j] ... [-0.00512369+0.j 0.02043165+0.j] [-0.01293088+0.j -0.00562299+0.j] [ 0.03972433+0.j -0.01824531+0.j]]
时间: 2023-09-28 19:04:05 浏览: 180
Mac下anaconda中Spyder打开报错Traceback(most recent call last)…问题
5星 · 资源好评率100%
这段代码出现了一个值错误(ValueError)异常,原因是输入的数据包含了复数(complex)类型的值,但是SpectralClustering类不支持处理复数类型的数据。具体地说,异常的堆栈跟踪显示,在调用sklearn.utils.validation.check_array()函数时,检测到输入数组包含了复数类型的值,因此抛出一个异常。这个异常被直接捕获,并且抛出了一个新的值错误异常,指示输入数据不支持复数类型。如果要使用SpectralClustering类对这个数据进行聚类,需要先将复数类型的值转换为实数类型的值。
阅读全文