Apple NACME AIML Intensive β’ iOS + ML β’ Health
Assuage: ML Distress Prediction
Built a logistic regression model to predict distress levels from HealthKit biometrics, achieving 82% test accuracy. Implemented on-device inference in Swift using Core ML for privacy-preserving health monitoring.
Accuracy
82% test accuracy
Deployment
Core ML on-device
Platform
iOS + HealthKit
Problem
Early detection of distress or health issues can help individuals take proactive measures. However, collecting and analyzing health data while maintaining privacy is challenging. This project aimed to create a privacy-preserving solution that uses on-device machine learning to predict distress levels from readily available HealthKit biometrics.
Approach
- Data Collection: Used HealthKit biometrics (heart rate, steps, sleep, etc.) as features
- Data Augmentation: Created pseudo-data to address limited training data availability
- Model Development: Trained logistic regression model using scikit-learn in Python
- Feature Engineering: Explored and engineered features from HealthKit data
- Model Evaluation: Achieved 82% test accuracy with proper train/test split
- iOS Integration: Converted model to Core ML format for on-device inference
- Privacy: All processing happens on-deviceβno data leaves the user's phone
Technical Implementation
# Python: Model training
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
# Feature engineering from HealthKit data
features = ['heart_rate', 'steps', 'sleep_hours', 'active_energy']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
# Train model
model = LogisticRegression()
model.fit(X_train, y_train)
# Evaluate
accuracy = accuracy_score(y_test, model.predict(X_test))
# Result: 82% accuracy
# Convert to Core ML
import coremltools as ct
coreml_model = ct.converters.sklearn.convert(model)
coreml_model.save('DistressPredictor.mlmodel')
// Swift: On-device inference
import CoreML
import HealthKit
let model = try DistressPredictor(configuration: .init())
let input = DistressPredictorInput(
heartRate: currentHeartRate,
steps: todaySteps,
sleepHours: lastNightSleep,
activeEnergy: todayActiveEnergy
)
let prediction = try model.prediction(from: input)
let distressLevel = prediction.distressLevel
Results
- Model Performance: Achieved 82% test accuracy in predicting distress levels
- Privacy: Complete on-device processing ensures user data never leaves their device
- User Experience: Seamless integration with HealthKit for automatic data collection
- Deployment: Successfully converted model to Core ML for iOS deployment
- Scalability: Model can be updated and improved as more data becomes available
Technologies Used
Impact
This project demonstrates how machine learning can be applied to health monitoring in a privacy-preserving way. By using on-device inference, users can benefit from ML-powered insights without compromising their privacy. The approach can be extended to other health prediction tasks and integrated into health monitoring apps.