|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 amoschen 于 2020-4-7 16:50 编辑
今天在练习python的过程遇到一个问题,就是下面的这段代码,在python自带的IDLE中能够正常运行,但是在pycharm中运行就会报错,有没有大神予以解答的?
#-*- coding: utf-8 -*-
#数据规范化
import pandas as pd
datafile = 'E:\学习文件\个人学习资料\Python\书籍\《Python数据分析与挖掘实战》源数据和代码' \
'\Python-2+|+++÷+d-++=-|++\chapter4\demo\data\discretization_data.xls' #参数初始化
data = pd.read_excel(datafile) #读取数据
data = data[u'肝气郁结证型系数'].copy()
k = 4
d1 = pd.cut(data, k, labels = range(k)) #等宽离散化,各个类比依次命名为0,1,2,3
#等频率离散化
w = [1.0*i/k for i in range(k+1)]
w = data.describe(percentiles = w)[4:4+k+1] #使用describe函数自动计算分位数
w[0] = w[0]*(1-1e-10)
d2 = pd.cut(data, w, labels = range(k))
from sklearn.cluster import KMeans #引入KMeans
kmodel = KMeans(n_clusters = k, n_jobs = 4) #建立模型,n_jobs是并行数,一般等于CPU数较好
kmodel.fit(data.values.reshape((len(data), 1))) #训练模型
c = pd.DataFrame(kmodel.cluster_centers_).sort_values(0) #输出聚类中心,并且排序(默认是随机序的)
w = c.rolling(2).mean().iloc[1:] #相邻两项求中点,作为边界点
w = [0] + list(w[0]) + [data.max()] #把首末边界点加上
d3 = pd.cut(data, w, labels = range(k))
def cluster_plot(d, k): #自定义作图函数来显示聚类结果
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False #用来正常显示负号
plt.figure(figsize = (8, 3))
for j in range(0, k):
plt.plot(data[d==j], [j for i in d[d==j]], 'o')
plt.ylim(-0.5, k-0.5)
return plt
cluster_plot(d1, k).show()
cluster_plot(d2, k).show()
cluster_plot(d3, k).show()
以下为pycharm中的报错信息
E:\学习文件\个人学习资料\Python\学习代码\environment\Scripts\python.exe E:/学习文件/个人学习资料/Python/书籍/《Python数据分析与挖掘实战》源数据和代码/Python-2+|+++÷+d-++=-|++/chapter4/demo/code/4-3_data_discretization.py
exception calling callback for <Future at 0xdee9c88 state=finished raised BrokenProcessPool>
joblib.externals.loky.process_executor._RemoteTraceback:
'''
Traceback (most recent call last):
File "D:\python\lib\site-packages\joblib\externals\loky\process_executor.py", line 391, in _process_worker
call_item = call_queue.get(block=True, timeout=timeout)
File "D:\python\lib\multiprocessing\queues.py", line 99, in get
if not self._rlock.acquire(block, timeout):
PermissionError: [WinError 5] 拒绝访问。
'''
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "D:\python\lib\site-packages\joblib\externals\loky\_base.py", line 625, in _invoke_callbacks
callback(self)
File "D:\python\lib\site-packages\joblib\parallel.py", line 340, in __call__
self.parallel.dispatch_next()
File "D:\python\lib\site-packages\joblib\parallel.py", line 769, in dispatch_next
if not self.dispatch_one_batch(self._original_iterator):
File "D:\python\lib\site-packages\joblib\parallel.py", line 835, in dispatch_one_batch
self._dispatch(tasks)
File "D:\python\lib\site-packages\joblib\parallel.py", line 754, in _dispatch
job = self._backend.apply_async(batch, callback=cb)
File "D:\python\lib\site-packages\joblib\_parallel_backends.py", line 551, in apply_async
future = self._workers.submit(SafeFunction(func))
File "D:\python\lib\site-packages\joblib\externals\loky\reusable_executor.py", line 160, in submit
fn, *args, **kwargs)
File "D:\python\lib\site-packages\joblib\externals\loky\process_executor.py", line 1027, in submit
raise self._flags.broken
joblib.externals.loky.process_executor.BrokenProcessPool: A task has failed to un-serialize. Please ensure that the arguments of the function are all picklable.
exception calling callback for <Future at 0xdefaf98 state=finished raised BrokenProcessPool>
joblib.externals.loky.process_executor._RemoteTraceback:
'''
Traceback (most recent call last):
File "D:\python\lib\site-packages\joblib\externals\loky\process_executor.py", line 391, in _process_worker
call_item = call_queue.get(block=True, timeout=timeout)
File "D:\python\lib\multiprocessing\queues.py", line 99, in get
if not self._rlock.acquire(block, timeout):
PermissionError: [WinError 5] 拒绝访问。
'''
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "D:\python\lib\site-packages\joblib\externals\loky\_base.py", line 625, in _invoke_callbacks
callback(self)
File "D:\python\lib\site-packages\joblib\parallel.py", line 340, in __call__
self.parallel.dispatch_next()
File "D:\python\lib\site-packages\joblib\parallel.py", line 769, in dispatch_next
if not self.dispatch_one_batch(self._original_iterator):
File "D:\python\lib\site-packages\joblib\parallel.py", line 835, in dispatch_one_batch
self._dispatch(tasks)
File "D:\python\lib\site-packages\joblib\parallel.py", line 754, in _dispatch
job = self._backend.apply_async(batch, callback=cb)
File "D:\python\lib\site-packages\joblib\_parallel_backends.py", line 551, in apply_async
future = self._workers.submit(SafeFunction(func))
File "D:\python\lib\site-packages\joblib\externals\loky\reusable_executor.py", line 160, in submit
fn, *args, **kwargs)
File "D:\python\lib\site-packages\joblib\externals\loky\process_executor.py", line 1027, in submit
raise self._flags.broken
File "D:\python\lib\site-packages\joblib\externals\loky\_base.py", line 625, in _invoke_callbacks
callback(self)
File "D:\python\lib\site-packages\joblib\parallel.py", line 340, in __call__
self.parallel.dispatch_next()
File "D:\python\lib\site-packages\joblib\parallel.py", line 769, in dispatch_next
if not self.dispatch_one_batch(self._original_iterator):
File "D:\python\lib\site-packages\joblib\parallel.py", line 835, in dispatch_one_batch
self._dispatch(tasks)
File "D:\python\lib\site-packages\joblib\parallel.py", line 754, in _dispatch
job = self._backend.apply_async(batch, callback=cb)
File "D:\python\lib\site-packages\joblib\_parallel_backends.py", line 551, in apply_async
future = self._workers.submit(SafeFunction(func))
File "D:\python\lib\site-packages\joblib\externals\loky\reusable_executor.py", line 160, in submit
fn, *args, **kwargs)
File "D:\python\lib\site-packages\joblib\externals\loky\process_executor.py", line 1027, in submit
raise self._flags.broken
joblib.externals.loky.process_executor.BrokenProcessPool: A task has failed to un-serialize. Please ensure that the arguments of the function are all picklable.
ERROR: The process "6664" not found.
ERROR: The process "8120" not found.
ERROR: The process "7940" not found.
ERROR: The process "6636" not found.
joblib.externals.loky.process_executor._RemoteTraceback:
'''
Traceback (most recent call last):
File "D:\python\lib\site-packages\joblib\externals\loky\process_executor.py", line 391, in _process_worker
call_item = call_queue.get(block=True, timeout=timeout)
File "D:\python\lib\multiprocessing\queues.py", line 99, in get
if not self._rlock.acquire(block, timeout):
PermissionError: [WinError 5] 拒绝访问。
'''
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "E:/学习文件/个人学习资料/Python/书籍/《Python数据分析与挖掘实战》源数据和代码/Python-2+|+++÷+d-++=-|++/chapter4/demo/code/4-3_data_discretization.py", line 21, in <module>
kmodel.fit(data.values.reshape((len(data), 1))) #训练模型
File "D:\python\lib\site-packages\sklearn\cluster\_kmeans.py", line 956, in fit
for seed in seeds)
File "D:\python\lib\site-packages\joblib\parallel.py", line 1017, in __call__
self.retrieve()
File "D:\python\lib\site-packages\joblib\parallel.py", line 909, in retrieve
self._output.extend(job.get(timeout=self.timeout))
File "D:\python\lib\site-packages\joblib\_parallel_backends.py", line 562, in wrap_future_result
return future.result(timeout=timeout)
File "D:\python\lib\concurrent\futures\_base.py", line 432, in result
return self.__get_result()
File "D:\python\lib\concurrent\futures\_base.py", line 384, in __get_result
raise self._exception
File "D:\python\lib\site-packages\joblib\externals\loky\_base.py", line 625, in _invoke_callbacks
callback(self)
File "D:\python\lib\site-packages\joblib\parallel.py", line 340, in __call__
self.parallel.dispatch_next()
File "D:\python\lib\site-packages\joblib\parallel.py", line 769, in dispatch_next
if not self.dispatch_one_batch(self._original_iterator):
File "D:\python\lib\site-packages\joblib\parallel.py", line 835, in dispatch_one_batch
self._dispatch(tasks)
File "D:\python\lib\site-packages\joblib\parallel.py", line 754, in _dispatch
job = self._backend.apply_async(batch, callback=cb)
File "D:\python\lib\site-packages\joblib\_parallel_backends.py", line 551, in apply_async
future = self._workers.submit(SafeFunction(func))
File "D:\python\lib\site-packages\joblib\externals\loky\reusable_executor.py", line 160, in submit
fn, *args, **kwargs)
File "D:\python\lib\site-packages\joblib\externals\loky\process_executor.py", line 1027, in submit
raise self._flags.broken
File "D:\python\lib\site-packages\joblib\externals\loky\_base.py", line 625, in _invoke_callbacks
callback(self)
File "D:\python\lib\site-packages\joblib\parallel.py", line 340, in __call__
self.parallel.dispatch_next()
File "D:\python\lib\site-packages\joblib\parallel.py", line 769, in dispatch_next
if not self.dispatch_one_batch(self._original_iterator):
File "D:\python\lib\site-packages\joblib\parallel.py", line 835, in dispatch_one_batch
self._dispatch(tasks)
File "D:\python\lib\site-packages\joblib\parallel.py", line 754, in _dispatch
job = self._backend.apply_async(batch, callback=cb)
File "D:\python\lib\site-packages\joblib\_parallel_backends.py", line 551, in apply_async
future = self._workers.submit(SafeFunction(func))
File "D:\python\lib\site-packages\joblib\externals\loky\reusable_executor.py", line 160, in submit
fn, *args, **kwargs)
File "D:\python\lib\site-packages\joblib\externals\loky\process_executor.py", line 1027, in submit
raise self._flags.broken
joblib.externals.loky.process_executor.BrokenProcessPool: A task has failed to un-serialize. Please ensure that the arguments of the function are all picklable.
Process finished with exit code 1
|
|