python - 使用 joblib 共享 pandas 数据框以进行不同的分类过程
问题描述
我正在使用引用此链接joblib.memory
的缓存数据框。因此,其他进程可以使用相同的 shared 。我必须训练多个分类器,对于所有分类器都是通用的,但对于每个分类器来说都是不同的。我的想法是与所有分类过程共享,这样就不需要为每个分类加载到内存中。dataframe
dfX
dfy
dataframe dfX
dfX
def costly_compute():
df_v = pd.read_parquet(file, columns=var, engine="fastparquet")
return df_v
location = './cachedir'
memory = Memory(location, verbose=0)
costly_compute_cached = memory.cache(costly_compute)
def data_processing_using_cache(col):
start = time.time()
dfX = costly_compute_cached()
stop= time.time()
print("reading dfx",stop-start)
dfy = pd.read_parquet(file, columns=[col])
##Training with (dfX,dfy) and generate accuracy for col
return accuracy
start = time.time()
results = data_processing_using_cache(y0)
stop = time.time()
print('\nFirst round - caching the data')
print('Elapsed time for the entire processing: {:.2f} s'
.format(stop - start))
start = time.time()
results = data_processing_using_cache(y0)
stop = time.time()
print('\Second round - serial- using caching data')
print('Elapsed time for the entire processing: {:.2f} s'
.format(stop - start))
start = time.time()
results = Parallel(n_jobs=2)(
delayed(data_processing_mean_using_cache)(col)
for col in all_y_cols)
stop = time.time()
print('\Third round - parallel- using caching data')
所有三个回合都需要相似的时间。这是否意味着第二轮和第三轮没有使用缓存数据帧?
解决方案
推荐阅读
- sql - 仅使用 sql 在 ORACLE db 中的单元格内容中搜索
- scrapy - ScrapyD 中是否有管道概念?
- javascript - 滚动时使div淡入淡出
- java - 如何通过交易调用以太坊智能合约方法?
- cassandra - 几个小时前创建的提交日志可以应用于 cassandra 集群吗?
- dart - 有没有办法将高度设置为抽屉页眉?
- node.js - 如何检测脚本正在使用 npm 或 yarn 运行?
- c# - NSInvalidArgumentException 原因:-[NSISLinearExpression _referenceView] 在 IOS 10.3.1 或更低版本上
- c - 从nodemcu lua中的lua函数返回大字符串
- python - 从元组列表转换后,python字典中的排序顺序丢失