AI-Powered Health Recommendations Based on Data
Most health apps show data. User sees 7,340 steps and closes the app. Recommendation system changes this: instead of "here's your data"—"here's what it means for you today".
Recommendation System Architecture
Personalized health recommendations—not a single ML algorithm. Pipeline of several layers:
- Data collection—activity (steps, workouts), sleep, nutrition, biometrics (HR, SpO2, weight)
- User profile—age, goals, baseline metrics, behavior patterns
- Feature engineering—aggregation into meaningful metrics
- Recommendation model—rule engine + ML ranking
- Display—specific, relevant, at right moment
Data: HealthKit as Single Point on iOS
class HealthDataAggregator {
private let store = HKHealthStore()
func weeklyStats() async throws -> HealthWeekSnapshot {
async let steps = fetchSum(.stepCount, days: 7)
async let sleepHours = fetchCategorySamples(.sleepAnalysis, days: 7)
async let restingHR = fetchAverage(.restingHeartRate, days: 7)
async let activeEnergy = fetchSum(.activeEnergyBurned, days: 7)
return try await HealthWeekSnapshot(
avgDailySteps: steps / 7,
avgSleepHours: sleepHours,
avgRestingHR: restingHR,
totalActiveKcal: activeEnergy
)
}
}
On Android—Health Connect SDK (HealthConnectClient) with similar data types. HealthConnectClient.readRecords(StepsRecord::class)—steps query for period.
Rule Engine as Recommendation Base
Rule-based approach—not outdated, but practical. Rules transparent, testable, don't require large training dataset. ML on top adds personalization in ranking.
Example rule structure:
struct HealthRule {
let id: String
let condition: (HealthWeekSnapshot) -> Bool
let recommendation: Recommendation
let priority: Int
}
let rules: [HealthRule] = [
HealthRule(
id: "low_sleep",
condition: { $0.avgSleepHours < 6.5 },
recommendation: Recommendation(
title: "Insufficient sleep reduces recovery",
body: "Average sleep this week—\($0.avgSleepHours.formatted(.number.precision(.fractionLength(1)))) hours. Try 30 min earlier for 3 days.",
category: .sleep,
urgency: .medium
),
priority: 8
),
HealthRule(
id: "elevated_resting_hr",
condition: { snapshot in
guard let hr = snapshot.avgRestingHR else { return false }
return hr > 80 && snapshot.avgSleepHours < 7
},
recommendation: ...,
priority: 9
)
]
Combined conditions important: "resting HR 85 bpm" alone might be normal for someone, but combined with poor sleep—overtraining or stress marker.
ML Layer: Ranking and Personalization
Rule engine generates candidate list—recommendations matching conditions. Then ML ranks by user execution probability.
Use collaborative filtering or simple gradient boosting on user + recommendation features:
- Historical CTR of this recommendation type for user
- Day-of-week pattern (user more active weekends—activity recommendations more relevant Friday)
- Streak: user followed recommendation 5 days—boost next recommendation priority
Train on implicit feedback: recommendation shown → user opened → executed (HealthKit data) / ignored.
Timing and Push Notifications
Right moment more important than right content. "Go to bed early" at 8 PM works. At 11:30 PM—doesn't.
func scheduleRecommendation(_ rec: Recommendation) {
let content = UNMutableNotificationContent()
content.title = rec.title
content.body = rec.shortBody
content.sound = .default
let bestTime = optimalDeliveryTime(for: rec, userSchedule: userProfile.typicalSchedule)
let trigger = UNCalendarNotificationTrigger(
dateMatching: Calendar.current.dateComponents([.hour, .minute], from: bestTime),
repeats: false
)
let request = UNNotificationRequest(identifier: rec.id, content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request)
}
optimalDeliveryTime—logic based on user patterns: when they typically open app, bedtime (from HealthKit sleep data), workout times.
What Makes Recommendations Work
One specific recommendation daily better than five generic ones. "Walk 2,000 steps today by 6 PM, you're at 1,200"—works. "Move more"—doesn't.
Tie to real-time context: if CMMotionActivityManager shows user walking—don't suggest activity recommendation. Don't irritate.
Development Process
Define data sources and user model schema. Develop rules (15–30 initial set). Implement HealthKit / Health Connect aggregation pipeline. Train ranking model (need data—or synthetic, or pre-launch beta). Delivery system: in-app and push with optimal timing. A/B test effectiveness.
Timeframe Estimates
Rule-based system with basic recommendation set and HealthKit integration—1–2 weeks. Complete personalized system with ML ranking and optimal timing—3–5 weeks.







