Skip to content

Commit

Permalink
feat (component-service): new section
Browse files Browse the repository at this point in the history
  • Loading branch information
santanche committed Oct 5, 2024
1 parent 0ee836c commit 98451da
Show file tree
Hide file tree
Showing 14 changed files with 7,069,896 additions and 1 deletion.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ build/
*.class

## Node ##
node_modules
node_modules

### Python ###
*.pyc
__pycache__/
Empty file added notebooks/ai/README.md
Empty file.
96 changes: 96 additions & 0 deletions notebooks/ai/age-food-correlation.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'fcid_code': '600349000', 'correlation': -0.42727039243602566, 'p_value': 1.3055703823764138e-50}\n"
]
}
],
"source": [
"import pandas as pd\n",
"from scipy import stats\n",
"\n",
"# Load the CSV file\n",
"df = pd.read_csv(\"intake-person-demo(age).csv\", dtype={'fcid_code': str})\n",
"\n",
"def get_correlation(fcid_code):\n",
" # Filter the dataframe for the given fcid_code\n",
" filtered_df = df[df['fcid_code'] == fcid_code]\n",
" \n",
" # Check if there's data for the given fcid_code\n",
" if filtered_df.empty:\n",
" return {\"error\": \"No data found for the given fcid_code\"}\n",
" \n",
" # Calculate the correlation between age and intake_bw\n",
" correlation, p_value = stats.pearsonr(filtered_df['age'], filtered_df['intake_bw'])\n",
" \n",
" return {\n",
" \"fcid_code\": fcid_code,\n",
" \"correlation\": correlation,\n",
" \"p_value\": p_value\n",
" }\n",
"\n",
"# Example usage\n",
"result = get_correlation(\"600349000\")\n",
"print(result)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To use this function, make sure you have the required libraries installed and the CSV file in the same directory as your notebook. You can install the libraries using:\n",
"\n",
"```\n",
"!pip install pandas scipy\n",
"```\n",
"\n",
"Then, you can call the function with different fcid_codes to get the correlation:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Example usage with multiple fcid_codes\n",
"fcid_codes = [\"code1\", \"code2\", \"code3\"]\n",
"\n",
"for code in fcid_codes:\n",
" result = get_correlation(code)\n",
" print(f\"Result for {code}:\")\n",
" print(result)\n",
" print()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading

0 comments on commit 98451da

Please sign in to comment.