Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse invert_hash #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions from_mwt_ds/DataScience/vw_executor/artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,17 +216,41 @@ class Model9(Artifact):
def __init__(self, path: Union[str, Path]):
super().__init__(path)

@staticmethod
def parse_invert_hash(s: str, weight: Dict):
def get_ns(s: str) -> str:
split = s.split('^')
return "^".join(split[:-1]), split[-1]

interacted = s.split('*')

if len(interacted) == 1:
weight["ft_type"].append("feature")
weight["ns1"].append(None)
weight["ns2"].append(None)
weight["ns3"].append(None)
elif len(interacted) == 2:
weight["ft_type"].append("quadratic")
weight["ns1"].append(get_ns(interacted[0]))
weight["ns2"].append(get_ns(interacted[1]))
weight["ns3"].append(None)
elif len(interacted) == 3:
weight["ft_type"].append("cubic")
weight["ns1"].append(get_ns(interacted[0]))
weight["ns2"].append(get_ns(interacted[1]))
weight["ns3"].append(get_ns(interacted[2]))

@property
def weights(self) -> pd.DataFrame:
result = {'name': [], 'weight': []}
result = {'name': [], 'weight': [], 'ft_type': [], 'ns1': [], 'ns2': [], 'ns3': []}
for line in reversed(self.raw):
if ':' not in line:
break

parts = line.split(' ')[0].split(':')
result['name'].append(parts[0])
result['weight'].append(_safe_to_float(parts[-1], None))

Model9.parse_invert_hash(parts[0], result)
df = pd.DataFrame(result)
df.set_index('name', inplace=True)
df.sort_index(inplace=True)
Expand Down