Skip to content

Commit

Permalink
add feature names
Browse files Browse the repository at this point in the history
Signed-off-by: weiwee <wbwmat@gmail.com>
  • Loading branch information
sagewe committed Jul 21, 2023
1 parent e364e82 commit 5df07ce
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 4 additions & 2 deletions python/fate/arch/dataframe/ops/_histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@
import functools

from fate.arch.tensor.inside import Hist
from ._compress_block import compress_blocks

from .._dataframe import DataFrame
from ..manager import BlockType, DataManager
from ._compress_block import compress_blocks


def hist(df: DataFrame, targets):
data_manager = df.data_manager
column_names = data_manager.infer_operable_field_names()

block_table, data_manager = _try_to_compress_table(df.block_table, data_manager)
block_id = data_manager.infer_operable_blocks()[0]

def _mapper(blocks, target, bid: int = None):
histogram = Hist()
histogram = Hist(column_names)
histogram.update(blocks[bid], target)

return histogram
Expand Down
8 changes: 6 additions & 2 deletions python/fate/arch/tensor/inside/_op_hist.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@


class Hist:
def __init__(self):
def __init__(self, feature_names):
self.feature_names = feature_names
self.data: typing.Dict[int, typing.Dict[int, typing.Any]] = {}

def update(self, features, labels):
Expand Down Expand Up @@ -38,7 +39,7 @@ def cumsum(self):
return self

def __sub__(self, other: "Hist"):
out = Hist()
out = Hist(self.feature_names)
for j in self.data:
out.data[j] = {}
for v in self.data[j]:
Expand All @@ -48,6 +49,9 @@ def __sub__(self, other: "Hist"):
out.data[j][v] = self.data[j][v] - other.data[j][v]
return out

def to_dict(self):
return {name: self.data[i] for i, name in enumerate(self.feature_names)}


if __name__ == "__main__":
import numpy as np
Expand Down

0 comments on commit 5df07ce

Please sign in to comment.