You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the below code, I am appending the vehicleType to the prefix to get which column name to use from my input Dataframe. So for example if vehicleType = 'car' then I would return 'features_car' feature value. Data: df = pandas.DataFrame([["car",0.1,0.0],["car",0.2,0.0],["suv",0.0,0.2]],columns=['vehicleType','features_car','features_suv']) Custom Transformer:
classGetScore(BaseEstimator, TransformerMixin): # type: ignore"""Apply binarize transform for matching values to filter_value."""def__init__(self, prefix: str):
"""Initialize transformer with expected columns."""self.prefix=prefixpassdefdot_product(self, x) ->float:
"""Return 1.0 if input == filter_value, else 0."""print("type of x:")
print(type(x))
returnx[self.prefix+x.vehicleType]
deffit(self, X, y=None): # type: ignore"""Fit the transformer."""returnselfdeftransform(self, X: pandas.DataFrame|numpy.ndarray, y: None=None) ->numpy.ndarray:
"""Transform the given data."""iftype(X) ==pandas.DataFrame:
x=X.apply(lambdax: self.dot_product(x), axis=1)
returnx.values.reshape((-1, 1))
# elif type(X) == numpy.ndarray:# vector_func = numpy.vectorize(self.dot_product)# x = vector_func(X)# return x.reshape((-1, 1))defget_feature_names_out(self) ->None:
"""Return feature names. Required for onnx conversion."""pass
To write a custom converter for my GetScore, I would need to be able to access the input by the column name. Is that accessible in the converter inputs? Or would I have to come up with another approach?
The text was updated successfully, but these errors were encountered:
The library was started before scikit-learn implemented this feature and this information is not used right now. We could probably make a code change to improve the mapping between onnx name and scikit-learn name. I'm not sure it is possible to guarantee an exact mapping in particular if scikit-learn allows name to be reused but it is not a very complicated changed. Do you think it should be the exact name, or extended with a prefix or suffix?
In the below code, I am appending the vehicleType to the prefix to get which column name to use from my input Dataframe. So for example if vehicleType = 'car' then I would return 'features_car' feature value.
Data:
df = pandas.DataFrame([["car",0.1,0.0],["car",0.2,0.0],["suv",0.0,0.2]],columns=['vehicleType','features_car','features_suv'])
Custom Transformer:
sklearn pipeline:
To write a custom converter for my GetScore, I would need to be able to access the input by the column name. Is that accessible in the converter inputs? Or would I have to come up with another approach?
The text was updated successfully, but these errors were encountered: