Java端通过SkLearn2PMML-Plugin将客户变压器转换为PMML

时间:2018-11-27 09:40:31

标签: java python data-science pmml

我在github(https://github.com/jpmml/sklearn2pmml-plugin/blob/master/README.md)中知道SkLearn2PMML-Plugin项目。但是我对Java的经验很少。有人可以帮我编写功能转换器的java插件。下面是我的特征转换器。

class FeatureSelector(TransformerMixin):
'''A transformer for extracting certain column(s)'''
def __init__(self, cols):
    self.cols = cols

def fit(self, X, y=None, **fit_params):
    return self

def transform(self, X, **transform_params):
    return X[self.cols]




class ModelTransformer(TransformerMixin):

def __init__(self, model):
    self.model = model

def fit(self, *args, **kwargs):
    self.model.fit(*args, **kwargs)
    return self

def transform(self, X, **transform_params):
    return pd.DataFrame(self.model.predict(X))

1 个答案:

答案 0 :(得分:0)

您可以使用FeatureSelector转换来实现sklearn2pmml.preprocessing.ExpressionTransformer的功能:

selector = ExpressionTransformer("X[0]")

ModelTransformer功能有些棘手,但确实可行。下次,请考虑直接通过SkLearn2PMML项目打开功能请求(而不是要求SO为您编写代码):https://github.com/jpmml/sklearn2pmml/issues/118