Machine learning is being used in almost everything we use today. From Netflix recommendations to Nest devices that predict and change the temperature of your home, it's pretty incredible how we're applying the technology in a diverse manner.
I wanted to build something for the Phillips Hue that would learn my usage patterns and make predictions based on the observed behavior.
Hubert is a machine-learning application that records, learns, and predicts your light usage patterns. Over time, Hubert will make predictions on the current light states and change any non-regular lights automatically. This can be especially useful when you've left to walk the dog but forgot to shut off the lights. Hubert can even learn when you arrive back home and start to make these changes for you automatically.
Hubert is built and run using Docker. A series of containers are run in parallel to analyze, record, learn, and make changes to your light usage patterns.
There are four main Docker images that make up Hubert.
hubert- The main processor; Sends updates to Cassandra container; Processes RabbitMQ messages to alter the state of the lights
learn- Machine learning algorithm; Learns from usage and sends messages to RabbitMQ for processing
rabbitmq- A RabbitMQ instance used for publish-subscribe
cassandra- A Cassandra instance used for data collection
First, we need a way to log and store behavior of the lights. The Hue Bridge provides us with a robust API that we can use to fetch information about the state of our lights such as
reachable, and so much more. Almost all of this information is important to us and so we record it to a Cassandra database every 10 seconds via a daemon written in Node.js.
Rather than stick to one language that could do this job fairly well, Hubert uses proven tools such as Python and scikit-learn to build a ridge regression model that can predict future states of our lights.
The first few weeks of data collection are to train the ridge regression model. Hubert does not start altering the state of your lights until enough data has been collected and the mean squared error is within an acceptable limit.
Hubert's algorithm is simple in that it loops over a range of polynomials (0-9)
and a range of alphas (
0.0, 1e-8, 1e-5, 1e-1) to determine the fit that
best minimizes the test error. There are plans to implement k-fold
cross-validation or something similar to best fit smaller amounts of data.
Hubert's machine-learning algorithm will alter the state of your Hue lights if:
When both of these conditions are met, the
learn image will send a message via RabbitMQ. The
hubert image in turn picks up this message and updates the Hue lights via the API.
You can find all the source for Hubert on Github
Found Hubert to be useful? Please let me know!