graph-construct/construct-graph.ipynb: update
This commit is contained in:
parent
84bcefc417
commit
6ca1195ec5
1 changed files with 7 additions and 7 deletions
|
|
@ -30,7 +30,7 @@
|
|||
"case = '...'\n",
|
||||
"casegraphs = '...'\n",
|
||||
"\n",
|
||||
"df_data = pd.read_csv(f'../datasets/{case}.csv')\n",
|
||||
"df_data = pd.read_csv(f'../sentiment-analysis/{case}.csv')\n",
|
||||
"user_nodes = df_data.groupby('user')['id'].apply(list).to_dict()\n",
|
||||
"\n",
|
||||
"df_data.info()"
|
||||
|
|
@ -62,7 +62,7 @@
|
|||
" G.add_edge(row['id'], row['parentid'])\n",
|
||||
"\n",
|
||||
"# Export nearest-neighbour graph\n",
|
||||
"nx.write_graphml(G, f'../datasets/{casegraphs}-nn-graph.graphml')\n",
|
||||
"nx.write_graphml(G, f'{casegraphs}-nn-graph.graphml')\n",
|
||||
"\n",
|
||||
"# Define nearest-neighbour interaction count dictionary\n",
|
||||
"nn_count = {}\n",
|
||||
|
|
@ -98,7 +98,7 @@
|
|||
"tc_G = nx.transitive_closure(G)\n",
|
||||
"\n",
|
||||
"# Export transitive-closure graph\n",
|
||||
"nx.write_graphml(tc_G, f'../datasets/{casegraphs}-tc-graph.graphml')\n",
|
||||
"nx.write_graphml(tc_G, f'{casegraphs}-tc-graph.graphml')\n",
|
||||
"\n",
|
||||
"# Define transitive-closure interaction count dictionary\n",
|
||||
"tc_count = {}\n",
|
||||
|
|
@ -139,19 +139,19 @@
|
|||
" if row['parentid'] != 'no_parent':\n",
|
||||
" dG.add_edge(row['id'], row['parentid'])\n",
|
||||
"\n",
|
||||
"nx.write_graphml(dG, f'../datasets/{casegraphs}-nn-dgraph.graphml')\n",
|
||||
"nx.write_graphml(dG, f'{casegraphs}-nn-dgraph.graphml')\n",
|
||||
"\n",
|
||||
"# Construct directed-transitive-closure directed graph\n",
|
||||
"dtc_dG = nx.transitive_closure(dG)\n",
|
||||
"\n",
|
||||
"# Export directed-transitive-closure directed graph\n",
|
||||
"nx.write_graphml(dtc_dG, f'../datasets/{casegraphs}-dtc-dgraph.graphml')\n",
|
||||
"nx.write_graphml(dtc_dG, f'{casegraphs}-dtc-dgraph.graphml')\n",
|
||||
"\n",
|
||||
"# Convert to directed-transitive-closure undirected graph\n",
|
||||
"dtc_G = dtc_dG.to_undirected()\n",
|
||||
"\n",
|
||||
"# Export directed-transitive-closure graph\n",
|
||||
"nx.write_graphml(dtc_G, f'../datasets/{casegraphs}-dtc-graph.graphml')\n",
|
||||
"nx.write_graphml(dtc_G, f'{casegraphs}-dtc-graph.graphml')\n",
|
||||
"\n",
|
||||
"# Define directed-transitive-closure interaction count dictionary\n",
|
||||
"dtc_count = {}\n",
|
||||
|
|
@ -196,7 +196,7 @@
|
|||
" 'post-count': pd.Series(user_c)\n",
|
||||
"})\n",
|
||||
"\n",
|
||||
"export_dataset = f'../datasets/{case}-users.csv'\n",
|
||||
"export_dataset = f'{case}-users.csv'\n",
|
||||
"df_users.to_csv(export_dataset, index=False)\n",
|
||||
"\n",
|
||||
"df_users.info()"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue