lamps-1798692_1920

Create your DIY remote for Philips Hue with Raspberry Pi

You know those Philips Hue lights, which are amazing and really cool gadgets for your house? Well, thanks to Philips it is also easy to create your very own DIY remote control for them. Yes, of course you can get a remote for these lights in the shop as well, but why would you if you can program one yourself?!

To do this I’ve used my Raspberry Pi 2 model B, and from my Arduino Starter Kit I’ve used a breadboard, a remote control and an IR (infrared) receiver. I’ve named my remote control “SpecialForMP3”, since this is the only text I could find on it. But you can use any infrared remote control you want, so if you have some useless remote controls lying around, just give them a purpose again.

RemoteControl_IRreceiver

First, we need to setup the Raspberry Pi to be able to receive infrared signals sent by the remote control. Furthermore, we have to make sure the Raspberry Pi can not only receive the signals, but is also capable of deciphering them. In other words, we want to make sure the Raspberry Pi can “hear” the remote control and is also capable of understanding what is said; they need to speak the same language.

The first step towards achieving this goal, is connecting the IR receiver to the Raspberry Pi. After we’ve done this we can start with setting up the LIRC (Linux Infrared Remote Control) package on the Raspberry Pi. LIRC is a package that allows you to decode and send infrared signals of many (but not all) commonly used remote controls. To setup both the IR receiver and LIRC, you can follow the steps as described here. You can find the resulting LIRC configuration file on GitHub, together with the rest of the code needed to finish this project.

When finished, my setup looks like this:
20170827_161012 20170827_160940

As a side note, I had some troubles using mode2 -d /dev/lirc0, after pushing a button on my remote instead of seeing something like the example I got the message “Partial read 8 bytes” and then it just stopped. After changing the driver from devinput to default in lirc_options.conf this issue was fixed.

When you find yourself having no permission to change files, look at the chmod 777 option, this makes sure everybody has read-write-execute permissions on the specified files and/or folders.

Now we’re ready for installing Python packages that make it possible to use LIRC and connect to the Philips Hue Bridge which controls the lights:

  • sudo pip install phue
  • sudo apt-get install python-lirc

We get started by connecting the Philips Hue Bridge through a Python script, this can easily be done by using it’s IP address. You can find out what the correct IP address is in multiple ways, an easy one is using the (official) Philips Hue app:

  • Go to the settings menu in the Philips Hue app and go to My Bridge, click on Network settings and switch off the DHCP toggle; the IP address of the bridge will show.

The next thing we need to do is connect to the Philips Hue Bridge and determine the names of the available lights and light groups.

# import the necessary packages
from phue import Bridge
# identify the bridge
b = Bridge(‘192.168.1.128’)
# connect to the bridge (first press button on bridge)
# this only has to be done the first time you setup the connection
b.connect()
# get the names of all the lights
print b.get_light_objects(‘name’)
# get the names of the light groups
print b.get_group()

 In order to change the colour of a light, we need to know the XY code of this colour. Since we’re more familiar with using RGB codes for colour, we can use this function to convert RGB to XY.

Finally, we can connect to the LIRC and create the loop in which we will change the colour of the lights. In my case I have the following lights available: Zithoek, Zithoek bloom, Raamkant, Midden, Keukenkant, Slaapkamer. And I have the following light groups available:  Zithoek, Eetkamer, Slaapkamer. You can find the complete script to use the remote to control the Philips Hue Lights on GitHub as well, this script connects to the Philips Hue Bridge and to LIRC and has ten different scenes for the lights, but you can of course adapt this to your own needs and wishes.

Good luck and enjoy!

pexels-photo-324028

Project Friday 1.5: AI & Coffee – When you flip your coffee machine the finger

Everybody has those mornings when your mood is not as wonderful as always and your energy levels seem to be lagging, especially before you had your coffee. Those mornings when you just want to flip the finger to everything and everyone and tell the world to fuck off. When “working” on our A.I. coffee machine, we recognized this feeling and felt that it’s our duty to take this feeling seriously.

So, here’s what we did, we trained our coffee machine to recognize when someone flips it the finger. Thomas spend the entire afternoon collecting training data, meaning that he was just flipping the finger to his computer and looking for YouTube clips where people flip the finger. Which is why I quoted “working” in the first paragraph. In the picture below you’ll see some of our training data.

middlefingers

And the results after two days of training:

middlefinger

When it spots the middle finger, it serves a double shot of espresso. Now, we’re not claiming that it fixes your mood entirely, but sure as hell makes it a bit better!

Last session we’ve had our dr. Frankenstein moment, it was working. It was however on a dry run, we saw the buttons worked, but didn’t connect the coffee machine to the water. This time we did, apparently there’s still a little bug, as it decided to serve a cappuccino every 20 seconds.

question-mark-2492009_1920

Model in één middag in de praktijk

Ken je dat? Dat je eigenlijk gewoon eens wilt weten of de data die je hebt, geschikt is voor het voorspellen van bepaald gedrag van je klanten? Maar dat je geen tools tot je beschikking hebt en ook niet zo goed weet waar te beginnen…

Een klant van ons constateerde dat er omzet potentie bleef liggen door de foutieve inschatting van potentiële klantwaarde van prospects. De potentiële klantwaarde werd bepaald door naar enkele generieke kenmerken van prospects te kijken en op basis daarvan een schatting te maken. Dat de schatting van de klantwaarde niet goed (genoeg) was werd door de accountmanagers geconstateerd doordat zij (gedeeltelijk) de verkeerde prospects benaderden. Daarnaast bleek uit de evaluaties van campagnes voor lage klantwaarde prospects dat hier toch wel aardig wat hoge klantwaarde klanten tussen zaten. Hoog tijd voor verbetering dus. Voor dit probleem is een Business Case opgesteld met meerdere scenario’s; de potentie van deze Business Case lag tussen de vijfhonderdduizend en 2,5 miljoen euro.

Naast het helpen van de klant met de opzet voor deze Business Case, hebben we ook nog een aantal kwalitatieve aspecten meegenomen: we hebben een medewerker meegenomen in een aantal methoden en technieken voor data analytics en hem de grondbeginselen van R geleerd. Daarmee hebben we meteen input geleverd voor een grotere Business Case voor de uitfasering van SPSS naar R. Nadat we hier samen met de klant mee aan de slag zijn gegaan, hebben we binnen vijf dagen een eerste model op kunnen leveren, waarvan de toegevoegde waarde op dit moment getest wordt in een pilotproject.

Nou hoor ik je denken “jullie hebben toch een model in één middag, waarom heeft dit dan vijf dagen moeten duren?”. Een terechte vraag uiteraard. De extra tijd die we hierin hebben gestoken, hing vooral samen met het meenemen van de medewerker in de basics van data analytics en R. Zo kon hij meteen ruiken aan dit vakgebied en op basis daarvan (beter) bepalen of hij het leuk zou vinden om zich meer in die richting te ontwikkelen. Wat ons betreft niet alleen een interessant en leuk traject, maar vooral ook bijzonder nuttig en voor herhaling vatbaar!

Heb jij interesse, of loop je ook al tijden met een dergelijke kwestie? Schroom dan vooral niet om contact met ons op te nemen!

 

pexels-photo-324028

Project Friday 1.4: A.I. & Coffee – It’s Alive!

It’s raining cats and dogs, the fridge is stuffed with cold beers and the Spotfiy playlist Coffee House is blasting through the office. In other words, a perfect time to work on our coffee machine with face recognition capabilities. And today we had our own dr. Frankenstein moment. It’s alive and it works!

Last Christmas, everyone at Cmotions was photographed professionally. These photos are the input for the face recognition algorithm. We started out by using the face recognition package in python, which detects key facial points (edges of eyes, nose, mouth, etc.) and estimates the distances between those points. The algorithm was way too slow, so we used face detection first. Using pretrained Haar Cascades, we first extract a face from a picture and that pass to the recognition algorithm. Next step will be to train our own recognition algorithm and to implement some easter eggs, like when you flip the finger, it give you a double shot of espresso. Or trying to identify your facial expressions and when you’re angry it brews your coffee extra strong. If you got any ideas, let us know!

20170714_152046

As stated in earlier articles, we do this for the fun of it and to learn new stuff.

Pandas, does that make the picture black and white? – Joost

One of the things we had to learn about is electrical engineering. At Cmotions, we know data and how to use it in order to retrieve information out of it (like extracting faces from a bunch of pixels in a photo). The soldering part and especially figuring out on to which point we needed to solder took some trial and error. See part one here, where a colleague short circuited the Arduino within ten minutes. The first Frankenstein moment was when we we’re able to say, with Python, that we wanted a coffee and it actually makes a cup of coffee.

The second Eureka moment was when we integrated this with the Face Recognition scripts on the Raspberry PI. It’s Alive! And how do we know it’s working? Well, after testing it on our faces, we came up we the (quite brilliant) idea of showing Facebook photos of colleagues.

20170714_180006

 

pexels-photo-296888

Project Friday 1.3: Artificial Intelligence meets coffee

Last Friday the third afternoon of Project Friday took place. In Project Friday we spent about once a month  an afternoon on something completely useless. Why do we do this? Because we can, it’s fun and interesting and it’s a good reason to grab a couple of beers. This Project Friday is all about mixing Espresso Machines with Artificial Intelligence: adding facial recognition to the machine so that you don’t need to push the button to get your favorite coffee.

In the previous afternoons (day 1 and day 2), we’ve installed everything on the Raspberry PI (which was quite a hassle), learned what relays were and how to use them, soldered the first buttons and were able to control these buttons via the computer. This Friday we set ourselves the goal to real time face detection on the PI cam.

As the weather was warm and sunny, we decided it was better to leave the office and reach our goal in a more suitable environment, somewhere we the Raspberry PI (and us) wouldn’t overheat. So we drove to my place and settled ourselves in the garden, brought a television outside, hooked up the Raspberry PI and off coding we went. An additional benefit was the BBQ!

Astonishingly enough, not only the Raspberry PI had trouble with the warm weather, so did your cognitive capabilities. The move didn’t make us more productive (but was still the right choice with this kind of weather). So progress was slow, and we were on half the strength as three team members were on holiday. We did had some success, we did manage to implement the pre-trained HAAR-cascades for detecting faces and our trained cascade for detecting your middle finger when you flip it. But didn’t get so far to get default face recognition in place. So we’ll leave that for the next afternoon!

20170526_170709 20170526_161358

pexels-photo-296888

Project Friday 1.2: Artificial Intelligence meets coffee

A month ago we started with ‘Project Friday’; once a month we’ll lock some collegues in a room with a couple of beers and a fun project. This project: give a coffeemachine a brain and an eye, so it can see who’s standing in front of the machine and knows what he/she wants. Why do we do this? Well, because it’s fun.

This friday we made some significant progress, first of all we didn’t short circuit the arduino board, which we accomplished in the first ten minutes the previous time. We managed to reverse engineer some of the buttons of the circuitboard of the coffee machine and after learning about the transistors and relays, we managed to “push” a few of the buttons of the machine using the arduino. We bought a cheap solder around the corner of the office and soldered the first three buttons.

Meanwhile, on the Raspberry we succeeded extracting faces from the images using HAAR cascades, when multiple faces are detected it selects the biggest one. Face Recognition consists of two parts: detection (where in image / frame is a face) and recognition (to whom belongs that face). The first part works, for the second part we had some trouble installing libraries, apparently this takes a long time!

Next time, we’re going to solder the rest of the buttons and program the arduino, create trainingsdata by taking pictures of ourselves and try to train the first algorithms.

IMG_20170414_175446 IMG_20170414_164921 IMG_20170414_145149

IMG_20170313_180058

R Experience @ University of Groningen

This Monday was the last day of the R Experience course at the University of Groningen. Since this year Marketing (Intelligence) students are required to use R for assignments, where they’ve only worked with SPSS before. To kickstart their learning curve in R, we lectured the R Experience, in cooperation with the MARUG (Marketing Association at University of Groningen).

The course is intended for analysts who already know the statistics and modelling theories and principles. The goal of the course is to learn how to do this in R, instead of using tools like SPSS or SAS. In five sessions, we showed how to work with Rstudio and how to write code.

They should make this course mandatory for the study Marketing Intelligence

The first module started with an entry level introduction to writing code. In the following module we’ve touched how Rstudio works, how to import data and how to use functions. In the next modules data manipulation and preparation (like missing values, outliers, correlations and near zero variance) were discussed. In the last sessions we showed how to use the caret package to train lots of different kind of models with minor changes in code.

Very clear explanation and definitely added value for every Marketing Intelligence Student

We were amazed by the enthusiasm of the group, students were on Facebook, but instead of looking at their timeline, they used it to send code to each other via Messenger. Also reactions in the feedback forms were very positive, with an average grade of 8.5/10 and no one who wouldn’t recommend the course to fellow students, we consider the course as a great success. Next year, we’ll definitely do this again!

Hackathon_051

Tweede Kamer Verkiezingen Hackathon – The Aftermovie!

Op vrijdag 10 maart jl. heeft de tweede “The Analytics Lab Hackathon” plaatsgevonden, de opdracht was dit keer om de zetelverdeling te voorspellen van de Tweede Kamer na de verkiezingen van 15 maart.Hackathon_033

Dankzij de serieuze, sportieve en ook humoristische inzet van onze deelnemende teams is het weer een zeer leuke dag geweest, waarbij iedereen wilde winnen, maar het toch vooral ging om het meedoen. We willen alle deelnemers dan ook bedanken voor hun aanwezigheid en bijdrage aan deze leuke dag!

Winnaar Hackathon Verkiezingen

 

Nadat donderdagochtend de voorlopige uitslag bekend werd gemaakt van de verkiezingen, konden wij het team van de ANWB als winnaar aanwijzen, op de voet gevolgd door het Essent – Vrouwen Voor Data team. De ANWB kon er met de prijs vandoor gaan door een RMSE (root mean square error) te behalen van slechts 5,29.

Wat ons betreft: op naar volgend jaar, op naar de volgende hackathon!

pexels-photo-296888

Project Friday 1.1: Artificial Intelligence meets coffee

This Friday we started with our first ‘Project Friday’. About once a month, on a Friday, we’ll lock ourselves away for the afternoon with a couple of beers and a fun project. The project doesn’t need to bring money to table, it needs to bring fun, challenges, knowledge and inspiration to the table.

Our first project is definitely an awesome one; Artificial Intelligence meets Coffee! Douwe Egberts was kind enough to provide us with a full automatic coffee machine, well almost full automatic, you still need to push the button to let the machine know whether you want a normal coffee, a cappuccino, an espresso or whatever grinds your gears. Our objective: create an actual full automatic coffee machine. The goal is to add face recognition to the coffee machine: Stand in front of the machine, the machine recognizes who you are and knows which coffee you want.

We started by prepping a Raspberry Pi and installing OpenCV. Dismantling the machine and figuring out how circuit board works using the well proven method of trial and error. Since we’re not engineers, the biggest challenge is probably going to be to hack the coffee machine: within 15 minutes, one colleague managed to short circuit the Arduino board. Great start!

 

PF1.1

 

PF 1.0

494345930

Python & R vs. SPSS & SAS

When we’re working for clients we mostly come across the statistical programming languages SAS, SPSS, R and Python. Of these SAS and SPSS are probably the most used. However, the interest for the open source languages R and Python is increasing. In recent years, some of our clients migrated from using SAS or SPSS to using R and/or Python. And even if they haven’t (yet), most commercial software packages (including SAS and SPSS) make it possible to connect to R and Python nowadays.

SAS was developed at the North Carolina State University and was primarily developed to be able to analyse large quantities of agriculture data. The abbreviation SAS stands for Statistical Analysis System. In 1976 the company SAS was founded as the demand for such software increased. Statistical Package for the Social Sciences (SPSS) was developed for the social sciences and was the first statistical programming language for the PC. It was developed in 1968 at the Stanford University and eight years later the company SPSS Inc. was founded, which was bought by IBM in 2009.

In 2000 the University of Auckland released the first version of R, a programming language primarily focused on statistical modeling and was open sourced under the GNU license. Python is the only one that was not developed at a university. Python was created by a Dutch guy who is a big fan of Monty Python (where the name comes from). He needed a project during Christmas and created this language which is based on ABC. ABC is a language, also created by him, with the goal to teach non-programmers how to program. Python is a multi-purpose language, like C++ and Java, with the big difference and advantage that Python is way easier to learn. Programmers carried on and created lots of modules on top of Python and it therefore has a wide range of statistical modeling capabilities nowadays. That’s why Python definitely belongs in this list.

In this article, we compare the four languages on methods and techniques, ease of learning, visualisation, support and costs. We explicitly focus on the languages, the user interfaces SAS Enterprise Miner and SPSS Modeler are out of scope.

table

Statistical methods and Techniques

My vision on Data Analysis is that there is continuum between explanatory models on one side and predictive models on the other side. The decisions you make during the modeling process depend on your goal. Let’s take Customer Churn as an example, you can ask yourself why are customers leaving? Or you can ask yourself which customers are leaving? The first question has as its primary goal to explain churn, while the second question has as its primary goal to predict churn. These are two fundamentally different questions and this has implications for the decisions you take along the way. The predictive side of Data Analysis is closely related to terms like Data Mining and Machine Learning.

When we’re looking at SPSS and SAS, both of these languages originate from the explanatory side of Data Analysis. They are developed in an academic environment, where hypotheses testing plays a major role. This makes that they have significant less methods and techniques in comparison to R and Python. Nowadays, SAS and SPSS both have data mining tools (SAS Enterprise Miner and SPSS Modeler), however these are different tools and you’ll need extra licenses.

One of the major advantages of open source tooling is that the community continuously improves and increases functionality. R was created by academics, who wanted their algorithms to spread as easily as possible. Ergo R has the widest range of algorithms, which makes R strong on the explanatory side and on the predictive side of Data Analysis.

Python is developed with a strong focus on (business) applications, not from an academic or statistical standpoint. This makes Python very powerful when algorithms are directly used in applications. Hence, we see that the statistical capabilities are primarily focused on the predictive side. Python is mostly used in Data Mining or Machine Learning applications where a data analyst doesn’t need to intervene. Python is therefore also strong in analysing images and videos, for example we’ve used Python this summer to build our own autonomous driving RC car. Python is also the easiest language to use when using Big Data Frameworks like Spark.

Ease of learning

Both SPSS and SAS have a comprehensive user interface, with the consequence that a user doesn’t necessarily need to code. Furthermore, SPSS has a paste-function which creates syntaxes from steps executed in the user interface and SAS has Proc SQL, which makes SAS-coding a lot easier for people who know the SQL query language. SAS and SPSS code are syntaxtically far from similar to each other and also very different from other relevant programming languages, so when you need to learn one of these from scratch, good luck with it!

Although there are GUI alternatives for R, like Rattle, it doesn’t come close to SAS or SPSS in terms of its functionality. R is easily to learn for programmers, however, a lot of analysts don’t have a background in programming. R has the steepest learning curve from all, it’s the most difficult one to start with. But once you get the basics, it gets easier soon. For this specific reason, we’ve created a R course, called Experience R, which kickstarts (aspiring) data analysts / scientists in learning R. Python is based on ABC, which is developed with the sole purpose of teaching non-programmers how to program. Readability is one of the key features of Python. This makes Python the easiest language to learn. As Python is so broad, there are no GUI’s for Python.

To conclude, as for ease of learning SPSS and SAS are the best option for starting analysts as they provide tools where the user doesn’t need to program.

Support

Both SAS and SPSS are commercial products and therefore have official support. This motivates some companies to choose for these languages: if something goes wrong, they’ve got support.

There is a misconception around the support for open-source tooling. It’s true that there is no official support from the creators or owners, nonetheless, there’s a large community for both languages most willing to help you to solve your problem. And 99 out of 100 times (if not more often), your question has already been asked and answered on sites like Stack Overflow. On top of that, there are numerous companies that do provide professional support for R and Python. So, although there’s no official support for both R and Python, in practice we see that if you’ve got a question, you’ll likely have your answer sooner if it’s about R or Python than in case it’s SAS or SPSS related.

Visualisation

The graphical capabilities of SAS and SPSS are purely functional; although it is possible to make minor changes to graphs, to fully customize your plots and visualizations in SAS and SPSS can be very cumbersome or even impossible. R and Python offer much more opportunities to customize and optimize your graphs due to the wide range of modules that are available. The most widely used module for R is ggplot2, which has a wide set of graphs where you’re able to adjust practically everything. These graphs are also easily made interactive, which allows users to play with the data through applications like shiny.

Python and R learned (and still learn) a lot from each other. One of the best examples of this is that Python also has a ggplot-module , which has practically the same functionality and syntax as it does in R. Another widely used module for visualisation in Python is Matplotlib.

Costs

R and Python are open source, which makes them freely available for everybody. The downside is that, as we’ve discussed before, these are harder to learn languages compared to start using the SAS or SPSS GUI. As a result, analysts equipped with R and/or Python in their skillset have higher salaries than analyst that don’t. Educating employees that are currently not familiar with R and/or Python costs money as well. Therefore, in practice it isn’t the case that the open source programming language are completely free of costs, but when you compare it with the license fees for SAS or SPSS, the business case is very easily made: R and Python are way cheaper!

My choice

“Software is like sex, it’s better when it’s free” – Linus Torvalds (creator Linux)

My go-to tools are R and Python, I can use these languages everywhere without having to buy licenses. Also I don’t need to wait for the licenses. And time is a key feature in my job as a consultant. Aside from licenses, probably the main reason is the wide range of statistical methods; I can use any algorithm out there and choose the one that suits the challenge at hand best.

Which of the two languages I use depends on the goal, as mentioned above. Python is a multi-purpose language and is developed with a strong focus on applications. Python is therefore strong in Machine Learning applications; hence I use Python for example for Face or Object Recognition or Deep Learning applications. I use R for goals which have to do with customer behaviour, where the explanatory side also plays a major role; if I know which customers are about to churn, I would also like to know why.

These two languages are for a large part complementary. There are libraries for R that allow you to run Python code (reticulate, rPython), and there are Python modules which allow you to run R code (rpy2). This makes the combination of the two languages even stronger.


Jeroen Kromme, Senior Consultant Data Scientist