 Good afternoon, everyone. It's my pleasure to introduce Javier Arias, who's a senior developer at Telefonica in Barcelona here in Spain, and he's going to be talking about machine learning for the means using Python, of course. Do you hear me well? They're in the back. Yeah, it's okay. Okay, if not, please let me know because if I lower my voice, let me let me check back of the context of the photos because please... It's also for my mama. This could be a day in your life. This could be today. It's about time to leave the office and your phone tells you the best route to go home. It's fine because you never told your phone where home is or what's the appropriate time to leave the office. In fact, on Fridays, the phone will tell you the best route to your parents' home because on Fridays, you visit your parents. So you go to a parking and you happen to be a happiest loner. Not that everybody of us can be it, but let's imagine for a minute. In the in the largest version of the firmware card, there is an autopilot feature. Without a pilot, the car is able to keep the lane by moving the steering wheel, keep the speed and the distance with the rest of the cars. And not only that, the car is able to learn not only from its own experiences, but from experiences from the Teslas from around the world. So you get home and you want to play some music. But you don't feel like choosing any music. So you trust on Spotify to play some music for you that you don't know. But you actually know, like, when listening to the music, you check your photos, which are very well organized in categories like here with architecture and arts. But you never tag them. It was Flickr that is able to look inside your photos and see what's inside and tag them accordingly. These things are happening daily to thousands or even millions of people from around the world and all of them have something in common. Do you know what it is? It's machine learning. Machine learning is already in your life. It's everyone around us and it will be very important in the next years. So what's this presentation about? I'll try to explain a little bit why machine learning is so important for us as users, as engineers and for companies and for the rest of the world. Also I'll try to explain about my journey with machine learning. My name is Javed Arias and I am a backend engineer. Six months ago I didn't know anything about machine learning and I'm not an expert. It would need years of study and practice to do so. But you can get started pretty quick and do very interesting and funny things because there are many technologies and many resources around that are free, that are open source and of course using Python and libraries with Python. And also I'll try to explain some very basic machine learning concepts and we'll see a couple of code samples. So as many of you know, machine learning will be very important during the next years but one of the first questions that came to my mind when I started with it is is really machine learning intelligent? Are these algorithms already better than us? And the response is that in some concrete questions, in some concrete aspects machines and algorithms are already better than us. One example of that is image recognition. ImageNet is hosting a yearly challenge on machine learning, on image recognition and the performance of the winner algorithms have been improving a lot during the last years thanks to the adoption of deep learning and this kind of technologies. In 2015, the winner algorithm performed better than humans at recognizing things inside images. Something similar happened to chess about 20 years ago when IBM's Deep Blue defeated the world champion, Gadik Asparov. I remember vividly reading about this in the news and reading it on the newspaper. Those 20 years ago, maybe, that's why some colleagues tell me that I'm a senior developer. But it was quite a milestone at the time but there are other games that are much more complex than chess. For example, the Game of Go. The Game of Go is so complex that the number of movements is bigger than the number of atoms in the universe. For such a complex game, it's very important to play with intuition. And for that reason, many people thought that algorithms could never win the champions until this spring when AlphaGo by Google defeated the world champion, Lyciol. This thing, algorithms being better than us in concrete tasks are happening more and more frequently. And for that reason, many people are making apocalyptic predictions on the moment that machines will be more intelligent than us. It's the singularity point. But, okay, I don't want to be so apocalyptic. I want to talk to you about my journey. As I said, six months ago I didn't know anything about machine learning and I thought that it would take weeks or months of study just to get started. But that's not true. If you are a dummy like me, you don't know anything about machine learning you can get started and in a little bit of time you can get very useful and very surprising things, at least for me. When I started, I decided to study not by using courses or books but by using massive open online courses. And these courses have videos and exercises and there are different providers. There are forums where you can discuss with other people about the things you are doing. And there are many different providers so you have to do your research here. What I chose was the Udacity Introduction to Machine Learning but it could be any other one which would fit for you. It's very well organized and it's using Python and Scale-Learn and this was a plus for me. And also for me it was very important that you can do it at your own pace because I can't stick to deadlines. So this was a plus for me. And one thing that caught my attention was the subtitle which is better recognition for fun and profit. I can imagine about the profit but what about the fun? And the course starts like this. A couple of friends sharing a bottle of wine, not bad. And it ends like this with same friends and more wine. So it seems that machine learning can also be fun after all. So what is machine learning? I want to explain very basic concepts and some insights that many times are not well explained or just overlooked when you start with machine learning. I think that there are things that are important at least for me and I want to share them with you. Of course this is not a short course and you should learn and read books and do courses and these things but when we work in machine learning we want to solve a complex problem. So we have something here in the middle and you show, you have some inputs which is the data in machine learning is features and we have to do a prediction which is the outcome of this thing here in the middle. The first approach, the classical approach is programming. Probably all of us here know how to program so you have to understand your problem and you have to explain it step by step in baby steps to the computer so that it can follow your steps to achieve the solution. But the problem is that for very complex domains such as emergency recognition, medicine, these kind of things this doesn't scale because let's imagine that we have to solve something for medicine. Maybe you have to code thousands and thousands of rules and these rules are not exact because medicine is not an exact science so maybe you have conflicts and you have to solve them and it's very difficult to solve. But if you use machine learning the approach is totally different. Instead of explaining the computer what are the steps to solve the problem you show the computer some real world data some examples of data and you let the algorithm learn and take its own conclusions from the data. This has huge implications and it's that we can teach computers to do things that we don't know how to do and I'll show you that in some minutes. So I'll try to explain from a user point of view I'm not going to enter into mathematical details because I studied mathematics something like 23 years ago and I couldn't remember but I'll try to explain from the point of view of users how machine learning works at a high level and we will solve an example for character recognition so we will have thousands of images like this each one is containing a character, a letter and we will have the labels telling us that the first letter is an F, the second an E and so on. So the first step in machine learning is getting our data. That blue image that corresponds to an F there, the yellow image which is a G and so on. Second step is to choose an algorithm. Lorena in the talk before this was talking about Naive Bayes but there are many many tens or maybe hundreds of algorithms out there. There is super vector machines or k-means, decision trees, neural networks many of them and you have to choose and there are different algorithms that can be a good fit for your project and also these algorithms can be configured so you have to choose a combination of algorithms and configuration so this is part of the machine learning art and then you train your algorithm. For training the algorithm you start by showing some images and you say okay this blue image is an F and this yellow image is a G and so on. In some respect it's like showing a baby to read. It's like teaching a baby to read. The first step is to get predictions so you show new data to the algorithm and it will tell you okay I think this is a D but the tricky question here is is that letter really a D? Is there an algorithm predicting correctly the letters inside? We will answer this question later. So we have a lot of tools and we have different languages such as MATLAB and R but here we want to talk about Python of course and I don't have to show here the beauty of Python but it's a very good fit and it's following its own philosophy of batteries included. There are many, many libraries with very good quality that will help you to solve problems very easily and we will solve the character recognition problem using Python and SQL learn is one of the most popular libraries out there it's open source with Python and the documentation is wonderful not just for the library but just as a reference of algorithms and methodologies and everything. And SQL learn gives support to the full life cycle of machine learning. So we will solve this problem. We will do the following steps we will get the features with labels we already have the data we will choose and configure an algorithm we will be using logistic regression with no configuration we will train the algorithm then we will do predictions and then we will validate them. So let's get started with the example we have this big data set here thousand of images with the labels we want to separate them in two different data sets one data set is for training the other is for testing for validating our results and we will use train test split function from SQL learn and we will split our data set and labels we will give a size for our training data set size matters but we will not explain why here and there is a random state that happens to be a constant and this showed me in the very beginning why the hell are we giving a random state that happens to be a constant and the other is that the train test split will separate our big data set in a random set of images for the training and the test but by passing this constant the selection of images for each data set will be the same always so that we can compare different configuration of the algorithms or different algorithms then we initialize our algorithm logistic regression, no configuration and we do the fit the fit is the training and we pass the training data set and the labels this is the part where we teach the baby to read but it's very easy we don't have to iterate and do things for us to do predictions we just call the predict function on our classifier but the question is if our predictions were good or bad to solve this question we will use accuracy there are many different ways in machine learning but we will use accuracy it's the simplest one and we don't have time for more so what we do is do predictions and we have some test predictions what we do is compare the test labels which is the ground truth the things we know are truth to the test predictions and this way we know the percentage of images that we have been predicting correctly with this example I just gave you we got 89% of accuracy this means that of 500 5000 images were predicting well 90% almost in just 5 lines of code and this is what I mentioned before I never did image recognition or image processing it would take weeks or months to implement such a thing without machine learning and we did it here in 20 minutes together of course we can improve the results we can play with training data as Lorena from the previous talk mentioned before we can change the algorithm and the configurations and this is very easy using SQL because the APIs for the different algorithms is almost the same and you can give SQL different configurations for one algorithm and it will test all the different configurations and give you the best one so we already seen this very simple example with classical machine learning currently I'm doing another course at Udacity of deep learning I just did the very first lesson and with it I did the first exercise of couple or exercises and I want to present them to you I think that it's part of code that you more or less can understand I'm not going to explain neural networks and please don't ask it because I don't know anything about it but I think that you can get an intuition on how we are going to structure the code so this is the course I'm still doing so I'm going to run we will use TensorFlow which is a library by Google and who is the author of the course as well and it seems that deep learning is not so fun because there is no wine in the course for the moment but I'm still in the first two lessons I will I keep my hope so we will be using TensorFlow and I'll jump directly to the code the difference between SQL and TensorFlow is that SQL learning is using an imperative API and in TensorFlow what you do is describe a set of mathematical operations in a kind of graph and then you execute that graph with your data so you have to know what are the mathematical operations to implement your neural network so please don't make questions about this this is the simplest possible neural network in the world this is two layers neural network and here in the left we have an image X and there on the right we have a prediction the prediction is a matrix with a set of probabilities for each letter so we will pick the letter with more probability and the implementation is very easy the image is a matrix and we will do the matrix multiplied by matrix of weights and we will add another matrix which is the bias and we will apply a ReLU function which is a kind of filter this is what I understood from the first lesson and you have then you are making a pipe the result from each one is going to be piped then we go to the second layer which is again a matrix multiplication an addition of a bias and we will get a matrix of weights and then we will do a softmax which is a function that transforms a set of weights in a set of probabilities so the implementation is very simple it's if you remember that you have, remember this what we do is we do a multiplication of matrices of our test data set with the first matrix of weights for the first layer and we add the biases this is layer 1 logits and then we apply the ReLU on the layer 1 logits and we will have the output for the first layer and then we do the matrix multiplication and then the addition and then we apply the softmax over the output of the previous operation and this is the implementation of a simple neural network this is the production neural network you have to train it so that you can have these different processes with correct values for your problem and it's much more complex and maybe next year I will explain that so this is what I wanted to share with you the idea is that I'll do a very quick summary machine learning is here already in our lives and it will become very important for everybody if you are a dummy like me machine learning don't be afraid you can do very funny things with the resources and tools that we have there outside and with very good quality free open source to use and you can do very funny things so if you want to use them and do interesting things just do it for your own profit and of course for fun thank you thank you compared to regression analysis neural networks are known to to be to take a lot of time what are your experience I think it's using part it's not as fast as C++ thank you for the question so in my experience the question is that as I understand the question the question is that how compares the performance from the first example and from the second and also how compares that with the performance with other languages such as C++ and the response is very easy for me to answer but in my experience the performance of the at least for these neural networks is more than enough and there have been many advances in last year with the adoption of graphic GPUs and different algorithms and we are using here instead of sinusoidal functions have made possible to train very complex networks in any case I don't know how it compares but if you want to train very complex models you will need very expensive hardware but you can play with it in a small laptop in my experience I also have a small question like there are a lot of tools with different level of support for example which provide basically API for machine learning like API.ai Watson from IBM something from Google my question is have you used them and is it worth to play around with them for example for text recognition they do a lot of interesting stuff so it's better to just develop something on your own Thank you I don't have a lot of experience with that system some weeks ago I did a small prototype of a chatbot using natural language processing libraries from Microsoft in that case and my experience is that these models are already very well trained for very specific purposes and if you have the time and money if your core business probably it's better for you to train your own models and have people specialized if it's some side thing it's not main core business you don't have the money probably these already built models are more than good enough for you but for very specific things you don't have already trained things but it's my experience Thank you So at 5.15 we've got some lightning talks otherwise tomorrow at 9am there will be a fantastic keynote by Paul Inder in the Brent who will be talking about the use of Python at Walt Disney and I'm told it's a great talk so I encourage you all to come let's thank the speakers again