基于大数据的人类健康生活方式数据分析系统 | 大数据时代必备毕设:人类健康生活方式数据分析系统紧跟Hadoop+Spark技术潮流

43 阅读7分钟

💖💖作者:计算机毕业设计杰瑞 💙💙个人简介:曾长期从事计算机专业培训教学,本人也热爱上课教学,语言擅长Java、微信小程序、Python、Golang、安卓Android等,开发项目包括大数据、深度学习、网站、小程序、安卓、算法。平常会做一些项目定制化开发、代码讲解、答辩教学、文档编写、也懂一些降重方面的技巧。平常喜欢分享一些自己开发中遇到的问题的解决办法,也喜欢交流技术,大家有技术代码这一块的问题可以问我! 💛💛想说的话:感谢大家的关注与支持! 💜💜 网站实战项目 安卓/小程序实战项目 大数据实战项目 深度学校实战项目 计算机毕业设计选题推荐

基于大数据的人类健康生活方式数据分析系统介绍

《人类健康生活方式数据分析系统》是一个基于大数据技术构建的健康数据分析平台,采用Hadoop分布式存储架构结合Spark大数据处理引擎,实现对海量健康生活数据的高效存储、处理和分析。系统前端采用Vue+ElementUI+Echarts技术栈构建直观友好的用户界面,后端基于Spring Boot框架搭建稳定的服务架构,通过MySQL数据库存储结构化数据。系统核心功能涵盖健康生活数据管理、生理衰退关联分析、人群健康画像分析、生活方式影响分析以及特定人群风险分析等模块,运用Spark SQL进行复杂数据查询,结合Pandas和NumPy进行数据处理和统计分析。平台能够处理多维度健康指标数据,通过大数据分析技术挖掘健康生活方式与人体生理指标之间的关联规律,为用户提供科学的健康生活指导建议,同时支持管理员进行用户信息管理、系统公告发布等后台管理功能。

基于大数据的人类健康生活方式数据分析系统演示视频

演示视频

基于大数据的人类健康生活方式数据分析系统演示图片

在这里插入图片描述 在这里插入图片描述 在这里插入图片描述 在这里插入图片描述 在这里插入图片描述 在这里插入图片描述 在这里插入图片描述 在这里插入图片描述

基于大数据的人类健康生活方式数据分析系统代码展示

from pyspark.sql import SparkSession
from pyspark.sql.functions import col, avg, count, when, desc, asc
import pandas as pd
import numpy as np
from sklearn.cluster import KMeans
from sklearn.preprocessing import StandardScaler
from datetime import datetime
import json

spark = SparkSession.builder.appName("HealthDataAnalysis").config("spark.some.config.option", "some-value").getOrCreate()

def health_data_correlation_analysis(user_id=None):
    """生理衰退关联分析核心功能"""
    health_df = spark.sql("""
        SELECT user_id, age, gender, bmi, blood_pressure_high, blood_pressure_low, 
               heart_rate, sleep_hours, exercise_frequency, diet_score, stress_level,
               created_time FROM health_data WHERE status = 1
    """)
    if user_id:
        health_df = health_df.filter(col("user_id") == user_id)
    health_pandas = health_df.toPandas()
    health_pandas['age_group'] = pd.cut(health_pandas['age'], bins=[0, 25, 35, 45, 55, 100], labels=['青年', '青中年', '中年', '中老年', '老年'])
    correlation_matrix = health_pandas[['bmi', 'blood_pressure_high', 'blood_pressure_low', 'heart_rate', 'sleep_hours', 'exercise_frequency', 'diet_score', 'stress_level']].corr()
    aging_indicators = health_pandas.groupby('age_group').agg({
        'blood_pressure_high': ['mean', 'std'],
        'heart_rate': ['mean', 'std'],
        'bmi': ['mean', 'std'],
        'sleep_hours': ['mean', 'std']
    }).round(2)
    risk_factors = []
    for index, row in health_pandas.iterrows():
        risk_score = 0
        if row['bmi'] > 28:
            risk_score += 2
        if row['blood_pressure_high'] > 140:
            risk_score += 3
        if row['sleep_hours'] < 6:
            risk_score += 2
        if row['exercise_frequency'] < 2:
            risk_score += 1
        if row['stress_level'] > 7:
            risk_score += 2
        risk_factors.append({'user_id': row['user_id'], 'risk_score': risk_score, 'risk_level': '高风险' if risk_score >= 6 else '中风险' if risk_score >= 3 else '低风险'})
    deterioration_analysis = health_pandas.groupby(['age_group', 'gender']).agg({
        'blood_pressure_high': lambda x: (x > 140).sum() / len(x) * 100,
        'bmi': lambda x: (x > 28).sum() / len(x) * 100,
        'sleep_hours': lambda x: (x < 6).sum() / len(x) * 100
    }).round(2)
    return {
        'correlation_matrix': correlation_matrix.to_dict(),
        'aging_indicators': aging_indicators.to_dict(),
        'risk_factors': risk_factors,
        'deterioration_analysis': deterioration_analysis.to_dict()
    }

def population_health_portrait_analysis():
    """人群健康画像分析核心功能"""
    health_df = spark.sql("""
        SELECT h.*, u.occupation, u.education_level, u.income_level, u.location 
        FROM health_data h JOIN user_info u ON h.user_id = u.user_id 
        WHERE h.status = 1
    """)
    health_pandas = health_df.toPandas()
    features = ['bmi', 'blood_pressure_high', 'heart_rate', 'sleep_hours', 'exercise_frequency', 'diet_score', 'stress_level']
    scaler = StandardScaler()
    scaled_features = scaler.fit_transform(health_pandas[features])
    kmeans = KMeans(n_clusters=4, random_state=42)
    health_pandas['health_cluster'] = kmeans.fit_predict(scaled_features)
    cluster_names = {0: '健康活力型', 1: '亚健康型', 2: '慢性病风险型', 3: '高风险型'}
    health_pandas['cluster_name'] = health_pandas['health_cluster'].map(cluster_names)
    cluster_analysis = health_pandas.groupby('cluster_name').agg({
        'bmi': ['mean', 'std', 'min', 'max'],
        'blood_pressure_high': ['mean', 'std'],
        'heart_rate': ['mean', 'std'],
        'sleep_hours': ['mean', 'std'],
        'exercise_frequency': ['mean', 'std'],
        'diet_score': ['mean', 'std'],
        'stress_level': ['mean', 'std'],
        'user_id': 'count'
    }).round(2)
    demographic_analysis = health_pandas.groupby(['cluster_name', 'gender', 'occupation']).size().reset_index(name='count')
    lifestyle_patterns = health_pandas.groupby('cluster_name').apply(lambda x: {
        '平均运动频率': x['exercise_frequency'].mean(),
        '平均睡眠时长': x['sleep_hours'].mean(),
        '平均饮食得分': x['diet_score'].mean(),
        '平均压力水平': x['stress_level'].mean(),
        '高血压比例': (x['blood_pressure_high'] > 140).sum() / len(x) * 100,
        '肥胖比例': (x['bmi'] > 28).sum() / len(x) * 100
    }).to_dict()
    health_recommendations = {}
    for cluster_name in cluster_names.values():
        cluster_data = health_pandas[health_pandas['cluster_name'] == cluster_name]
        recommendations = []
        if cluster_data['exercise_frequency'].mean() < 3:
            recommendations.append('建议增加运动频率至每周3-4次')
        if cluster_data['sleep_hours'].mean() < 7:
            recommendations.append('建议保证每日7-8小时充足睡眠')
        if cluster_data['diet_score'].mean() < 7:
            recommendations.append('建议改善饮食结构,增加蔬果摄入')
        if cluster_data['stress_level'].mean() > 6:
            recommendations.append('建议学习压力管理技巧,适当放松')
        health_recommendations[cluster_name] = recommendations
    return {
        'cluster_analysis': cluster_analysis.to_dict(),
        'demographic_analysis': demographic_analysis.to_dict('records'),
        'lifestyle_patterns': lifestyle_patterns,
        'health_recommendations': health_recommendations,
        'cluster_distribution': health_pandas['cluster_name'].value_counts().to_dict()
    }

def lifestyle_impact_analysis(lifestyle_factor):
    """生活方式影响分析核心功能"""
    health_df = spark.sql("""
        SELECT user_id, age, gender, bmi, blood_pressure_high, heart_rate, 
               sleep_hours, exercise_frequency, diet_score, stress_level,
               smoking_status, drinking_status, work_hours FROM health_data 
        WHERE status = 1
    """)
    health_pandas = health_df.toPandas()
    impact_results = {}
    if lifestyle_factor == 'exercise':
        health_pandas['exercise_group'] = pd.cut(health_pandas['exercise_frequency'], bins=[0, 1, 3, 5, 10], labels=['很少运动', '偶尔运动', '适量运动', '频繁运动'])
        exercise_impact = health_pandas.groupby('exercise_group').agg({
            'bmi': ['mean', 'std'],
            'blood_pressure_high': ['mean', 'std'],
            'heart_rate': ['mean', 'std'],
            'stress_level': ['mean', 'std']
        }).round(2)
        exercise_health_rate = health_pandas.groupby('exercise_group').apply(lambda x: {
            '正常血压比例': (x['blood_pressure_high'] <= 120).sum() / len(x) * 100,
            '正常BMI比例': ((x['bmi'] >= 18.5) & (x['bmi'] <= 24.9)).sum() / len(x) * 100,
            '低压力比例': (x['stress_level'] <= 5).sum() / len(x) * 100
        }).to_dict()
        impact_results = {'exercise_impact': exercise_impact.to_dict(), 'exercise_health_rate': exercise_health_rate}
    elif lifestyle_factor == 'sleep':
        health_pandas['sleep_group'] = pd.cut(health_pandas['sleep_hours'], bins=[0, 6, 8, 10, 24], labels=['睡眠不足', '正常睡眠', '充足睡眠', '过度睡眠'])
        sleep_impact = health_pandas.groupby('sleep_group').agg({
            'bmi': ['mean', 'std'],
            'stress_level': ['mean', 'std'],
            'heart_rate': ['mean', 'std'],
            'diet_score': ['mean', 'std']
        }).round(2)
        sleep_correlation = health_pandas[['sleep_hours', 'stress_level', 'bmi', 'heart_rate', 'diet_score']].corr()['sleep_hours'].to_dict()
        impact_results = {'sleep_impact': sleep_impact.to_dict(), 'sleep_correlation': sleep_correlation}
    elif lifestyle_factor == 'diet':
        health_pandas['diet_group'] = pd.cut(health_pandas['diet_score'], bins=[0, 5, 7, 9, 10], labels=['不良饮食', '一般饮食', '良好饮食', '优秀饮食'])
        diet_impact = health_pandas.groupby('diet_group').agg({
            'bmi': ['mean', 'std'],
            'blood_pressure_high': ['mean', 'std'],
            'stress_level': ['mean', 'std']
        }).round(2)
        diet_health_outcomes = health_pandas.groupby('diet_group').apply(lambda x: {
            '健康体重比例': ((x['bmi'] >= 18.5) & (x['bmi'] <= 24.9)).sum() / len(x) * 100,
            '正常血压比例': (x['blood_pressure_high'] <= 120).sum() / len(x) * 100
        }).to_dict()
        impact_results = {'diet_impact': diet_impact.to_dict(), 'diet_health_outcomes': diet_health_outcomes}
    lifestyle_recommendations = generate_lifestyle_recommendations(health_pandas, lifestyle_factor)
    trend_analysis = analyze_lifestyle_trends(health_pandas, lifestyle_factor)
    return {
        'impact_analysis': impact_results,
        'recommendations': lifestyle_recommendations,
        'trend_analysis': trend_analysis
    }

def generate_lifestyle_recommendations(data, factor):
    recommendations = {}
    if factor == 'exercise':
        low_exercise = data[data['exercise_frequency'] <= 1]
        if len(low_exercise) > 0:
            recommendations['低运动人群'] = '建议每周至少进行150分钟中等强度运动'
    elif factor == 'sleep':
        poor_sleep = data[data['sleep_hours'] < 7]
        if len(poor_sleep) > 0:
            recommendations['睡眠不足人群'] = '建议建立规律作息,保证7-9小时睡眠'
    return recommendations

def analyze_lifestyle_trends(data, factor):
    trends = {}
    if factor == 'exercise':
        trends['运动频率分布'] = data['exercise_frequency'].value_counts().to_dict()
    elif factor == 'sleep':
        trends['睡眠时长分布'] = data.groupby(pd.cut(data['sleep_hours'], bins=5))['user_id'].count().to_dict()
    return trends

基于大数据的人类健康生活方式数据分析系统文档展示

在这里插入图片描述

💖💖作者:计算机毕业设计杰瑞 💙💙个人简介:曾长期从事计算机专业培训教学,本人也热爱上课教学,语言擅长Java、微信小程序、Python、Golang、安卓Android等,开发项目包括大数据、深度学习、网站、小程序、安卓、算法。平常会做一些项目定制化开发、代码讲解、答辩教学、文档编写、也懂一些降重方面的技巧。平常喜欢分享一些自己开发中遇到的问题的解决办法,也喜欢交流技术,大家有技术代码这一块的问题可以问我! 💛💛想说的话:感谢大家的关注与支持! 💜💜 网站实战项目 安卓/小程序实战项目 大数据实战项目 深度学校实战项目 计算机毕业设计选题推荐