Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_parameterized_term_default_value(self):
defaults = {'a': 'default for a', 'b': 'default for b'}
class F(Factor):
params = defaults
inputs = (SomeDataSet.foo,)
dtype = 'f8'
window_length = 5
assert_equal(F().params, defaults)
assert_equal(F(a='new a').params, assoc(defaults, 'a', 'new a'))
assert_equal(F(b='new b').params, assoc(defaults, 'b', 'new b'))
assert_equal(
F(a='new a', b='new b').params,
{'a': 'new a', 'b': 'new b'},
)
'node_attr': {'color': 'white',
'fontcolor': '#FFFFFF',
'penwidth': '3'},
'edge_attr': {'color': 'white',
'penwidth': '3'}}
df.value.resample('1w').mean().visualize('resample.svg', **kwargs)
df = dd.demo.make_timeseries('2010-01-01', '2010-08-30',
{'value': float, 'name': str, 'id': int},
freq='10s',
partition_freq='1M',
seed=1)
df.value.rolling(100).mean().visualize('rolling.svg', **assoc(kwargs,
'rankdir', 'LR'))
shap_output = {"shap_values": shap_values,
"shap_expected_value": np.repeat(shap_expected_value, len(shap_values))}
col_dict = merge(col_dict, shap_output)
return new_df.assign(**col_dict)
p.__doc__ = learner_pred_fn_docstring("xgb_regression_learner", shap=True)
log = {'xgb_regression_learner': {
'features': features,
'target': target,
'prediction_column': prediction_column,
'package': "xgboost",
'package_version': xgb.__version__,
'parameters': assoc(params, "num_estimators", num_estimators),
'feature_importance': bst.get_score(),
'training_samples': len(df)},
'object': bst}
return p, p(df), log
def rebatch_metadata_by_experiment(metadata):
normal, normal_rest = prioritize_normals(metadata)
batch = metadata[0]["participant"]
tumor_batch = [tz.assoc(x, "batch", batch) for x in metadata
if x["sample_type"] in PRIORITIZED_TUMOR_CODES.keys()]
normal = [tz.assoc(normal, "batch", batch)] if normal else []
# run each non priority normal as its own tumor sample with no control
normal_rest = [tz.assoc(x, "batch", batch + "-" + x["sample_type"]) for x
in normal_rest]
normal_rest = [tz.assoc(x, "phenotype", "tumor") for x in normal_rest]
all_batches = normal + normal_rest + tumor_batch
return all_batches
def _print_python(expr, leaves=None):
child, scope = print_python(leaves, expr._child)
funcname = next(funcnames)
return ('%s(%s)' % (funcname, child),
toolz.assoc(scope, funcname, expr.func))
prediction_column : str
The name of the column with the predictions from the model.
If a multiclass problem, additional prediction_column_i columns will be added for i in range(0,n_classes).
weight_column : str, optional
The name of the column with scores to weight the data.
encode_extra_cols : bool (default: True)
If True, treats all columns in `df` with name pattern fklearn_feat__col==val` as feature columns.
"""
import xgboost as xgb
params = extra_params if extra_params else {}
params = assoc(params, "eta", learning_rate)
params = params if "objective" in params else assoc(params, "objective", 'binary:logistic')
weights = df[weight_column].values if weight_column else None
features = features if not encode_extra_cols else expand_features_encoded(df, features)
dtrain = xgb.DMatrix(df[features].values, label=df[target].values, feature_names=map(str, features), weight=weights)
bst = xgb.train(params, dtrain, num_estimators)
def p(new_df: pd.DataFrame, apply_shap: bool = False) -> pd.DataFrame:
dtest = xgb.DMatrix(new_df[features].values, feature_names=map(str, features))
pred = bst.predict(dtest)
if params["objective"] == "multi:softprob":
col_dict = {prediction_column + "_" + str(key): value
def _get_subnet_config_w_az(self, network_config):
az_count = int(network_config.get('az_count', 2))
subnet_config = network_config.get('subnet_config', {})
for subnet in subnet_config:
for az in range(az_count):
newsubnet = assoc(subnet, 'AZ', az)
yield newsubnet
def todo_app(state, action):
if action['type'] == ActionTypes.ADD_TODO:
todos = state['todos'] + (action['text'],)
return toolz.assoc(state, 'todos', todos)
elif action['type'] == ActionTypes.COMPLETE_TODO:
todos = state['todos'][:action['index']] + state['todos'][action['index'] + 1:]
return toolz.assoc(state, 'todos', todos)
else:
return state
shap_output = {"shap_values": shap_values,
"shap_expected_value": np.repeat(shap_expected_value, len(shap_values))}
col_dict = merge(col_dict, shap_output)
return new_df.assign(**col_dict)
p.__doc__ = learner_pred_fn_docstring("catboost_classification_learner", shap=True)
log = {'catboost_classification_learner': {
'features': features,
'target': target,
'prediction_column': prediction_column,
'package': "catboost",
'package_version': catboost.__version__,
'parameters': assoc(params, "num_estimators", num_estimators),
'feature_importance': cbr.feature_importances_,
'training_samples': len(df)},
'object': cbr}
return p, p(df), log