{"id":2096,"date":"2018-06-14T00:26:45","date_gmt":"2018-06-14T00:26:45","guid":{"rendered":"http:\/\/intelligentonlinetools.com\/blog\/?page_id=2096"},"modified":"2018-06-15T00:48:05","modified_gmt":"2018-06-15T00:48:05","slug":"source-code-for-machine-learning-correlation-data-analysis-between-food-and-mood","status":"publish","type":"page","link":"http:\/\/intelligentonlinetools.com\/blog\/source-code-for-machine-learning-correlation-data-analysis-between-food-and-mood\/","title":{"rendered":"Source Code for Machine Learning Correlation Data Analysis Between Food and Mood"},"content":{"rendered":"<p>Here is the code for <a href=http:\/\/intelligentonlinetools.com\/blog\/2018\/06\/10\/machine-learning-correlation-analysis-food-mood target=\"_blank\">Machine Learning Correlation Data Analysis Between Food and Mood<\/a><br \/>\nPython pandas dataframe is used in this script for calculation correlation between two time series.<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n# -*- coding: utf-8 -*-\r\n\r\nimport numpy as np\r\nimport pandas as pd\r\nimport matplotlib.pyplot as plt\r\nimport seaborn\r\n\r\npd.set_option('display.height', 1000)\r\npd.set_option('display.max_rows', 500)\r\npd.set_option('display.max_columns', 500)\r\npd.set_option('display.width', 1000)\r\n\r\n\r\nprint('loading csv file ...')\r\ndf = pd.read_csv(&quot;data.csv&quot;)\r\ndf.columns=['X','Y']\r\n\r\nn=15\r\nm=15\r\n\r\n\r\ndef get_data (df_pandas,k,z):\r\n    \r\n    \r\n  \r\n    x = np.zeros(df_pandas.shape[0]) \r\n    y = np.zeros(df_pandas.shape[0])\r\n       \r\n    new_df = pd.DataFrame() #creates a new dataframe that's empty\r\n    for index, row in df_pandas.iterrows():\r\n       \r\n        x[index]=df_pandas.loc[index-k:index,'X'].mean()\r\n      \r\n        y[index]=df_pandas.loc[index:index+z,'Y'].mean()\r\n    \r\n    new_df=pd.concat([pd.DataFrame(x),pd.DataFrame(y)], &quot;columns&quot;)\r\n    new_df.columns = ['X', 'Y']\r\n   \r\n    return new_df       \r\n        \r\n        \r\n\r\ncorr_df = pd.DataFrame() #creates a new dataframe that's empty\r\n\r\nfor i in range (1,n):\r\n    for j in range (1,m):\r\n   \r\n       data=get_data(df, i, j)\r\n       corr_df.loc[i, j] = data['X'].corr(data['Y'])\r\n\r\nprint (&quot;corr_df&quot;)       \r\nprint (corr_df)        \r\n\r\ndef heatmap(pddf, vmax=1.0, vmin=1.0, do_mask=False):        \r\n   print(&quot;--------------- CREATE A HEATMAP ---------------&quot;)\r\n\r\n   if do_mask:                                                                  \r\n      mask = np.zeros_like(pddf)\r\n      mask[np.triu_indices_from(mask)] = True\r\n\r\n\r\n      seaborn.heatmap(pddf, cmap='RdYlGn_r', vmax=vmax, vmin=vmin , mask = mask, linewidths=2.5)\r\n   else:   \r\n      seaborn.heatmap(pddf, cmap='RdYlGn_r', vmax=vmax, vmin=vmin , linewidths=2.5)\r\n     \r\n   # in case want reorient the labels for each column and row to make them easier to read.\r\n   plt.yticks(rotation=0) \r\n   plt.xticks(rotation=0) \r\n   plt.show()\r\n\r\nheatmap (corr_df, vmax=0.5, vmin=0)\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Here is the code for Machine Learning Correlation Data Analysis Between Food and Mood Python pandas dataframe is used in this script for calculation correlation between two time series.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"jetpack_post_was_ever_published":false},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Source Code for Machine Learning Correlation Data Analysis Between Food and Mood - Machine Learning Applications<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/intelligentonlinetools.com\/blog\/source-code-for-machine-learning-correlation-data-analysis-between-food-and-mood\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Source Code for Machine Learning Correlation Data Analysis Between Food and Mood - Machine Learning Applications\" \/>\n<meta property=\"og:description\" content=\"Here is the code for Machine Learning Correlation Data Analysis Between Food and Mood Python pandas dataframe is used in this script for calculation correlation between two time series.\" \/>\n<meta property=\"og:url\" content=\"http:\/\/intelligentonlinetools.com\/blog\/source-code-for-machine-learning-correlation-data-analysis-between-food-and-mood\/\" \/>\n<meta property=\"og:site_name\" content=\"Machine Learning Applications\" \/>\n<meta property=\"article:modified_time\" content=\"2018-06-15T00:48:05+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"http:\/\/intelligentonlinetools.com\/blog\/source-code-for-machine-learning-correlation-data-analysis-between-food-and-mood\/\",\"url\":\"http:\/\/intelligentonlinetools.com\/blog\/source-code-for-machine-learning-correlation-data-analysis-between-food-and-mood\/\",\"name\":\"Source Code for Machine Learning Correlation Data Analysis Between Food and Mood - Machine Learning Applications\",\"isPartOf\":{\"@id\":\"http:\/\/intelligentonlinetools.com\/blog\/#website\"},\"datePublished\":\"2018-06-14T00:26:45+00:00\",\"dateModified\":\"2018-06-15T00:48:05+00:00\",\"breadcrumb\":{\"@id\":\"http:\/\/intelligentonlinetools.com\/blog\/source-code-for-machine-learning-correlation-data-analysis-between-food-and-mood\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/intelligentonlinetools.com\/blog\/source-code-for-machine-learning-correlation-data-analysis-between-food-and-mood\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/intelligentonlinetools.com\/blog\/source-code-for-machine-learning-correlation-data-analysis-between-food-and-mood\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/intelligentonlinetools.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Source Code for Machine Learning Correlation Data Analysis Between Food and Mood\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/intelligentonlinetools.com\/blog\/#website\",\"url\":\"http:\/\/intelligentonlinetools.com\/blog\/\",\"name\":\"Machine Learning Applications\",\"description\":\"Artificial intelligence, data mining and machine learning for building web based tools and services.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/intelligentonlinetools.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Source Code for Machine Learning Correlation Data Analysis Between Food and Mood - Machine Learning Applications","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/intelligentonlinetools.com\/blog\/source-code-for-machine-learning-correlation-data-analysis-between-food-and-mood\/","og_locale":"en_US","og_type":"article","og_title":"Source Code for Machine Learning Correlation Data Analysis Between Food and Mood - Machine Learning Applications","og_description":"Here is the code for Machine Learning Correlation Data Analysis Between Food and Mood Python pandas dataframe is used in this script for calculation correlation between two time series.","og_url":"http:\/\/intelligentonlinetools.com\/blog\/source-code-for-machine-learning-correlation-data-analysis-between-food-and-mood\/","og_site_name":"Machine Learning Applications","article_modified_time":"2018-06-15T00:48:05+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"http:\/\/intelligentonlinetools.com\/blog\/source-code-for-machine-learning-correlation-data-analysis-between-food-and-mood\/","url":"http:\/\/intelligentonlinetools.com\/blog\/source-code-for-machine-learning-correlation-data-analysis-between-food-and-mood\/","name":"Source Code for Machine Learning Correlation Data Analysis Between Food and Mood - Machine Learning Applications","isPartOf":{"@id":"http:\/\/intelligentonlinetools.com\/blog\/#website"},"datePublished":"2018-06-14T00:26:45+00:00","dateModified":"2018-06-15T00:48:05+00:00","breadcrumb":{"@id":"http:\/\/intelligentonlinetools.com\/blog\/source-code-for-machine-learning-correlation-data-analysis-between-food-and-mood\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/intelligentonlinetools.com\/blog\/source-code-for-machine-learning-correlation-data-analysis-between-food-and-mood\/"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/intelligentonlinetools.com\/blog\/source-code-for-machine-learning-correlation-data-analysis-between-food-and-mood\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/intelligentonlinetools.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Source Code for Machine Learning Correlation Data Analysis Between Food and Mood"}]},{"@type":"WebSite","@id":"http:\/\/intelligentonlinetools.com\/blog\/#website","url":"http:\/\/intelligentonlinetools.com\/blog\/","name":"Machine Learning Applications","description":"Artificial intelligence, data mining and machine learning for building web based tools and services.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/intelligentonlinetools.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"}]}},"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/P7h1IJ-xO","jetpack-related-posts":[{"id":2366,"url":"http:\/\/intelligentonlinetools.com\/blog\/rl-dyna-q\/","url_meta":{"origin":2096,"position":0},"title":"Reinforcement Learning Dyna-Q","date":"November 3, 2018","format":false,"excerpt":"This is the python source code of RL_brain.py for post Reinforcement Learning Example for Planning Tasks Using Q Learning and Dyna-Q","rel":"","context":"Similar post","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2083,"url":"http:\/\/intelligentonlinetools.com\/blog\/dataset-correlation-analysis-food-mood\/","url_meta":{"origin":2096,"position":1},"title":"Dataset from Correlation Data Analysis Between Food and Mood","date":"June 13, 2018","format":false,"excerpt":"Here is the dataset from blog post \"Machine Learning for Correlation Data Analysis Between Food and Mood\" The dataset has two columns, X and Y where: X is how much sweet food was taken on daily basis, on the scale 0 - 1 , 0 is nothing, 1 means a\u2026","rel":"","context":"Similar post","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2499,"url":"http:\/\/intelligentonlinetools.com\/blog\/reinforcement-learning-dqn\/","url_meta":{"origin":2096,"position":2},"title":"Reinforcement Learning DQN","date":"January 5, 2019","format":false,"excerpt":"This is the python source code of RL_brainDQN.py for post Reinforcement Learning Python DQN Application for Resource Allocation","rel":"","context":"Similar post","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1756,"url":"http:\/\/intelligentonlinetools.com\/blog\/time-series-prediction-lstm-keras-python-source-code\/","url_meta":{"origin":2096,"position":3},"title":"Time Series Prediction with LSTM and Keras  &#8211; Python Source Code","date":"January 5, 2018","format":false,"excerpt":"Here you can find python source code for Time Series Prediction with LSTM and Keras","rel":"","context":"Similar post","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2284,"url":"http:\/\/intelligentonlinetools.com\/blog\/neural-networks-applications-seismic-prospecting-neural-network-code\/","url_meta":{"origin":2096,"position":4},"title":"Neural Networks Applications in Seismic Prospecting  &#8211; Neural Network Code","date":"September 8, 2018","format":false,"excerpt":"Below you will find neural network code for blog post Artificial Intelligence - Neural Networks Applications in Seismic Prospecting. This post is showing how seismic process can be automated using deep neural network such as simple Multi Layer perceptron. References 1. Artificial Intelligence - Neural Networks Applications in Seismic Prospecting","rel":"","context":"Similar post","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2501,"url":"http:\/\/intelligentonlinetools.com\/blog\/reinforcement-learning-dqn-run-planning\/","url_meta":{"origin":2096,"position":5},"title":"Reinforcement Learning DQN Run Planning","date":"January 5, 2019","format":false,"excerpt":"This is the python source code of run_planning_RL_DQN.py for post Reinforcement Learning Python DQN Application for Resource Allocation","rel":"","context":"Similar post","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/intelligentonlinetools.com\/blog\/wp-json\/wp\/v2\/pages\/2096"}],"collection":[{"href":"http:\/\/intelligentonlinetools.com\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/intelligentonlinetools.com\/blog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/intelligentonlinetools.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/intelligentonlinetools.com\/blog\/wp-json\/wp\/v2\/comments?post=2096"}],"version-history":[{"count":3,"href":"http:\/\/intelligentonlinetools.com\/blog\/wp-json\/wp\/v2\/pages\/2096\/revisions"}],"predecessor-version":[{"id":2116,"href":"http:\/\/intelligentonlinetools.com\/blog\/wp-json\/wp\/v2\/pages\/2096\/revisions\/2116"}],"wp:attachment":[{"href":"http:\/\/intelligentonlinetools.com\/blog\/wp-json\/wp\/v2\/media?parent=2096"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}