keyword-argument

Sklearn pass fit() parameters to xgboost in pipeline

本小妞迷上赌 提交于 2020-12-02 07:29:48
问题 Similar to How to pass a parameter to only one part of a pipeline object in scikit learn? I want to pass parameters to only one part of a pipeline. Usually, it should work fine like: estimator = XGBClassifier() pipeline = Pipeline([ ('clf', estimator) ]) and executed like pipeline.fit(X_train, y_train, clf__early_stopping_rounds=20) but it fails with: /usr/local/lib/python3.5/site-packages/sklearn/pipeline.py in fit(self, X, y, **fit_params) 114 """ 115 Xt, yt, fit_params = self._pre

Sklearn pass fit() parameters to xgboost in pipeline

旧巷老猫 提交于 2020-12-02 07:29:24
问题 Similar to How to pass a parameter to only one part of a pipeline object in scikit learn? I want to pass parameters to only one part of a pipeline. Usually, it should work fine like: estimator = XGBClassifier() pipeline = Pipeline([ ('clf', estimator) ]) and executed like pipeline.fit(X_train, y_train, clf__early_stopping_rounds=20) but it fails with: /usr/local/lib/python3.5/site-packages/sklearn/pipeline.py in fit(self, X, y, **fit_params) 114 """ 115 Xt, yt, fit_params = self._pre

Keyword arguments aliases in python

妖精的绣舞 提交于 2020-07-19 06:17:26
问题 It always seemed odd to me that there are keyword arguments (or arguments) that can be passed to functions or __init__ methods of classes. How do you prevent user who is not familiar to your code from making a mistake? How to get user instantly ( almost instinctively ) familiar to your code without badly written or long winded documentation or to many trials and errors preventing user from quickly and comfortably use your code or module ? In python we are lucky since we have help and dir

How to make “keyword-only” fields with dataclasses?

允我心安 提交于 2020-05-12 11:10:01
问题 Since 3.0 there is support to make an argument keyword only: class S3Obj: def __init__(self, bucket, key, *, storage_class='Standard'): self.bucket = bucket self.key = key self.storage_class = storage_class How to get that kind of signature using dataclasses? Something like this, but preferably without the SyntaxError : @dataclass class S3Obj: bucket: str key: str * storage_class: str = 'Standard' Ideally declarative, but using the __post_init__ hook and/or a replacement class decorator is

How to make “keyword-only” fields with dataclasses?

烈酒焚心 提交于 2020-05-12 11:09:11
问题 Since 3.0 there is support to make an argument keyword only: class S3Obj: def __init__(self, bucket, key, *, storage_class='Standard'): self.bucket = bucket self.key = key self.storage_class = storage_class How to get that kind of signature using dataclasses? Something like this, but preferably without the SyntaxError : @dataclass class S3Obj: bucket: str key: str * storage_class: str = 'Standard' Ideally declarative, but using the __post_init__ hook and/or a replacement class decorator is

Behavior difference between super().__init__() and explicit superclass __init__() in Python

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-23 05:41:06
问题 I am getting an unexplained difference in behavior between using super().__init__() and explicitly calling a super class constructor in my code. class IPElement(object): def __init__(self, ip_type='IPv4'): self.ip_type = ip_type class IPAddressSimple(IPElement): def __init__(self, ip_name, ip_type='IPv4'): self.ip_name = ip_name super().__init__(self, ip_type=ip_type) Here, the line super().__init__(self, ip_type=ip_type) results in a type error: TypeError: __init__() got multiple values for