当前位置: 首页>>代码示例>>Python>>正文


Python Parallel.sort_index方法代码示例

本文整理汇总了Python中joblib.Parallel.sort_index方法的典型用法代码示例。如果您正苦于以下问题:Python Parallel.sort_index方法的具体用法?Python Parallel.sort_index怎么用?Python Parallel.sort_index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在joblib.Parallel的用法示例。


在下文中一共展示了Parallel.sort_index方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: list

# 需要导入模块: from joblib import Parallel [as 别名]
# 或者: from joblib.Parallel import sort_index [as 别名]
    filled['cc_{}'.format(sex)] = filled['ccpublic_{}'.format(sex)] + filled['ccprivate_{}'.format(sex)]
    filled['crime_{}'.format(sex)] = filled['crimepublic_{}'.format(sex)] + filled['crimeprivate_{}'.format(sex)]
    filled['health_{}'.format(sex)] = filled['health_private_{}'.format(sex)] + filled['health_public_{}'.format(sex)] 
    filled['transfer_{}'.format(sex)] = filled['inc_trans_pub_{}'.format(sex)] + filled['diclaim_{}'.format(sex)] + filled['ssclaim_{}'.format(sex)] + filled['ssiclaim_{}'.format(sex)]

components = ['inc_labor', 'inc_parent', 'transfer', 'edu', 'crime', 'costs', 'cc', 'health', 'qaly', 'm_ed']
factors = np.arange(0,3.1,0.25)
combo = list(itertools.product(components, factors))

# vary factor: IRR
# applying factor to benefits        

def irr_factors(part, f):
    irr_tmp = deepcopy(filled)
    for sex in ['m', 'f', 'p']:
        irr_tmp['{}_{}'.format(part, sex)] = irr_tmp['{}_{}'.format(part, sex)] * f

    output = irr_calc(irr_tmp, etype=etype, components=components)        

    output['rate'] = f
    output['part'] = part
    
    print 'IRR for {} and factor {} calculated.'.format(part, f)
    return output

irr_factors = Parallel(n_jobs=25)(
	delayed(irr_factors)(part, f) for part, f in combo)
irr_factors = pd.concat(irr_factors, axis=0)
irr_factors.sort_index(inplace=True)
irr_factors.to_csv(os.path.join(plots, 'irr_factors.csv'), index=True)
开发者ID:jorgelgarcia,项目名称:abc-treatmenteffects-finalseason,代码行数:32,代码来源:sa_irrfactor.py

示例2: makeflows

# 需要导入模块: from joblib import Parallel [as 别名]
# 或者: from joblib.Parallel import sort_index [as 别名]
etype = 2
filled = makeflows(etype=etype)

# vary DWL: IRR
irr_dwl = pd.DataFrame([])
def irr_dwl(d):
    irr_tmp = deepcopy(filled)
    for sex in ['m', 'f', 'p']:
        for part in ['inc_trans_pub_{}'.format(sex), 'diclaim_{}'.format(sex), 'ssclaim_{}'.format(sex), 'ssiclaim_{}'.format(sex)]:
            irr_tmp[part] = irr_tmp[part] * (d/0.5)
        for part in ['edu_{}'.format(sex), 'm_ed_{}'.format(sex)]:
            irr_tmp[part].loc[(sex, slice(None), slice(None)), slice('c0','c18')] = \
                irr_tmp[part].loc[(sex, slice(None), slice(None)), slice('c0','c18')] * ((1 + d)/1.5)
        for part in ['ccpublic_{}'.format(sex), 'crimepublic_{}'.format(sex), 'health_public_{}'.format(sex), 'costs_{}'.format(sex)]:
            irr_tmp[part]  = irr_tmp[part] * ((1+d)/1.5)

    output = irr_calc(irr_tmp, etype=etype)
    
    output['rate'] = d
            
    print 'IRR for MCW {} calculated.'.format(d)
    
    return output

irr_dwl = Parallel(n_jobs=25)(
	delayed(irr_dwl)(d) for d in rate_range)
irr_dwl = pd.concat(irr_dwl, axis=0)
irr_dwl.sort_index(inplace=True)
irr_dwl.to_csv(os.path.join(plots, 'irr_dwl.csv'), index=True)

开发者ID:jorgelgarcia,项目名称:abc-treatmenteffects-finalseason,代码行数:31,代码来源:sa_irrdwl.py

示例3: list

# 需要导入模块: from joblib import Parallel [as 别名]
# 或者: from joblib.Parallel import sort_index [as 别名]
    filled['health_{}'.format(sex)] = filled['health_private_{}'.format(sex)] + filled['health_public_{}'.format(sex)] 
    filled['transfer_{}'.format(sex)] = filled['inc_trans_pub_{}'.format(sex)] + filled['diclaim_{}'.format(sex)] + filled['ssclaim_{}'.format(sex)] + filled['ssiclaim_{}'.format(sex)]

components = ['inc_labor', 'inc_parent', 'transfer', 'edu', 'crime', 'costs', 'cc', 'health', 'qaly']
factors = np.arange(0,3.1,0.25)

combo = list(itertools.product(components, factors))
    
# vary factor: BCR
# applying factor to benefits        

def bc_factors(part, f):    
    bc_tmp = deepcopy(filled)
    for sex in ['m', 'f', 'p']:
        bc_tmp['{}_{}'.format(part, sex)] = bc_tmp['{}_{}'.format(part, sex)] * f

    output = bc_calc(bc_tmp, components=components)        

    output['rate'] = f
    output['part'] = part

    print 'B/C Ratio for {} and factor {} calculated.'.format(part, f)
    return output



bc_factors = Parallel(n_jobs=25)(
	delayed(bc_factors)(part, f) for part, f in combo)
bc_factors = pd.concat(bc_factors, axis=0)
bc_factors.sort_index(inplace=True)
bc_factors.to_csv(os.path.join(plots, 'bc_factors.csv'), index=True)
开发者ID:jorgelgarcia,项目名称:abc-treatmenteffects-finalseason,代码行数:33,代码来源:sa_bcrfactor.py

示例4: Parallel

# 需要导入模块: from joblib import Parallel [as 别名]
# 或者: from joblib.Parallel import sort_index [as 别名]
	
	output_aic = pd.DataFrame(output_aic, index = pd.Index(cols, name = 'model'), columns = pd.MultiIndex.from_tuples([('aic', yvar)], names = ['stat', 'var'])).T
	output_bic = pd.DataFrame(output_bic, index = pd.Index(cols, name = 'model'), columns = pd.MultiIndex.from_tuples([('bic', yvar)], names = ['stat', 'var'])).T
	
	output = pd.concat([output_aic, output_bic], axis = 0)    
	
	return output

best_aic = {}
best_bic = {}
	
for spec in ['abccare', 'abc', 'care']:
	selection = Parallel(n_jobs=1)(
		delayed(model_select)(data, yvar, bank, spec) for yvar in outcomes.index) 
	selection = pd.concat(selection, axis=0)
	selection.sort_index(inplace=True)

	# estimate rankings by AIC and BIC
	selection = selection.rank(axis=1).groupby(level=0).sum()
	best = selection.idxmin(axis = 1)
	model_list = list(itertools.chain.from_iterable([itertools.combinations(bank, 3)]))
	best_aic["{}".format(spec)] = model_list[selection.idxmin(axis = 1)[0]]
	best_bic["{}".format(spec)] = model_list[selection.idxmin(axis = 1)[1]]

	print 'Best AIC:', ('R', 'male', 'abc') + best_aic['{}'.format(spec)]
	print 'Best BIC:', ('R', 'male', 'abc') + best_bic['{}'.format(spec)]

record = open('best_controls.txt', 'wb')
        
record.write('ABCCARE Best AIC: {} \n\n'.format(' '.join(('R', 'male', 'abc') + best_aic['abccare'])))
record.write('ABCCARE Best BIC: {}'.format(' '.join(('R', 'male', 'abc') + best_bic['abccare'])))
开发者ID:jorgelgarcia,项目名称:abc-treatmenteffects-finalseason,代码行数:33,代码来源:controls_selection.py


注:本文中的joblib.Parallel.sort_index方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。