我想使用带有sklearn
GridSearchCV
的自定义回归函数。它的精神类似于创建一个自定义分类器-如本博客所示:
http://danielhnyk.cz/creating-your-own-estimator-scikit-learn/
这里是博客中代码的压缩/编辑部分-显示了一些需要重写的方法。在
from sklearn.base import BaseEstimator, RegressorMixin
class MyCustomClassifier(BaseEstimator, RegressorMixin):
"""An example of classifier"""
def __init__(self, intValue=0, stringParam="defaultValue", otherParam=None):
"""
Called when initializing the classifier
"""
self.intValue = intValue
self.stringParam = stringParam
def fit(self, X, y=None):
self.treshold_ = (sum(X)/len(X)) + self.intValue # mean + intValue
return self
def _meaning(self, x):
# returns True/False according to fitted classifier
# notice underscore on the beginning
return( True if x >= self.treshold_ else False )
def predict(self, X, y=None):
..
回归和分类器之间相同的东西很可能是__init__, fit, predict
方法:我可能可以把它们拼凑在一起。但是__meaning
的等价物呢?或者其他不明显/不清晰的微妙考虑?在
下面是我要开始的一个骨架:
^{pr2}$据我所知,GridSearchCv将使用score
方法。。?在
目前没有回答
相关问题 更多 >
编程相关推荐