graph-inspect/*: add
This commit is contained in:
parent
b98904e9e5
commit
3c7e3fc018
3 changed files with 1431 additions and 0 deletions
335
graph-inspect/inspect-graph-user.ipynb
Normal file
335
graph-inspect/inspect-graph-user.ipynb
Normal file
|
|
@ -0,0 +1,335 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Inspect user interactions\n",
|
||||
"\n",
|
||||
"Inspecting the user interactions obtained from the NN, DTC and TC graphs."
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Import the dataset."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import pandas as pd\n",
|
||||
"\n",
|
||||
"casename = '...'\n",
|
||||
"case = '...'\n",
|
||||
"\n",
|
||||
"df_data = pd.read_csv(f'../datasets/{case}-closed-s-users.csv')\n",
|
||||
"\n",
|
||||
"df_data.describe()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Plot the distributions."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"import seaborn as sns\n",
|
||||
"\n",
|
||||
"plt.figure(figsize=(15, 10))\n",
|
||||
"\n",
|
||||
"plt.subplot(2,3,1)\n",
|
||||
"sns.histplot(df_data['nn-count'], bins=20)\n",
|
||||
"plt.yscale('log')\n",
|
||||
"plt.title('Distribution of NN interactions')\n",
|
||||
"plt.xlabel('NN interactions')\n",
|
||||
"plt.ylabel('Count')\n",
|
||||
"plt.grid()\n",
|
||||
"plt.tick_params(axis='both', direction='in',top=True, right=True)\n",
|
||||
"\n",
|
||||
"plt.subplot(2,3,2)\n",
|
||||
"sns.histplot(df_data['dtc-count'], bins=20)\n",
|
||||
"plt.yscale('log')\n",
|
||||
"plt.title('Distribution of DTC interactions')\n",
|
||||
"plt.xlabel('DTC interactions')\n",
|
||||
"plt.ylabel('Count')\n",
|
||||
"plt.grid()\n",
|
||||
"plt.tick_params(axis='both', direction='in',top=True, right=True)\n",
|
||||
"\n",
|
||||
"plt.subplot(2,3,3)\n",
|
||||
"sns.histplot(df_data['tc-count'], bins=20)\n",
|
||||
"plt.yscale('log')\n",
|
||||
"plt.title('Distribution of TC interactions')\n",
|
||||
"plt.xlabel('TC interactions')\n",
|
||||
"plt.ylabel('Count')\n",
|
||||
"plt.grid()\n",
|
||||
"plt.tick_params(axis='both', direction='in',top=True, right=True)\n",
|
||||
"\n",
|
||||
"plt.subplot(2,3,4)\n",
|
||||
"sns.histplot(df_data['post-count'], bins=20)\n",
|
||||
"plt.yscale('log')\n",
|
||||
"plt.title('Distribution of posts')\n",
|
||||
"plt.xlabel('Number of posts')\n",
|
||||
"plt.ylabel('Count')\n",
|
||||
"plt.grid()\n",
|
||||
"plt.tick_params(axis='both', direction='in',top=True, right=True)\n",
|
||||
"\n",
|
||||
"plt.subplot(2,3,5)\n",
|
||||
"sns.histplot(df_data['mean-sentiment'], bins=20, kde=True)\n",
|
||||
"plt.title('Distribution of mean sentiment')\n",
|
||||
"plt.xlabel('Mean sentiment')\n",
|
||||
"plt.ylabel('Count')\n",
|
||||
"plt.grid()\n",
|
||||
"plt.tick_params(axis='both', direction='in',top=True, right=True)\n",
|
||||
"\n",
|
||||
"plt.subplot(2,3,6)\n",
|
||||
"sns.histplot(df_data['std-sentiment'], bins=20, kde=True)\n",
|
||||
"plt.title('Distribution of SD sentiment')\n",
|
||||
"plt.xlabel('SD sentiment')\n",
|
||||
"plt.ylabel('Count')\n",
|
||||
"plt.grid()\n",
|
||||
"plt.tick_params(axis='both', direction='in',top=True, right=True)\n",
|
||||
"\n",
|
||||
"plt.suptitle(f'Distribution of user metrics {casename} case', fontsize=16)\n",
|
||||
"plt.tight_layout(rect=[0, 0, 1, 0.99])\n",
|
||||
"\n",
|
||||
"plt.savefig(f'../datasets/{case}-user-metrics.png')\n",
|
||||
"plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Plot interaction count against mean sentiment, SD sentiment and post count."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import pandas as pd\n",
|
||||
"import seaborn as sns\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"\n",
|
||||
"# Define the pairs of variables for the subplots\n",
|
||||
"variables = [\n",
|
||||
" (\"nn-count\", \"mean-sentiment\"),\n",
|
||||
" (\"dtc-count\", \"mean-sentiment\"),\n",
|
||||
" (\"tc-count\", \"mean-sentiment\"),\n",
|
||||
" (\"nn-count\", \"std-sentiment\"),\n",
|
||||
" (\"dtc-count\", \"std-sentiment\"),\n",
|
||||
" (\"tc-count\", \"std-sentiment\"),\n",
|
||||
" (\"nn-count\", \"post-count\"),\n",
|
||||
" (\"dtc-count\", \"post-count\"),\n",
|
||||
" (\"tc-count\", \"post-count\"),\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"# Create the figure\n",
|
||||
"plt.figure(figsize=(15, 15))\n",
|
||||
"\n",
|
||||
"# Loop through the variables and create subplots\n",
|
||||
"for i, (x_var, y_var) in enumerate(variables):\n",
|
||||
" plt.subplot(3, 3, i + 1)\n",
|
||||
" \n",
|
||||
" # Drop NaN values for the current pair of variables\n",
|
||||
" df_nonan = df_data.dropna(subset=[x_var, y_var])\n",
|
||||
" \n",
|
||||
" # Create scatter plot\n",
|
||||
" sns.scatterplot(x=x_var, y=y_var, data=df_nonan, alpha=0.4, color=\"black\", edgecolor=None)\n",
|
||||
" \n",
|
||||
" # Create Lowess regression plot\n",
|
||||
" sns.regplot(x=x_var, y=y_var, data=df_nonan, scatter=False, lowess=True, line_kws={'color': 'blue', 'linewidth': 2}, label=\"Lowess fit\")\n",
|
||||
" \n",
|
||||
" # Set logarithmic scale for x-axis\n",
|
||||
" plt.xscale(\"log\")\n",
|
||||
" \n",
|
||||
" # Set labels and grid\n",
|
||||
" plt.xlabel(x_var.replace('-', ' '))\n",
|
||||
" plt.ylabel(y_var.replace('-', ' '))\n",
|
||||
" plt.grid()\n",
|
||||
" plt.legend()\n",
|
||||
" plt.tick_params(axis='both', direction='in', top=True, right=True)\n",
|
||||
"\n",
|
||||
"# Set the overall title and layout\n",
|
||||
"plt.suptitle(f'Scatter plot of user metrics against interaction count {casename} case', fontsize=16)\n",
|
||||
"plt.tight_layout(rect=[0, 0, 1, 0.99])\n",
|
||||
"\n",
|
||||
"# Save the figure\n",
|
||||
"plt.savefig(f'../datasets/{case}-user-interaction-scatter.png')\n",
|
||||
"plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Plot (simplified) interaction count against mean sentiment, SD sentiment and post count. "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import pandas as pd\n",
|
||||
"import seaborn as sns\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"from scipy import stats\n",
|
||||
"\n",
|
||||
"# Assuming df_data is your DataFrame and casename and case are defined\n",
|
||||
"plt.figure(figsize=(15, 15))\n",
|
||||
"\n",
|
||||
"# Define the pairs of variables for the subplots\n",
|
||||
"variables = [\n",
|
||||
" (\"nn-count\", \"mean-sentiment\"),\n",
|
||||
" (\"dtc-count\", \"mean-sentiment\"),\n",
|
||||
" (\"tc-count\", \"mean-sentiment\"),\n",
|
||||
" (\"nn-count\", \"std-sentiment\"),\n",
|
||||
" (\"dtc-count\", \"std-sentiment\"),\n",
|
||||
" (\"tc-count\", \"std-sentiment\"),\n",
|
||||
" (\"nn-count\", \"post-count\"),\n",
|
||||
" (\"dtc-count\", \"post-count\"),\n",
|
||||
" (\"tc-count\", \"post-count\"),\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"# Loop through the variables and create subplots\n",
|
||||
"for i, (x_var, y_var) in enumerate(variables):\n",
|
||||
" plt.subplot(3, 3, i + 1)\n",
|
||||
" \n",
|
||||
" # Drop NaN values for the current pair of variables\n",
|
||||
" df_nonan = df_data.dropna(subset=[x_var, y_var])\n",
|
||||
" \n",
|
||||
" # Create the regression plot\n",
|
||||
" sns.regplot(x=x_var, y=y_var, data=df_nonan, scatter=False, ci=68, line_kws={'color': 'blue', 'linewidth': 2})\n",
|
||||
" \n",
|
||||
" # Fit the regression model and get r and p values\n",
|
||||
" slope, intercept, r_value, p_value, std_err = stats.linregress(df_nonan[x_var], df_nonan[y_var])\n",
|
||||
" \n",
|
||||
" # Add labels and grid\n",
|
||||
" plt.xlabel(x_var.replace('-', ' '))\n",
|
||||
" plt.ylabel(y_var.replace('-', ' '))\n",
|
||||
" plt.grid()\n",
|
||||
" plt.tick_params(axis='both', direction='in', top=True, right=True)\n",
|
||||
" \n",
|
||||
" # Add text annotation for r and p values\n",
|
||||
" plt.text(0.05, 0.95, f'r = {r_value:.4f}\\np = {max(p_value, 0.0001):.4f}', transform=plt.gca().transAxes, fontsize=12, verticalalignment='top', bbox=dict(facecolor='white', alpha=0.5))\n",
|
||||
"\n",
|
||||
"# Set the overall title and layout\n",
|
||||
"plt.suptitle(f'Regression plot of user metrics against interaction count {casename} case', fontsize=16)\n",
|
||||
"plt.tight_layout(rect=[0, 0, 1, 0.99])\n",
|
||||
"\n",
|
||||
"# Save the figure\n",
|
||||
"plt.savefig(f'../datasets/{case}-user-interaction-regression.png')\n",
|
||||
"plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Take out change in sentiment regressions."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import pandas as pd\n",
|
||||
"import seaborn as sns\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"from scipy import stats\n",
|
||||
"\n",
|
||||
"# Assuming df_data is your DataFrame and casename and case are defined\n",
|
||||
"fig, axes = plt.subplots(1, 3, figsize=(15, 6), sharey=True)\n",
|
||||
"\n",
|
||||
"# Define the variables for std-sentiment plots\n",
|
||||
"variables = [\n",
|
||||
" (\"nn-count\", \"std-sentiment\"),\n",
|
||||
" (\"dtc-count\", \"std-sentiment\"),\n",
|
||||
" (\"tc-count\", \"std-sentiment\"),\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"# Loop through the variables and create subplots\n",
|
||||
"for i, (ax, (x_var, y_var)) in enumerate(zip(axes, variables)):\n",
|
||||
" # Drop NaN values for the current pair of variables\n",
|
||||
" df_nonan = df_data.dropna(subset=[x_var, y_var])\n",
|
||||
" \n",
|
||||
" # Create the regression plot\n",
|
||||
" sns.regplot(x=x_var, y=y_var, data=df_nonan, scatter=False, ci=68, line_kws={'color': 'blue', 'linewidth': 2}, ax=ax)\n",
|
||||
" \n",
|
||||
" # Fit the regression model and get r and p values\n",
|
||||
" slope, intercept, r_value, p_value, std_err = stats.linregress(df_nonan[x_var], df_nonan[y_var])\n",
|
||||
" \n",
|
||||
" # Add labels and grid\n",
|
||||
" ax.set_xlabel(x_var.replace('-', ' '))\n",
|
||||
" if i == 0:\n",
|
||||
" ax.set_ylabel(y_var.replace('-', ' '))\n",
|
||||
" else:\n",
|
||||
" ax.set_ylabel('')\n",
|
||||
" ax.grid()\n",
|
||||
" ax.tick_params(axis='both', direction='in', top=True, right=True)\n",
|
||||
" \n",
|
||||
" # Add text annotation for r and p values\n",
|
||||
" ax.text(0.05, 0.95, f'r = {r_value:.4f}\\np = {max(p_value, 0.0001):.4f}', transform=ax.transAxes, fontsize=12, verticalalignment='top', bbox=dict(facecolor='white', alpha=0.5))\n",
|
||||
"\n",
|
||||
"# Set the overall title and layout\n",
|
||||
"plt.suptitle(f'Regression plot of standard deviation of sentiment against interaction count {casename} case', fontsize=16)\n",
|
||||
"plt.tight_layout(rect=[0, 0, 1, 0.95])\n",
|
||||
"\n",
|
||||
"# Save the figure\n",
|
||||
"plt.savefig(f'../datasets/{case}-user-std-sentiment-regression.png')\n",
|
||||
"plt.show()"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.14.6"
|
||||
},
|
||||
"vscode": {
|
||||
"interpreter": {
|
||||
"hash": "8c75c0fdd1a718867cdcb84b32adcfdbeaad00b3a4e00a59385211aeed084d4c"
|
||||
}
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 4
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue