{"id":52162,"date":"2025-06-20T00:00:00","date_gmt":"2025-06-20T07:00:00","guid":{"rendered":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/blog\/stress-detection-using-machine-learning-griddb\/"},"modified":"2025-06-20T00:00:00","modified_gmt":"2025-06-20T07:00:00","slug":"stress-detection-using-machine-learning-griddb","status":"publish","type":"post","link":"https:\/\/griddb.net\/en\/blog\/stress-detection-using-machine-learning-griddb\/","title":{"rendered":"Stress Detection using Machine Learning &#038; GridDB"},"content":{"rendered":"<p>Stress significantly affects individuals&#8217; well-being, productivity, and overall quality of life. Understanding and predicting stress levels can help take proactive measures to mitigate its adverse effects. W<\/p>\n<p>This article demonstrates how to develop a stress detection system using machine learning and deep learning techniques with the <a href=\"https:\/\/griddb.net\/en\/\">GridDB<\/a> database. We will begin by retrieving a stress detection dataset from Kaggle, storing it in a GridDB container, and utilizing this data to train predictive models capable of estimating users&#8217; perceived stress scores.<\/p>\n<p>GridDB, a high-performance NoSQL database, is particularly suited for managing complex and dynamic datasets. Its efficient in-memory processing and flexible data storage capabilities make it an ideal choice for real-time applications.<\/p>\n<p><strong>Note:<\/strong> The codes for this tutorial are in my <a href=\"https:\/\/github.com\/usmanmalik57\/GridDB-Blogs\/tree\/main\/Stress%20Detection%20Using%20Machine%20Learning%20with%20GridDB%20as%20Database\">GridDB Blogs GitHub repository<\/a>.<\/p>\n<h2>Prerequisites<\/h2>\n<p>You need to install the following libraries to run codes in this article.<\/p>\n<ol>\n<li>GridDB C Client<\/li>\n<li>GridDB Python client<\/li>\n<\/ol>\n<p>To install these libraries, follow the installation instructions on <a href=\"https:\/\/pypi.org\/project\/griddb-python\/\">GridDB Python Package Index (Pypi).<\/a><\/p>\n<p>The code is executed in <a href=\"https:\/\/colab.research.google.com\/\">Google Colab<\/a>, so you do not need to install other libraries.<\/p>\n<p>Run the following script to import the required libraries into your Python application.<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-python\">\nimport pandas as pd\nimport seaborn as sns\nimport matplotlib.pyplot as plt\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.metrics import mean_absolute_error, mean_squared_error\nfrom sklearn.ensemble import RandomForestRegressor\n\nimport tensorflow as tf\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Dense, Dropout, BatchNormalization\nfrom tensorflow.keras.callbacks import EarlyStopping, ModelCheckpoint\nfrom tensorflow.keras.optimizers import Adam\nfrom tensorflow.keras.models import load_model\n\nimport griddb_python as griddb<\/code><\/pre>\n<\/div>\n<h2>Inserting Stress Detection Dataset into GridDB<\/h2>\n<p>We will begin by inserting the stress detection dataset from Kaggle into GridDB. In a later section, we will retrieve data from the GridDB and train our machine-learning algorithms for user stress prediction.<\/p>\n<h3>Downloading and Importing the Stress Detection Dataset from Kaggle<\/h3>\n<p>You can <a href=\"https:\/\/www.kaggle.com\/datasets\/swadeshi\/stress-detection-dataset?resource=download\">download the stress detection dataset from Kaggle<\/a> and import it into your Python application.<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-python\">\n# Dataset download link\n# https:\/\/www.kaggle.com\/datasets\/swadeshi\/stress-detection-dataset?resource=download\n\ndataset = pd.read_csv(\"stress_detection.csv\")\nprint(f\"The dataset consists of {dataset.shape[0]} rows and {dataset.shape[1]} columns\")\ndataset.head()<\/code><\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/griddb.net\/wp-content\/uploads\/2025\/06\/img1-user-stress-dataset.webp\"><img fetchpriority=\"high\" decoding=\"async\" src=\"https:\/\/griddb.net\/wp-content\/uploads\/2025\/06\/img1-user-stress-dataset.webp\" alt=\"\" width=\"1787\" height=\"265\" class=\"aligncenter size-full wp-image-31705\" srcset=\"\/wp-content\/uploads\/2025\/06\/img1-user-stress-dataset.webp 1787w, \/wp-content\/uploads\/2025\/06\/img1-user-stress-dataset-300x44.webp 300w, \/wp-content\/uploads\/2025\/06\/img1-user-stress-dataset-1024x152.webp 1024w, \/wp-content\/uploads\/2025\/06\/img1-user-stress-dataset-768x114.webp 768w, \/wp-content\/uploads\/2025\/06\/img1-user-stress-dataset-1536x228.webp 1536w, \/wp-content\/uploads\/2025\/06\/img1-user-stress-dataset-600x89.webp 600w\" sizes=\"(max-width: 1787px) 100vw, 1787px\" \/><\/a><\/p>\n<p>The dataset consists of 3000 records belonging to 100 users. For each user, 30 days of data are recorded for various attributes such as openness, sleep duration, screen time, mobility distance, and number of calls.<\/p>\n<p>The <code>PSS_score<\/code> column contains the perceived stress score, which ranges from 10 to 40. A higher score corresponds to a higher stress level.<\/p>\n<p>The following script displays various statistics for the <code>PSS_score<\/code> column.<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-python\">\ndataset[\"PSS_score\"].describe()<\/code><\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-bash\">\ncount    3000.000000\nmean       24.701000\nstd         8.615781\nmin        10.000000\n25%        17.000000\n50%        25.000000\n75%        32.000000\nmax        39.000000\nName: PSS_score, dtype: float64\n<\/code><\/pre>\n<\/div>\n<p>Next, we will insert the user stress dataset into GridDB.<\/p>\n<h3>Connect to GridDB<\/h3>\n<p>You need to connect to a GridDB instance before inserting data into the GridDB.<\/p>\n<p>To do so, you must create a GridDB factory instance using the <code>griddb.StoreFactory.get_instance()<\/code> method.<\/p>\n<p>Next, you have to call the <code>get_store<\/code> method on the factory instance and pass the database host URL, cluster name, and user name and password. The <code>get_store()<\/code> method returns a <code>grid store<\/code> object that you can use to create containers in GridDB.<\/p>\n<p>To test whether the connection is successful, we retrieve a dummy container, <code>container1<\/code>, as shown in the script below.<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-python\">\n# GridDB connection details\nDB_HOST = \"127.0.0.1:10001\"\nDB_CLUSTER = \"myCluster\"\nDB_USER = \"admin\"\nDB_PASS = \"admin\"\n\n# creating a connection\n\nfactory = griddb.StoreFactory.get_instance()\n\ntry:\n    gridstore = factory.get_store(\n        notification_member = DB_HOST,\n        cluster_name = DB_CLUSTER,\n        username = DB_USER,\n        password = DB_PASS\n    )\n\n    container1 = gridstore.get_container(\"container1\")\n    if container1 == None:\n        print(\"Container does not exist\")\n    print(\"Successfully connected to GridDB\")\n\nexcept griddb.GSException as e:\n    for i in range(e.get_error_stack_size()):\n        print(\"[\", i, \"]\")\n        print(e.get_error_code(i))\n        print(e.get_location(i))\n        print(e.get_message(i))<\/code><\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-bash\">\nContainer does not exist\nSuccessfully connected to GridDB<\/code><\/pre>\n<\/div>\n<p>You should see the above message if the connection is successful.<\/p>\n<h3>Create Container for User Stress Data in GridDB<\/h3>\n<p>GridDB stores data in containers, which are specialized data structures for efficient data structure.<\/p>\n<p>The following script creates a GridDB container to store our stress detection dataset.<\/p>\n<p>We first remove any existing container with the name <code>user_stress_data<\/code> as we will use this name to create a new container.<\/p>\n<p>Next, we replace empty spaces in column names with an underscore since GridDB does not expect column names to have spaces.<\/p>\n<p>We will then map Pandas DataFrame data type to GridDB data types and create a column info list containing column names and corresponding GridDB data types,<\/p>\n<p>Next, we create a container info object and pass it the container name, the column info list, and the container type, which is <code>COLLECTION<\/code> for tabular data.<\/p>\n<p>Finally, we call the grid store&#8217;s <code>put_container<\/code> method and pass the container info object we created to it as a parameter.<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-python\">\n# drop container if already exists\ngridstore.drop_container(\"user_stress_data\")\n\n# Clean column names to remove spaces or forbidden characters in the GridDB container\ndataset.columns = [col.strip().replace(\" \", \"_\") for col in dataset.columns]\n\n\n# Mapping from pandas data types to GridDB data types\ntype_mapping = {\n    'float64': griddb.Type.DOUBLE,\n    'int64': griddb.Type.INTEGER,\n    'object': griddb.Type.STRING,\n    'category': griddb.Type.STRING  # Map category to STRING for GridDB\n}\n\n\n# Generate column_info dynamically\ncolumn_info = [[col, type_mapping[str(dtype)]] for col, dtype in dataset.dtypes.items()]\n\n# Define the container info\ncontainer_name = \"user_stress_data\"\ncontainer_info = griddb.ContainerInfo(\n    container_name, column_info, griddb.ContainerType.COLLECTION, row_key=True\n)\n\n# Connecting to GridDB and creating the container\ntry:\n    gridstore.put_container(container_info)\n    container = gridstore.get_container(container_name)\n    if container is None:\n        print(f\"Failed to create container: {container_name}\")\n    else:\n        print(f\"Successfully created container: {container_name}\")\n\nexcept griddb.GSException as e:\n    print(f\"Error creating container {container_name}:\")\n    for i in range(e.get_error_stack_size()):\n        print(f\"[{i}] Error code: {e.get_error_code(i)}, Message: {e.get_message(i)}\")<\/code><\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-bash\">\nSuccessfully created container: user_stress_data<\/code><\/pre>\n<\/div>\n<p>The above message shows that the container creation is successful.<\/p>\n<h3>Insert User Stress Data into GridDB<\/h3>\n<p>We can now store data in the container we created.<br \/>\nTo do so, we iterate through the rows in our dataset, convert the column data into a GridDB data type, and store each row in the container using the <code>put()<\/code> method.<\/p>\n<p>The following script inserts our stress detection dataset into the <code>user_stress_data<\/code> container we created.<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-python\">\ntry:\n    for _, row in dataset.iterrows():\n        # Prepare each row's data in the exact order as defined in `column_info`\n        row_data = [\n            int(row[col]) if dtype == griddb.Type.INTEGER else\n            float(row[col]) if dtype == griddb.Type.DOUBLE else\n            str(row[col])\n            for col, dtype in column_info\n        ]\n        # Insert the row data into the container\n        container.put(row_data)\n\n    print(f\"Successfully inserted {len(dataset)} rows of data into {container_name}\")\n\nexcept griddb.GSException as e:\n    print(f\"Error inserting data into container {container_name}:\")\n    for i in range(e.get_error_stack_size()):\n        print(f\"[{i}] Error code: {e.get_error_code(i)}, Message: {e.get_message(i)}\")<\/code><\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-bash\">\nSuccessfully inserted 3000 rows of data into user_stress_data<\/code><\/pre>\n<\/div>\n<p>The above output shows that data insertion is successful.<\/p>\n<h2>Stress Detection Using Machine and Deep Learning<\/h2>\n<p>In this section, we will retrieve the stress detection dataset from the <code>user_stress_data<\/code> GridDB container we created earlier. Subsequently, we will train machine learning and deep learning models for stress prediction.<\/p>\n<h3>Retrieving Data from GridDB<\/h3>\n<p>The following script defines the <code>retrieve_data_from_griddb()<\/code> function that accepts the container name as a parameter and calls the <code>get_container()<\/code> function on the grid store to retrieve the data container.<\/p>\n<p>Next, we create a <code>SELECT<\/code> query object and call its <code>fetch()<\/code> method to retrieve all records from the <code>user_stress_data<\/code> container. Finally, we call the <code>fetch_rows()<\/code> function to convert the records into a Pandas DataFrame.<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-python\">\ndef retrieve_data_from_griddb(container_name):\n\n    try:\n        data_container = gridstore.get_container(container_name)\n\n        # Query all data from the container\n        query = data_container.query(\"select *\")\n        rs = query.fetch()\n\n        data = rs.fetch_rows()\n        return data\n\n    except griddb.GSException as e:\n        print(f\"Error retrieving data from GridDB: {e.get_message()}\")\n        return None\n\n\nstress_dataset = retrieve_data_from_griddb(\"user_stress_data\")\nstress_dataset.head()\n<\/code><\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/griddb.net\/wp-content\/uploads\/2025\/06\/img2-user-stress-dataset-from-griddb.webp\"><img decoding=\"async\" src=\"https:\/\/griddb.net\/wp-content\/uploads\/2025\/06\/img2-user-stress-dataset-from-griddb.webp\" alt=\"\" width=\"1775\" height=\"235\" class=\"aligncenter size-full wp-image-31707\" srcset=\"\/wp-content\/uploads\/2025\/06\/img2-user-stress-dataset-from-griddb.webp 1775w, \/wp-content\/uploads\/2025\/06\/img2-user-stress-dataset-from-griddb-300x40.webp 300w, \/wp-content\/uploads\/2025\/06\/img2-user-stress-dataset-from-griddb-1024x136.webp 1024w, \/wp-content\/uploads\/2025\/06\/img2-user-stress-dataset-from-griddb-768x102.webp 768w, \/wp-content\/uploads\/2025\/06\/img2-user-stress-dataset-from-griddb-1536x203.webp 1536w, \/wp-content\/uploads\/2025\/06\/img2-user-stress-dataset-from-griddb-600x79.webp 600w\" sizes=\"(max-width: 1775px) 100vw, 1775px\" \/><\/a><\/p>\n<p>The above output shows the stress detection dataset we retrieved from the GridDB container.<\/p>\n<h3>Predicting User Stress with Machine Learning<\/h3>\n<p>We will first try to predict the <code>PSS_score<\/code> using a traditional machine learning algorithm such as <a href=\"https:\/\/en.wikipedia.org\/wiki\/Random_forest\">Random Forest Regressor<\/a>.<\/p>\n<p>The following script divides the dataset into features and labels, splits it into training and test sets, and normalizes it using the standard scaling approach.<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-python\">\nX = stress_dataset.drop(columns=['PSS_score'])\ny = stress_dataset['PSS_score']\n\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n\nscaler = StandardScaler()\nX_train = scaler.fit_transform(X_train)\nX_test = scaler.transform(X_test)<\/code><\/pre>\n<\/div>\n<p>Next, we create an object of the <code>RandomForestRegressor<\/code> class from he <a href=\"https:\/\/scikit-learn.org\/stable\/\">Scikit learn<\/a> library and pass the training and test sets to the <code>fit()<\/code> method.<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-python\">\nrf_model = RandomForestRegressor(random_state=42, n_estimators=1000)\nrf_model.fit(X_train, y_train)<\/code><\/pre>\n<\/div>\n<p>Finally, we evaluate the model performance by prediting <code>PSS_score<\/code> on the test set.<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-python\">\nrf_predictions = rf_model.predict(X_test)\n\n# Evaluate the regression model\nmae = mean_absolute_error(y_test, rf_predictions)\n\nprint(f\"Mean Absolute Error: {mae:.4f}\")<\/code><\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-bash\">\nMean Absolute Error: 7.8973<\/code><\/pre>\n<\/div>\n<p>The output shows that, on average, our model&#8217;s predicted <code>PSS_score<\/code> is off by 7.8 points. This is not so bad, but it is not very good either.<\/p>\n<p>Next, we will develop a deep neural network for stress detection prediction.<\/p>\n<h2>Predicting User Stress with Deep Learning<\/h2>\n<p>We will use the <a href=\"https:\/\/www.tensorflow.org\/\">TensorFlow<\/a> and <a href=\"https:\/\/keras.io\/\">Keras<\/a> libraries to create a sequential deep learning model with three dense layers. We will also add batch normalization and dropout to reduce model overfitting.<\/p>\n<p>We will also use an adaptive learning rate so the gradient doesn&#8217;t overshoot while training.<\/p>\n<p>Finally, we compile the model using the mean squared error loss and mean absolute error metric. We use this loss and metric since we are dealing with a regression problem.<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-python\">\nmodel = Sequential([\n    Dense(128, input_dim=X_train.shape[1], activation='relu'),\n    BatchNormalization(),\n    Dropout(0.2),\n    Dense(64, activation='relu'),\n    BatchNormalization(),\n    Dropout(0.2),\n    Dense(32, activation='relu'),\n    BatchNormalization(),\n    Dropout(0.1),\n    Dense(1)  \n])\n\n# Adaptive learning rate scheduler with exponential decay\ninitial_learning_rate = 0.001\nlr_schedule = tf.keras.optimizers.schedules.ExponentialDecay(\n    initial_learning_rate=initial_learning_rate,\n    decay_steps=10000,\n    decay_rate=0.9\n)\n\n# Compile the model with Adam optimizer and a regression loss\nmodel.compile(optimizer=Adam(learning_rate=lr_schedule),\n              loss='mean_squared_error',\n              metrics=['mean_absolute_error'])\n\n# Summary of the model\nmodel.summary()\n<\/code><\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/griddb.net\/wp-content\/uploads\/2025\/06\/img3-deep-learning-stress-detection-model-summary.webp\"><img decoding=\"async\" src=\"https:\/\/griddb.net\/wp-content\/uploads\/2025\/06\/img3-deep-learning-stress-detection-model-summary.webp\" alt=\"\" width=\"716\" height=\"553\" class=\"aligncenter size-full wp-image-31708\" srcset=\"\/wp-content\/uploads\/2025\/06\/img3-deep-learning-stress-detection-model-summary.webp 716w, \/wp-content\/uploads\/2025\/06\/img3-deep-learning-stress-detection-model-summary-300x232.webp 300w, \/wp-content\/uploads\/2025\/06\/img3-deep-learning-stress-detection-model-summary-600x463.webp 600w\" sizes=\"(max-width: 716px) 100vw, 716px\" \/><\/a><\/p>\n<p>The above output shows the model summary.<\/p>\n<p>Next, we train the model using the <code>fit()<\/code> method. We use an early stopping approach that stops model training if the loss doesn&#8217;t decrease for 100 consecutive epochs. Finally, we save the best model at the end of model training.<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-python\">\n# Define callbacks for training\nearly_stopping = EarlyStopping(monitor='val_loss', patience=100, restore_best_weights=True)\nmodel_checkpoint = ModelCheckpoint('best_model.keras', monitor='val_loss', save_best_only=True)\n\n# Train the model with the callbacks\nhistory = model.fit(\n    X_train, y_train,\n    epochs=1000,\n    batch_size=4,\n    validation_data=(X_test, y_test),\n    callbacks=[early_stopping, model_checkpoint],\n    verbose=1\n)<\/code><\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/griddb.net\/wp-content\/uploads\/2025\/06\/img4-deep-learning-model-training-results.webp\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/griddb.net\/wp-content\/uploads\/2025\/06\/img4-deep-learning-model-training-results.webp\" alt=\"\" width=\"1178\" height=\"232\" class=\"aligncenter size-full wp-image-31709\" srcset=\"\/wp-content\/uploads\/2025\/06\/img4-deep-learning-model-training-results.webp 1178w, \/wp-content\/uploads\/2025\/06\/img4-deep-learning-model-training-results-300x59.webp 300w, \/wp-content\/uploads\/2025\/06\/img4-deep-learning-model-training-results-1024x202.webp 1024w, \/wp-content\/uploads\/2025\/06\/img4-deep-learning-model-training-results-768x151.webp 768w, \/wp-content\/uploads\/2025\/06\/img4-deep-learning-model-training-results-600x118.webp 600w\" sizes=\"(max-width: 1178px) 100vw, 1178px\" \/><\/a><\/p>\n<p>We load the best model to evaluate the performance and use it to make predictions on the test set.<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-python\">\n\n# Load the best model\nbest_model = load_model('best_model.keras')\n\n# Make predictions on the test set\ny_pred = best_model.predict(X_test)\n\n# Calculate Mean Absolute Error\nmae = mean_absolute_error(y_test, y_pred)\nprint(f\"Mean Absolute Error: {mae:.4f}\")\n\n# Plot training history to show MAE over epochs\nplt.plot(history.history['mean_absolute_error'], label='Train MAE')\nplt.plot(history.history['val_mean_absolute_error'], label='Validation MAE')\nplt.title('Mean Absolute Error over Epochs')\nplt.xlabel('Epochs')\nplt.ylabel('MAE')\nplt.legend()\nplt.show()<\/code><\/pre>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/griddb.net\/wp-content\/uploads\/2025\/06\/img5-deep-learning-predictions.webp\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/griddb.net\/wp-content\/uploads\/2025\/06\/img5-deep-learning-predictions.webp\" alt=\"\" width=\"632\" height=\"538\" class=\"aligncenter size-full wp-image-31710\" srcset=\"\/wp-content\/uploads\/2025\/06\/img5-deep-learning-predictions.webp 632w, \/wp-content\/uploads\/2025\/06\/img5-deep-learning-predictions-300x255.webp 300w, \/wp-content\/uploads\/2025\/06\/img5-deep-learning-predictions-600x511.webp 600w\" sizes=\"(max-width: 632px) 100vw, 632px\" \/><\/a><\/p>\n<p>On the test set, we achieved a mean absolute error value of 7.89, similar to what we achieved using the Random Forest Regressor. The results also show that our model is slightly overfitting since the training loss is lower compared to validation loss across the epochs.<\/p>\n<h2>Conclusion<\/h2>\n<p>This article is a comprehensive guide to developing a stress detection system using machine learning, deep learning regression models, and the GridDB database.<\/p>\n<p>In this article, you explored the process of connecting to GridDB, inserting a stress detection dataset, and utilizing Random Forest and deep neural networks to predict perceived stress scores. The Random Forest and deep learning models performed decently with a manageable mean absolute error.<\/p>\n<p>If you have any questions or need assistance with GridDB or machine learning techniques, please ask on Stack Overflow using the <code>griddb<\/code> tag. Our team is always happy to help.<\/p>\n<p>For the complete code, visit my <a href=\"https:\/\/github.com\/usmanmalik57\/GridDB-Blogs\/tree\/main\/Stress%20Detection%20Using%20Machine%20Learning%20with%20GridDB%20as%20Database\">GridDB Blogs GitHub<\/a> repository.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Stress significantly affects individuals&#8217; well-being, productivity, and overall quality of life. Understanding and predicting stress levels can help take proactive measures to mitigate its adverse effects. W This article demonstrates how to develop a stress detection system using machine learning and deep learning techniques with the GridDB database. We will begin by retrieving a stress [&hellip;]<\/p>\n","protected":false},"author":41,"featured_media":52163,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[121],"tags":[],"class_list":["post-52162","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Stress Detection using Machine Learning &amp; GridDB | GridDB: Open Source Time Series Database for IoT<\/title>\n<meta name=\"description\" content=\"Stress significantly affects individuals&#039; well-being, productivity, and overall quality of life. Understanding and predicting stress levels can help take\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/griddb.net\/en\/blog\/stress-detection-using-machine-learning-griddb\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Stress Detection using Machine Learning &amp; GridDB | GridDB: Open Source Time Series Database for IoT\" \/>\n<meta property=\"og:description\" content=\"Stress significantly affects individuals&#039; well-being, productivity, and overall quality of life. Understanding and predicting stress levels can help take\" \/>\n<meta property=\"og:url\" content=\"https:\/\/griddb.net\/en\/blog\/stress-detection-using-machine-learning-griddb\/\" \/>\n<meta property=\"og:site_name\" content=\"GridDB: Open Source Time Series Database for IoT\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/griddbcommunity\/\" \/>\n<meta property=\"article:published_time\" content=\"2025-06-20T07:00:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/griddb.net\/wp-content\/uploads\/2025\/12\/Gemini_Generated_Image_xdk5chxdk5chxdk5.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"2048\" \/>\n\t<meta property=\"og:image:height\" content=\"2048\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"griddb-admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@GridDBCommunity\" \/>\n<meta name=\"twitter:site\" content=\"@GridDBCommunity\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"griddb-admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/griddb.net\/en\/blog\/stress-detection-using-machine-learning-griddb\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/griddb.net\/en\/blog\/stress-detection-using-machine-learning-griddb\/\"},\"author\":{\"name\":\"griddb-admin\",\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#\/schema\/person\/4fe914ca9576878e82f5e8dd3ba52233\"},\"headline\":\"Stress Detection using Machine Learning &#038; GridDB\",\"datePublished\":\"2025-06-20T07:00:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/griddb.net\/en\/blog\/stress-detection-using-machine-learning-griddb\/\"},\"wordCount\":1196,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#organization\"},\"image\":{\"@id\":\"https:\/\/griddb.net\/en\/blog\/stress-detection-using-machine-learning-griddb\/#primaryimage\"},\"thumbnailUrl\":\"\/wp-content\/uploads\/2025\/12\/Gemini_Generated_Image_xdk5chxdk5chxdk5.webp\",\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/griddb.net\/en\/blog\/stress-detection-using-machine-learning-griddb\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/griddb.net\/en\/blog\/stress-detection-using-machine-learning-griddb\/\",\"url\":\"https:\/\/griddb.net\/en\/blog\/stress-detection-using-machine-learning-griddb\/\",\"name\":\"Stress Detection using Machine Learning & GridDB | GridDB: Open Source Time Series Database for IoT\",\"isPartOf\":{\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/griddb.net\/en\/blog\/stress-detection-using-machine-learning-griddb\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/griddb.net\/en\/blog\/stress-detection-using-machine-learning-griddb\/#primaryimage\"},\"thumbnailUrl\":\"\/wp-content\/uploads\/2025\/12\/Gemini_Generated_Image_xdk5chxdk5chxdk5.webp\",\"datePublished\":\"2025-06-20T07:00:00+00:00\",\"description\":\"Stress significantly affects individuals' well-being, productivity, and overall quality of life. Understanding and predicting stress levels can help take\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/griddb.net\/en\/blog\/stress-detection-using-machine-learning-griddb\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/griddb.net\/en\/blog\/stress-detection-using-machine-learning-griddb\/#primaryimage\",\"url\":\"\/wp-content\/uploads\/2025\/12\/Gemini_Generated_Image_xdk5chxdk5chxdk5.webp\",\"contentUrl\":\"\/wp-content\/uploads\/2025\/12\/Gemini_Generated_Image_xdk5chxdk5chxdk5.webp\",\"width\":2048,\"height\":2048},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#website\",\"url\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/\",\"name\":\"GridDB: Open Source Time Series Database for IoT\",\"description\":\"GridDB is an open source time-series database with the performance of NoSQL and convenience of SQL\",\"publisher\":{\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#organization\",\"name\":\"Fixstars\",\"url\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/griddb.net\/wp-content\/uploads\/2019\/04\/fixstars_logo_web_tagline.png\",\"contentUrl\":\"https:\/\/griddb.net\/wp-content\/uploads\/2019\/04\/fixstars_logo_web_tagline.png\",\"width\":200,\"height\":83,\"caption\":\"Fixstars\"},\"image\":{\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/griddbcommunity\/\",\"https:\/\/x.com\/GridDBCommunity\",\"https:\/\/www.linkedin.com\/company\/griddb-by-toshiba\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#\/schema\/person\/4fe914ca9576878e82f5e8dd3ba52233\",\"name\":\"griddb-admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/5bceca1cafc06886a7ba873e2f0a28011a1176c4dea59709f735b63ae30d0342?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/5bceca1cafc06886a7ba873e2f0a28011a1176c4dea59709f735b63ae30d0342?s=96&d=mm&r=g\",\"caption\":\"griddb-admin\"},\"url\":\"https:\/\/griddb.net\/en\/author\/griddb-admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Stress Detection using Machine Learning & GridDB | GridDB: Open Source Time Series Database for IoT","description":"Stress significantly affects individuals' well-being, productivity, and overall quality of life. Understanding and predicting stress levels can help take","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":"https:\/\/griddb.net\/en\/blog\/stress-detection-using-machine-learning-griddb\/","og_locale":"en_US","og_type":"article","og_title":"Stress Detection using Machine Learning & GridDB | GridDB: Open Source Time Series Database for IoT","og_description":"Stress significantly affects individuals' well-being, productivity, and overall quality of life. Understanding and predicting stress levels can help take","og_url":"https:\/\/griddb.net\/en\/blog\/stress-detection-using-machine-learning-griddb\/","og_site_name":"GridDB: Open Source Time Series Database for IoT","article_publisher":"https:\/\/www.facebook.com\/griddbcommunity\/","article_published_time":"2025-06-20T07:00:00+00:00","og_image":[{"width":2048,"height":2048,"url":"https:\/\/griddb.net\/wp-content\/uploads\/2025\/12\/Gemini_Generated_Image_xdk5chxdk5chxdk5.webp","type":"image\/webp"}],"author":"griddb-admin","twitter_card":"summary_large_image","twitter_creator":"@GridDBCommunity","twitter_site":"@GridDBCommunity","twitter_misc":{"Written by":"griddb-admin","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/griddb.net\/en\/blog\/stress-detection-using-machine-learning-griddb\/#article","isPartOf":{"@id":"https:\/\/griddb.net\/en\/blog\/stress-detection-using-machine-learning-griddb\/"},"author":{"name":"griddb-admin","@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#\/schema\/person\/4fe914ca9576878e82f5e8dd3ba52233"},"headline":"Stress Detection using Machine Learning &#038; GridDB","datePublished":"2025-06-20T07:00:00+00:00","mainEntityOfPage":{"@id":"https:\/\/griddb.net\/en\/blog\/stress-detection-using-machine-learning-griddb\/"},"wordCount":1196,"commentCount":0,"publisher":{"@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#organization"},"image":{"@id":"https:\/\/griddb.net\/en\/blog\/stress-detection-using-machine-learning-griddb\/#primaryimage"},"thumbnailUrl":"\/wp-content\/uploads\/2025\/12\/Gemini_Generated_Image_xdk5chxdk5chxdk5.webp","articleSection":["Blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/griddb.net\/en\/blog\/stress-detection-using-machine-learning-griddb\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/griddb.net\/en\/blog\/stress-detection-using-machine-learning-griddb\/","url":"https:\/\/griddb.net\/en\/blog\/stress-detection-using-machine-learning-griddb\/","name":"Stress Detection using Machine Learning & GridDB | GridDB: Open Source Time Series Database for IoT","isPartOf":{"@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/griddb.net\/en\/blog\/stress-detection-using-machine-learning-griddb\/#primaryimage"},"image":{"@id":"https:\/\/griddb.net\/en\/blog\/stress-detection-using-machine-learning-griddb\/#primaryimage"},"thumbnailUrl":"\/wp-content\/uploads\/2025\/12\/Gemini_Generated_Image_xdk5chxdk5chxdk5.webp","datePublished":"2025-06-20T07:00:00+00:00","description":"Stress significantly affects individuals' well-being, productivity, and overall quality of life. Understanding and predicting stress levels can help take","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/griddb.net\/en\/blog\/stress-detection-using-machine-learning-griddb\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/griddb.net\/en\/blog\/stress-detection-using-machine-learning-griddb\/#primaryimage","url":"\/wp-content\/uploads\/2025\/12\/Gemini_Generated_Image_xdk5chxdk5chxdk5.webp","contentUrl":"\/wp-content\/uploads\/2025\/12\/Gemini_Generated_Image_xdk5chxdk5chxdk5.webp","width":2048,"height":2048},{"@type":"WebSite","@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#website","url":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/","name":"GridDB: Open Source Time Series Database for IoT","description":"GridDB is an open source time-series database with the performance of NoSQL and convenience of SQL","publisher":{"@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#organization","name":"Fixstars","url":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#\/schema\/logo\/image\/","url":"https:\/\/griddb.net\/wp-content\/uploads\/2019\/04\/fixstars_logo_web_tagline.png","contentUrl":"https:\/\/griddb.net\/wp-content\/uploads\/2019\/04\/fixstars_logo_web_tagline.png","width":200,"height":83,"caption":"Fixstars"},"image":{"@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/griddbcommunity\/","https:\/\/x.com\/GridDBCommunity","https:\/\/www.linkedin.com\/company\/griddb-by-toshiba"]},{"@type":"Person","@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#\/schema\/person\/4fe914ca9576878e82f5e8dd3ba52233","name":"griddb-admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/5bceca1cafc06886a7ba873e2f0a28011a1176c4dea59709f735b63ae30d0342?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5bceca1cafc06886a7ba873e2f0a28011a1176c4dea59709f735b63ae30d0342?s=96&d=mm&r=g","caption":"griddb-admin"},"url":"https:\/\/griddb.net\/en\/author\/griddb-admin\/"}]}},"_links":{"self":[{"href":"https:\/\/griddb.net\/en\/wp-json\/wp\/v2\/posts\/52162","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/griddb.net\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/griddb.net\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/griddb.net\/en\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/griddb.net\/en\/wp-json\/wp\/v2\/comments?post=52162"}],"version-history":[{"count":0,"href":"https:\/\/griddb.net\/en\/wp-json\/wp\/v2\/posts\/52162\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/griddb.net\/en\/wp-json\/wp\/v2\/media\/52163"}],"wp:attachment":[{"href":"https:\/\/griddb.net\/en\/wp-json\/wp\/v2\/media?parent=52162"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/griddb.net\/en\/wp-json\/wp\/v2\/categories?post=52162"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/griddb.net\/en\/wp-json\/wp\/v2\/tags?post=52162"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}