MCPcopy Create free account
hub / github.com/Tencent/embedx / statistics

Method statistics

demo/data/scripts/embedx_graph.py:140–172  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

138 yield EmbedxNode(json_node)
139
140 def statistics(self):
141 stats = [("Total edge number", self.context.total_edge_num())]
142 total_node_num, train_node_num, test_node_num = 0, 0, 0
143 max_label, num_label = 0, 0
144 total_feature_num, total_valid_feature_num = 0, 0
145 for node in self.next_node():
146 total_node_num += 1
147 if node.stage == "train":
148 train_node_num += 1
149 if node.stage == "test":
150 test_node_num += 1
151
152 if isinstance(node.label, int):
153 max_label = max(max_label, node.label)
154 num_label = max(max_label, node.label) + 1
155 else:
156 max_label = len(node.label) - 1
157 num_label = len(node.label)
158 if self.has_feature:
159 total_feature_num += len(node.feature)
160 total_valid_feature_num += len(node.valid_feature)
161 stats.append(("Total node number", total_node_num))
162 stats.append(("Total train node number", train_node_num))
163 stats.append(("Total test node number", test_node_num))
164 stats.append(("Total feature number", total_feature_num))
165 stats.append(("Total valid feature number", total_valid_feature_num))
166 if total_feature_num > 0:
167 ratio = 100.0 * (float(total_valid_feature_num) / total_feature_num)
168 stats.append(("Valid feature ratio", ratio))
169 stats.append(("Max label", max_label))
170 stats.append(("Label number", num_label))
171
172 return stats
173
174 def write_context(self, context_path):
175 with open(context_path, 'w', encoding='utf-8') as fout:

Callers 1

Calls 2

next_nodeMethod · 0.95
total_edge_numMethod · 0.80

Tested by

no test coverage detected