本文整理匯總了Python中Struct.Struct.exs方法的典型用法代碼示例。如果您正苦於以下問題:Python Struct.exs方法的具體用法?Python Struct.exs怎麽用?Python Struct.exs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Struct.Struct
的用法示例。
在下文中一共展示了Struct.exs方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: cvtest
# 需要導入模塊: from Struct import Struct [as 別名]
# 或者: from Struct.Struct import exs [as 別名]
def cvtest(name, base_sp, nsp, fs, base_featstruct, kfold=2, clf_type='svm',
nfeats=100, norm=True, ppi_output=None, train_limit=None,
save_data=True, balance_train=False, keep_cols=None, clf_factory=None,
clffact_feats=None, **kwargs):
"""
"""
assert kfold>1, "CV K-fold 1 not possible"
exs = ppi.feature_array(base_sp, fs, base_featstruct,
nsp, **kwargs) if ppi_output is None else ppi_output
arrfeats, ntest_pos = fe.arr_copy(exs.arrfeats), exs.ntest_pos
assert len(arrfeats)>0, '0 examples not supported'
if train_limit: print 'Sampling %s train/cv examples' % train_limit
train_limit = train_limit or len(arrfeats)
arrfeats = arrfeats if keep_cols is None else fe.keep_cols(arrfeats, keep_cols)
arrfeats = fe.keep_rows(arrfeats, random.sample(range(len(arrfeats)),
int(train_limit))) # shuffle even if not sampling. don't random.shuffle
ntest_pos = int(ntest_pos * train_limit / len(arrfeats))
if clf_type in clf_factories and clf_factory is None:
clf_factory, clffact_feats = clf_factories[clf_type]
ppis = []
for k in range(kfold):
print 'Fold %s:' % k
ppis_fold,clf,scaler,feats = fold_test(arrfeats, kfold, k, clf_factory,
clffact_feats, nfeats, norm, balance_train)
ppis += ppis_fold
random.shuffle(ppis)
ppis.sort(key=lambda x: x[2], reverse=True)
result = Struct(traincv=arrfeats[['id1','id2','hit']], clf=clf,
scaler=scaler, ppis=ppis, ntest_pos=ntest_pos, name=name,
species=base_sp, ppi_params=str(clf), feats=feats,
source_feats=exs.arrfeats.dtype.names, balance_train=balance_train)
if save_data:
result.exs = exs
return result