Latest / Talk Python To Me / #31: Machine Learning with Python and scikit-learn
Transcript
- 0:00Machine learning allows computers to find hidden insights without being explicitly programmed where to look or what to look for.
- 0:06Thanks to the work of some dedicated developers, Python has one of the best machine learning platforms out there called scikit-learn.
- 0:14In this episode, Alexander Gramfort is here to tell us about scikit-learn and machine learning.
- 0:19This is Talk Python To Me, number 31, recorded Friday, September 25, 2015.
- 0:25I'm a developer in many senses of the word, because I make these applications, but I also use these verbs to make this music.
- 0:37I construct it line by line, just like when I'm coding another software design.
- 0:41In both cases, it's about design patterns. Anyone can get the job done, it's the execution that matters.
- 0:47I have many interests, sometimes conflict, but creativity can usually be a benefit.
- 0:53Welcome to Talk Python To Me, a weekly podcast on Python, the language, the libraries, the ecosystem, and the personalities.
- 1:00This is your host, Michael Kennedy. Follow me on Twitter, where I'm @mkennedy.
- 1:04Keep up with the show and listen to past episodes at talkpython.fm, and follow the show on Twitter via at Talk Python.
- 1:11This episode is brought to you by Hired and Codeship.
- 1:15Thank them for supporting the show on Twitter via at Hired underscore HQ and at Codeship.
- 1:22Hey, everyone. Thanks for listening today.
- 1:24Let me introduce Alexander so we can get right to the interview.
- 1:27Alexander Grandfort is currently an assistant professor at Telecom Paris Tech and scientific consultant for the CEA Neurospin Brain Imaging Center.
- 1:38His work is on statistical machine learning, signal and image processing optimization, scientific computing, and software engineering with a primary focus in brain functional imaging.
- 1:50Before joining Telecom Paris Tech, he worked at the Martino Center for Biomedical Imaging at Harvard in Boston.
- 1:56He's also an active member for the Center for Data Science at Université Paris-Saclay.
- 2:02Alexander, welcome to the show.
- 2:04Thank you. Hi.
- 2:06Hi. I'm really excited to talk about machine learning and scikit-learn with you today.
- 2:11It's something I know almost nothing about, so it's going to be a great chance for me to learn along with everyone else who's listening in.
- 2:17So hopefully I'll be able to give relevant answers.
- 2:21Yeah, I'm sure that you will.
- 2:23All right, so we're going to talk all about machine learning, but before we get there, let's hear your story.
- 2:27How did you get into programming in Python?
- 2:29Well, I've done a lot of scientific computing and scientific programming over the last maybe 10 to 15 years.
- 2:35I started my undergrad in computer science, doing a lot of signal and image processing.
- 2:40Well, like these types of people, I've done a lot of MATLAB in my previous life.
- 2:46Yes, I've done a lot of MATLAB too. I know about the .im files.
- 2:49And I switched to a team for my postdoc.
- 2:56Basically, I did a PhD in computer science applied to brain imaging.
- 2:59And I switched to a different team where basically I was surrounded by people working with Python.
- 3:05And basically, I got into it and switched.
- 3:08In one week, MATLAB was gone from my life.
- 3:14But it's been maybe five years now.
- 3:16And yeah, that's kind of the historical part.
- 3:20Do you miss MATLAB?
- 3:22Not really.
- 3:23Me either.
- 3:25There are some cool things about it, but...
- 3:29Yeah, I still have students that are insisting to work with me in MATLAB.
- 3:34So I have to still do stuff in MATLAB for supervision.
- 3:38But not really when I have the choice.
- 3:43Yeah, if you get a choice, of course.
- 3:44I think one of the things that's really a drawback about specialized systems like MATLAB is it's very hard to build production finished products.
- 3:53You can do research.
- 3:55You can learn.
- 3:56You can write papers.
- 3:57You can even test algorithms.
- 3:59But if you want to get something that's running on data centers on its own, probably MATLAB is, you know, you could make it work, but it's not generally the right choice.
- 4:06Definitely.
- 4:07Yeah.
- 4:08Yeah.
- 4:09And so things like, you know, I think that explains a lot of the growth of Python in this whole data science, scientific computing world, along with great toolkits like scikit-learn, right?
- 4:21Yes.
- 4:22I mean, definitely the way scikit-learn is now used.
- 4:27The fact that the Python stack allows you to make this production type of code is a clear win for everyone.
- 4:36So before we get into the details of scikit-learn and how you work with it and all the features it has, let's just, you know, in a really broad way, talk about machine learning.
- 4:46Like, what is machine learning?
- 4:47I would say the simple example of machine learning is trying to predict something from previous data.
- 4:54So what people would call supervised learning.
- 4:58And there are plenty of examples of this in everyday life, like your mailbox that predicts for you if your email is a spam or a ham.
- 5:07And that's basically a system that learns from previous data how to make an informed choice and give you a prediction.
- 5:17And that's basically the most simple way of seeing machine learning.
- 5:21And basically you see machine learning problems framed this way in all contexts, from industry to academic science.
- 5:30And, I mean, there are many examples.
- 5:33And basically, in terms of other types of classes of problems that you see in machine learning, it's not really these prediction problems.
- 5:43We're trying to make sense from raw data where you don't have labels like spam or ham, but you just have data and you want to figure out what's the structure, what types of input or insight can you get from it.
- 5:57And that's, I would say, the other big class of problem that machine learning addresses.
- 6:02Yeah, so there's that general classification.
- 6:06I guess with the first category you were talking about, like spam filters and other things that maybe fall into that realm would be like credit card fraud, maybe trading stocks, these kind of binary, do it, don't do it, based on examples.
- 6:21That's something that is, is it called structured learning or what's the?
- 6:26The common name is supervised learning.
- 6:30Supervised learning, that's right.
- 6:31Yeah, so basically you have pairs of training observations that are the data and their corresponding labels.
- 6:38So text and the label would be spam or ham.
- 6:41Or you can also see, this is basically binary classification.
- 6:45The other types of machine learning problems you have is, for example, regression.
- 6:49You want to predict the price of a house and you know the number of square feet.
- 6:54You know the number of rooms.
- 6:57You know what's exactly the location.
- 6:59And so you have a bunch of variables that describe your house or apartment.
- 7:03And from this you want to predict the price.
- 7:05And that's another example where now it seems the price is a continuous variable.
- 7:10It's not binary.
- 7:11This is what people call regression.
- 7:13And this is another big class of supervised learning problem.
- 7:17Right.
- 7:17So you might know through the real estate data, all the houses in the neighborhood that have sold in the last two years, the ones that have sold last month, all their variables and dimensions, if you will, like number of bathrooms, number of bedrooms, square feet, or square meters.
- 7:34You could feed it into the system to train it.
- 7:40And then you could say, well, now I have a house with two bathrooms and three bedrooms.
- 7:44And right here, what's it worth?
- 7:46Right?
- 7:46Exactly.
- 7:47That's basically a typical example and also a typical data set that we use in scikit-learn that basically illustrates the concept of regression with a similar problem.
- 7:55Right.
- 7:56There's, we'll talk more about it, but there's a scikit-learn comes with some pre-built data sets.
- 8:01And one of them is the Boston house market, right?
- 8:03Exactly.
- 8:04That's the one.
- 8:05Yeah.
- 8:05How much data do you have to give it?
- 8:08Like, suppose I want to try to estimate the value of my house, which, you know, at least in the United States, we have this service called Zillow.
- 8:14So they're doing way more.
- 8:16I'm sure they're running something like this, actually.
- 8:19But suppose I wanted to take it upon myself to, like, grab the real estate data and try to estimate the value of my home.
- 8:25How many houses would I have to give it before it would start to be reasonable?
- 8:30Well, that's a tough question.
- 8:32And I guess there's no simple answer.
- 8:35I mean, you have this, that you can see on the cheat sheets of scikit-learn that says if you have less than 50 observations, then go get more data.
- 8:45But I guess it's also a simplified answer.
- 8:48It depends on the difficulty of the task.
- 8:50So at the end of the day, often for these types of problems, you want to know something.
- 8:55And this can be easy or hard.
- 8:58You cannot really know before trying.
- 9:00And typically regression would say, okay, if I predict that the 10% plus or minus, that's maybe good enough for my application.
- 9:07And maybe you need less data.
- 9:08If you want to be super accurate, you need more data.
- 9:12But the question of how much is, it's really hard to answer without really trying and using actual data.
- 9:17Yeah, I can imagine.
- 9:18It probably also depends on the variability of the data, the accuracy of the data, how many variables you're trying to give it.
- 9:26So if you just added, just tried to base it on square footage or square meters of your house, that one variable, maybe it's easier to predict than, you know, 20 components that describe your house, right?
- 9:40So the thing, the more variables you have, the more you can hope to get.
- 9:46Now it's not as simple as this, because if variables are not informative, then they're basically adding noise to your problem.
- 9:53So you want as many variables to describe your data in order to capture the weak signals.
- 10:02But sometimes just variables are not relevant or predictive.
- 10:06And so there are more, you want to remove them from the prediction problem.
- 10:10Okay, that makes sense.
- 10:11So I was looking into what are some of the novel uses of machine learning in order to sort of have some things to ask you about and just see what's out there.
- 10:25What are ones that come to mind for you?
- 10:27And then I'll give you some that I found on my list.
- 10:29Maybe I'm biased because I'm really into using machine learning for scientific data and academic problems.
- 10:36But I guess for things that are really academic breakthrough that are reaching everybody is really related to computer vision and NLP these days and probably also speech.
- 10:47So these types of systems that try to predict something from speech signals or from images like describing you what's the contents, what types of objects you can find.
- 10:58And for NLP you have like machine translation.
- 11:01We did a show with OpenCV and the whole Python angle there.
- 11:07There was a lot of really cool stuff on medical imaging going on there.
- 11:11Does that have to do with scikit-learn as well?
- 11:14Well, you have people doing medical imaging using scikit-learn, basically extracting features from MR images, magnetic resonance images, or CT scanners, or also like EEG brain signals.
- 11:29And they're using EEG – sorry, they're using scikit-learn as the prediction tool, deriving features from their raw data.
- 11:40And that reaches, of course, clinical applications in some contexts.
- 11:45Maybe automatic systems that say, hey, this looks like it could be cancer or it could be some kind of problem, bring the attention of an expert who could actually look at it and say, yes, no, something like this?
- 11:57Yeah, exactly.
- 11:58It's like helping diagnosis, like trying to help the clinician to isolate something that looks weird or suspicious in the data to get like the time of this physicist and the clinician onto this particular part of the data to see what's going on and if the patient is suffering for something.
- 12:19Right.
- 12:19That's really cool.
- 12:20I mean, maybe you could take previous biopsies and invasive things that have happened to other people and their pictures and their outcomes and say, look, you have basically the same features and we did this test and the machine believes that you actually don't have a problem.
- 12:36So, you know, probably don't worry about it.
- 12:37We'll just watch this or something like that, right?
- 12:39Yeah, I mean, on this line of thought, there was recently a Kaggle competition using retina pictures.
- 12:45So, like people suffering from diabetes usually have problems with retinas.
- 12:50And so, you can take pictures of retinas from hundreds of people and see if you can build a system that predicts something about the patient and the state of the disease from these images.
- 13:05And this is typically done by pooling data from multiple people.
- 13:08That's really cool.
- 13:09I've heard this Kaggle competition or challenges before in various places looking at it.
- 13:15What is that?
- 13:15So, it's basically a website that allows you to organize these types of supervised learning problems where a company or a structure, NGO, whatever, is having data and is trying to build a system, a predictive system.
- 13:33And they ask Kaggle to set this up, which basically means for Kaggle putting the training data set online and giving this to data scientists.
- 13:45And they basically then spend time building a predictive system that is evaluated on new data on which to get a score.
- 13:52And that allows you to see how the system works on new data and to rank basically the data scientists that are playing with the system.
- 14:01It's kind of an open innovation approach in data science.
- 14:07That's really cool.
- 14:08So, that's just Kaggle.com.
- 14:10Yes.
- 14:11K-A-G-G-L-E.com.
- 14:13Exactly.
- 14:13Yeah.
- 14:14Very nice.
- 14:14Some of the other ones that I sort of ran across while I was looking around that were pretty cool was one is some guys at Cornell University built machine learning algorithms to listen for the sound of whales in the ocean and use them in real time to help ships avoid running into whales.
- 14:34That's pretty awesome, right?
- 14:35Yeah.
- 14:36Yeah.
- 14:36There was a Kaggle competition on these whale sounds maybe a couple of years ago.
- 14:43And it was a – I mean, not many data scientists have experienced, like, listening to whales.
- 14:49So, it's kind of everybody doesn't really know what types of data.
- 14:53And I remember this presentation from the winner basically saying how to win a Kaggle competition without knowing anything about the data.
- 15:01It's kind of a provocative talk.
- 15:03That is cool.
- 15:04But showing how you can basically build a predictive system by just looking at the data and trying to make sense out of it without really being an expert in the field.
- 15:13Yeah.
- 15:13That's probably a really valuable skill as a data scientist to have, right?
- 15:17Because you can be an expert, but not in everything.
- 15:19Some other ones that were interesting was IBM was working on something to look at the handwritten notes of physicians.
- 15:29Uh-huh.
- 15:30And then it would predict whether – how likely the person that those notes were about would have a heart attack.
- 15:37Yeah.
- 15:37In the clinical world, it's true that a lot of information is actually raw text, like manual, like just written notes, but also raw text on the system.
- 15:48For machine learning, that's a particularly difficult problem because it's what we call unstructured data.
- 15:57So you need to – typically for scikit-learn to work on these types of data, you need to do something extra to basically come up with a structure or come up with features that allow you to predict something.
- 16:08Sure.
- 16:10And so both of those two examples that I brought up have really interesting data origin problems.
- 16:15So if I give you an MP3 of a whale or an audio stream of a whale, how do you turn that into numbers that go into the machine even to train it?
- 16:30And then similarly with handwriting, how do you – you've got to do handwriting recognition.
- 16:36You've got to then do sort of understanding what the handwriting means.
- 16:41And there's a lot of levels.
- 16:42How do you take this data and actually get it into something like scikit-learn?
- 16:46So scikit-learn expects that every observation, we also call it a sample or a data point, is basically described by a vector, like a vector of values.
- 16:57So if you take the sound of the whale, you can say, okay, there's a sound in the MP3, it's just a set of floating point values, like every time sample, really time domain signals that you get for a few seconds of data.
- 17:10It's probably not the best way to get a predictive – a good predictive system.
- 17:15You want to do some feature transformation, change the input to get something that brings features that are more powerful for scikit-learn and the learning system.
- 17:25And you would typically do this with time-frequency transform, things like spectrograms, trying to extract features that are really, for example, invariant to some aspects of the day, like frequencies or time shifts.
- 17:38So there's probably a bit of pre-processing to do on these row signals.
- 17:43And then once you have your vector, you can use the scikit-learn machinery to build your predictive system.
- 17:48How much of that pre-processing is in the tool set?
- 17:53So it depends for what types of data.
- 17:55Typically for signals, there's nothing really specific in scikit-learn.
- 17:59You would probably use scipy signal or any types of signal processing Python code that you find online.
- 18:06I would say for other types of data, like text, in scikit-learn, there are something that is called feature extraction module.
- 18:14And you have – in the feature extraction module, you have something for text, which is probably the biggest part of the feature extraction is really text processing.
- 18:22And you have some stuff also for images, but it's quite limited.
- 18:29We should probably introduce what scikit-learn is and get into the details of that.
- 18:33But I have one more sort of example to let people know about that I think is pretty cool.
- 18:38On show 16, I talked to Roy Rappaport from Netflix.
- 18:42And Netflix has a tremendously large cloud computing infrastructure to power all of their – you know, basically their movie system, right?
- 18:51And everything behind the scenes there.
- 18:53And they have so many virtual machine instances and services running on them and then different types of devices, accessing services on those machines that they said it's almost impossible to determine if there's, you know, some edge case where there's a problem manually.
- 19:10And so they actually set up machine learning to monitor their infrastructure and then tell them if there's some kind of problem in real time.
- 19:18Yeah.
- 19:19So I think that's really a cool use of it as well.
- 19:33This episode is brought to you by Hired.
- 19:36Hired is a two-sided, curated marketplace that connects the world's knowledge workers to the best opportunities.
- 19:42Each offer you receive has salary and equity presented right up front, and you can view the offers to accept or reject them before you even talk to the company.
- 19:51Typically, candidates receive five or more offers in just the first week, and there are no obligations ever.
- 19:58Sounds pretty awesome, doesn't it?
- 20:00Well, did I mention there's a signing bonus?
- 20:02Everyone who accepts a job from Hired gets a $2,000 signing bonus.
- 20:06And as Talk Python listeners, it gets way sweeter.
- 20:10Use the link Hired.com slash Talk Python To Me, and Hired will double the signing bonus to $4,000.
- 20:18Opportunity's knocking.
- 20:20Visit Hired.com slash Talk Python To Me and answer the call.
- 20:31Yeah, that's a very cool thing to do.
- 20:36And actually, many industries and many companies are looking for these types of systems that they call anomaly detection or failure prediction.
- 20:46And it's getting a big use case for machine learning, indeed.
- 20:52The Netflix guys were actually using scikit-learn, not just some other machine learning system.
- 20:56So let's get to the details of that.
- 20:59What's scikit-learn?
- 20:59Where did it come from?
- 21:00So scikit-learn is probably the biggest machine learning library that you can find in the Python world.
- 21:07So it dates back from almost 10 years ago when David Cornapal was doing a Google Summer of Code to kickstart the scikit-learn project.
- 21:16And then for a few years, there was a French guy called Mathieu Broucher who took on the project.
- 21:24But it was kind of a one-guy project for many years.
- 21:28And in 2010, with colleagues at INRIA in France, we decided to basically try to start from this state of scikit-learn and make it bigger and really try to build a community around this.
- 21:46So these people are Gael Varroco and Fabian Pedregosa and also somebody you may have heard of in the machine learning world with Olivier Grisel.
- 21:56And so that was pretty much 2010, so five years ago.
- 22:03And basically it took on pretty quickly.
- 22:05After, I would say, a year of scikit-learn, we had more than 10 core developers way beyond the initial lab where it started.
- 22:17That's really excellent.
- 22:18Yeah, I mean, it's definitely an absolutely mainstream project that people are using in production these days.
- 22:24So congratulations to everyone on that.
- 22:26That's great.
- 22:26Thank you.
- 22:27Yeah.
- 22:28And so the name scikit-learn comes from the fact that it's basically an extension to the SciPy pieces, right?
- 22:37So SciPy is like NumPy for numerical processing, SciPy for scientific stuff, Matplotlib, IPython, SimPy for symbolic math, and Pandas, right?
- 22:48And then there's these extensions.
- 22:50Yes.
- 22:51So basically the kind of division is that you cannot put everything in SciPy.
- 22:55SciPy is already a big project.
- 22:57And the idea of the SciKits were to build extensions around SciPy that are more domain-specific.
- 23:03Also, it's kind of also easier to contribute to a smaller project.
- 23:08So basically the barrier of entry for newcomers is much lower when you contribute to a Scikit than to SciPy, which is a fairly big project now.
- 23:16Yeah, there's so much support for the whole SciPy system, right?
- 23:22So it's much better to just build on that than try to duplicate anything and say NumPy or whatever.
- 23:27Exactly.
- 23:28I mean, there's a lot of efforts to see what could be NumPy 2.0 and what's going to be the future of it and how to extend it.
- 23:37I mean, a lot of people are thinking of what's next because, I mean, NumPy is almost 10 years old, probably more than 10 years old now.
- 23:44And, yeah, people are trying to see also how it can evolve.
- 23:49Sure.
- 23:49That makes a lot of sense.
- 23:51So speaking of evolving and going forward, what are the plans with scikit-learn?
- 23:57Where is it going?
- 23:57So I would say in terms of features, I mean, scikit-learn is really in the consolidation stage.
- 24:04scikit-learn is five years old.
- 24:06The API is pretty much settled.
- 24:09There's a few things here and there that are basically that we have to deal with now that basically due to early decisions in terms of API that needs to be fixed.
- 24:20And I guess the big objective is to basically do scikit-learn 1.0, like the first stable, fully stable release in terms of API because that's something that we've been talking about between the core developers for, I mean, more than two years now, coming with this 1.0 version that stabilizes every part of the API.
- 24:44Right.
- 24:44One final major cleanup, if you can, and then stabilizing it, yeah?
- 24:49Exactly.
- 24:49Exactly.
- 24:49And in terms of new features, I mean, you always have a lot of cool stuff that are around and you see the number of pull requests that are coming on top of scikit-learn.
- 25:01It's pretty crazy.
- 25:02And I would say a huge maintainer's effort and reviewing effort.
- 25:07So features are coming in slowly now in scikit-learn, much more slowly than it used to be, but I guess it's normal for a project that is getting big.
- 25:14Yeah, it's definitely getting big.
- 25:16It has 7,600 stars and 4,500 forks on GitHub, so that's pretty awesome.
- 25:22Yeah.
- 25:23It has 457 contributors.
- 25:24Cool.
- 25:25Yeah, I would say for every release we get, I mean, we try to release every six months.
- 25:30And for every release we get a big number of contributors.
- 25:36So maybe we could do like a survey of the modules of scikit-learn, just the important ones that come to mind.
- 25:44What are the moving parts in there?
- 25:46So I would say maybe something I know the most, which is a part of the module that I maintain the most, which is the linear model.
- 25:52And recently the efforts on the linear models were to scale it up.
- 25:58Basically try to learn this linear models in an out-of-core fashion to be able to scale to data that do not fit in RAM.
- 26:07And that's part of the, I would say, part of the plan for this linear model module in scikit-learn.
- 26:15That's cool.
- 26:15So what kind of problems do you solve with that?
- 26:17The types of problems where you have a, like, humongous number of samples and potentially a lot number of features.
- 26:24So there are not so many applications where you get that many number of samples, but that's typically text or log files.
- 26:31These types of industry problems where you collect a lot of samples on a regular basis.
- 26:38You have these examples also if you monitor an industrial system, like if you want to do what we discussed before about, like, predictive maintenance.
- 26:46That's probably a use case where this can be useful.
- 26:50Probably the other, like, module that also attracts a lot of effort these days is the Ensemble module, and especially the tree module.
- 27:00So for models like Random Forest or Gradient Boosting, which are very popular models that have been helping people to win cargo competitions for the last few years.
- 27:13Yeah, I've heard a lot about these forests and so on.
- 27:17Can you talk a little bit about what that is?
- 27:19So a random forest basically is a set of decision trees that you pull together to get a prediction that is more accurate.
- 27:32More accurate because it has less variance in technical terms.
- 27:36And the way it works is you try to basically build decision trees from a subset of data, a subset of samples, subset of features in a clever way.
- 27:46And then you pull all these trees in one big predictive model.
- 27:50And, for example, if you do binary classification and you train a thousand trees, you ask for a new observation to the thousand trees.
- 27:59What's the label?
- 27:59Is it positive or negative?
- 28:01And then you basically count the number of trees that are saying positive.
- 28:05And if you have more trees saying positive, then you predict positive.
- 28:08That's kind of the basic idea of random forest.
- 28:11And it turns out to be super powerful.
- 28:13That's really cool.
- 28:14Well, it seems to me like it would bring in kind of different perspectives or taking different components or parts of a problem into account.
- 28:23So some of the trees look at some features and maybe the other trees look at other features.
- 28:28And then they can combine in some important way.
- 28:31Exactly.
- 28:32Yeah.
- 28:33Another one that I see coming up is the SVM module.
- 28:36What's that one do?
- 28:38So SVM is a very popular machine learning approach that was basically, I mean, very big in the 90s and 10 years ago and still get some attraction.
- 28:52And basically, the idea of a support vector machine, which is the SVM is the according for, is to be able to use kernels on the data and basically solve linear problems in an abstract space where you project your raw data.
- 29:10Let me try to give an example.
- 29:11If you take a graph or if you take a graph or if you take a string, that's not naturally something that can be represented by a vector.
- 29:18And when you do an SVM, you have a tool, which is a kernel that allows you to compare these observations, like a kernel between strings, a kernel between graphs.
- 29:27And once you define this kernel, and this kernel needs to satisfy some properties that I'm going to skip, then you can use this SVM to do classification but also regression.
- 29:37This is what you have in the SVM module of Seciturn, which is basically a very clever and efficient binding of an underlying library, which is called LibSVM.
- 29:47Okay, excellent.
- 29:48And is that used more in the unsupervised world?
- 29:51It's completely supervised.
- 29:52When you do SVM, it's classification or regression that's supervised.
- 29:55There's one use case of SVM in an unsupervised setting, which is what we call the one-class SVM.
- 30:02So you just have one class, which basically means that you don't have labels, you just have data, and you're trying to see what are the data that are the less like the others.
- 30:11That's more like an anomaly detection problem, or we call it also novelty detection or outlier detection.
- 30:17Maybe we could talk a little bit about some of the algorithms.
- 30:21As a non-expert in sort of the data science machine learning field, I go in there and I see all these cool algorithms and graphs, but I don't really know what would I do with that.
- 30:31On the site, it says there's all these algorithms it supports.
- 30:34So, for example, it supports dimensionality reduction.
- 30:38Like, what kind of problems would I bring that in for?
- 30:41I guess it's hard to summarize.
- 30:44The hundreds of hundreds of pages that you have in scikit-learn in the documentation, I'm trying to give you a big picture without too much technical detail to tell you when these algorithms are useful and what they are useful for, and what are the hypotheses and what kind of output you can hope to get.
- 31:02It's one of the strengths of the scikit-learn documentation, by the way.
- 31:05And so to answer your question, dimensionality reduction, I would say like the 101 way of doing it is the principal component analysis, where you're trying to extract subspace that captures the most variance in the data.
- 31:22And that can be used to do visualization of the data in low dimension.
- 31:26If you do a PCA in two or three dimensions, then you can look at your observation as a scatterplot in two or three D.
- 31:33And that's basically visualization.
- 31:35But you can also use this to reduce the size of your data set, maybe without losing too much predictive power.
- 31:43So you take your biggest data set, you run a PCA, and then you reduce the dimension.
- 31:48And then suddenly you have a learning problem, which is on smaller data, because you basically reduce the number of features.
- 31:55That's kind of the standard approaches, which is like visualization or reducing of the data set to have a more efficient learning in terms of computing time, but also sometimes in prediction problem.
- 32:08Okay, that makes a lot of sense.
- 32:10That's really cool.
- 32:10So like if we went back to my house example, maybe I was feeding like the length of the driveway and the number of trees in the yard.
- 32:18And it might turn out that neither of those have any effect on house prices.
- 32:22So we could reduce it to a smaller problem by having this whole PCA go, look, those don't matter.
- 32:27Throw that part out.
- 32:28It's really about the number of bathrooms and the square footage or something.
- 32:32Well, yes and no.
- 32:36That's kind of the idea.
- 32:36Okay, but in this example of Boston, the prediction of houses, you want to reduce the dimension in an informed way.
- 32:44Because the number of trees in the yard can be informative for something, but maybe not to predict the price of the apartment or price of the house.
- 32:52So when you do dimensionally reduction in the context of supervised learning, that can be also what you call feature selection or basically selecting the predictive features, which ultimately leads to a reduced data set because you remove features.
- 33:05But that would be in a supervised context.
- 33:07When you do PCA, you're really in an unsupervised way.
- 33:10You don't know what are the labels.
- 33:11You just want to figure out what's the variance.
- 33:14Where is the variance in the data coming from?
- 33:16On which axis and which direction should I look to see the structure?
- 33:20Another thing that is in there are ensemble methods for predicting multiple supervised models.
- 33:29What's the story there?
- 33:30That sounds cool.
- 33:30So random forest is an example of ensemble methods.
- 33:36When you have an ensemble, it's basically saying that you're taking a lot of classifiers or a lot of regressors and you combine them in a bag of prediction, a bag of models or an ensemble of models.
- 33:50And then you make them collaborate in order to build a better prediction.
- 33:53And random forest is basically an ensemble of trees.
- 33:57But you can also do an ensemble of neural networks.
- 34:02You can do an ensemble of whatever model you want to pull.
- 34:07And that turns out to be in practice often a very efficient approach.
- 34:11Yeah, like we were saying, the more perspectives, different models, it seems like that's a really good idea.
- 34:18So you mentioned neural networks.
- 34:20Yes.
- 34:21So scikit-learn has support for neural networks as well?
- 34:23Well, you have a multilayer perception, which is like the basic neural network.
- 34:29I mean, these days in neural network, people talk about deep learning.
- 34:32I've heard about it.
- 34:33That's about the extent of it.
- 34:34What's deep learning?
- 34:35This episode is brought to you by Codeship.
- 34:53Codeship has launched organizations, create teams, set permissions for specific team members,
- 34:58and improve collaboration in your continuous delivery workflow.
- 35:01Maintain centralized control of your organization's projects and teams with Codeship's new organizations plan.
- 35:07And as Talk Python listeners, you can save 20% off any premium plan for the next three months.
- 35:12Just use the code TALKPYTHON, all caps, no spaces.
- 35:17Check them out at CodeChip.com and tell them thanks for supporting the show on Twitter where they're at, CodeChip.
- 35:28So deep learning is basically neural networks 2.0, where you take neural networks and you stack more layers.
- 35:35So kind of the story there is that for many years, people were kind of stuck with networks of two or three layers.
- 35:44So not very deep.
- 35:46And part of the issue is that it was really hard to train something that would add more layers.
- 35:51In terms of research, there was two things that came up, which is first that we get access to more data,
- 35:57which means that we can train bigger and more complex models.
- 36:01But also there were some breakthrough in learning these models that allowed people to avoid overfitting,
- 36:09trying to be able to learn this bigish model, these big models, because you have more data,
- 36:14but also clever ways to prevent overfitting.
- 36:17And that basically led to deep learning these days.
- 36:19Oh, very interesting.
- 36:20Yeah, that's been one of the problems with neural networks, right?
- 36:23Is that if you teach it too much, then it only knows, you know, just the things you've taught it or something, right?
- 36:27Exactly.
- 36:28It basically learns by heart what you provide as trading observations
- 36:33and end up being very bad when you provide new observations.
- 36:38Want to talk a little bit about the datasets that come built in there?
- 36:41Uh-huh.
- 36:42We've talked a little bit about the Boston one, and that's the Boston house prices for regression.
- 36:47What I hear coming up a lot is one called Iris.
- 36:50Is that like your eye itself?
- 36:54So Iris is the dataset that we use to illustrate all the classification problems.
- 37:00It's really something that is a very common dataset that turned out to have a good license that we could ship it with scikit-learn,
- 37:07and basically we built most of the examples using this Iris dataset,
- 37:12which is also very much used in textbooks of machine learning.
- 37:15So that was kind of the default choice, and it talks to people because you understand what's the problem that you're trying to do,
- 37:23and it's rich enough and not too big, so we can make all these examples run super fast and build a nice location.
- 37:30That's very cool.
- 37:30What is the dataset?
- 37:31What exactly is it about?
- 37:33So the Iris dataset, you're trying to predict the types of plants, for example, using the sepal length, so the sepal width.
- 37:44So you have a number of features that describe the plant, and you're trying to predict which one among three it is.
- 37:51So it's a three-label, three-class classification problem.
- 37:55Yeah, that's cool.
- 37:56Enough data to not just be a linear model or something, a single variable model, but not too much?
- 38:02Exactly.
- 38:04It's not completely linear a bit, but not too hard at the same time.
- 38:10Right.
- 38:10If you get 20 variables, that's probably too much to deal with.
- 38:13Then one is on diabetes.
- 38:14What about diabetes does that dataset represent?
- 38:17Do you know?
- 38:18I'm actually not really sure what's the – no, it's a regression problem.
- 38:24It's used a lot in the linear model, especially for the sparse regression models because the – I mean, part of these sparse regression models are trying to extract the predictive features.
- 38:34I guess in the diabetes dataset, you try to find something related to diabetes, and you're interested into finding the most predictive features.
- 38:41What are the best features?
- 38:43And then that's part of the reason I think we're using it.
- 38:46And then another one is digits, which kind of meant to model images, right?
- 38:51One of the early, I would say, breakthrough of machine learning was this work in the 90s where Yad Lequin and other people were trying to build a system that could predict what was the digit present on the screen or in the image.
- 39:10So it's a very old machine learning problem where you start from a picture or an image of a digit that is handwritten, and you're trying to predict what it is from zero to nine.
- 39:20And it's an example that basically people can easily grasp in order to understand what's the machine learning.
- 39:26You give me an image, and I'll predict something between zero and nine.
- 39:30And historically, when we did the first version of the scikit-learn website, we had something like seven or eight lines of Python code that were running classification of digits.
- 39:41So that was kind of the motivation example where we said, okay, scikit-learn is machine learning made easy.
- 39:46And here it is, an example.
- 39:48It's ten lines of code classifying digits.
- 39:51And that was basically the punchline.
- 39:53Solving this old hard problem in a nice, simple way, right?
- 39:57Yeah.
- 39:57You know, lately, there's been a lot of talk about artificial intelligence, and especially from people like Elon Musk and Stephen Hawking,
- 40:08saying that maybe we should be concerned about artificial intelligence and things like that.
- 40:14So one of my first questions around this area is, is machine learning the same thing as artificial intelligence?
- 40:20Depends who you ask.
- 40:23Okay.
- 40:24Sure.
- 40:25No, I mean, AI was basically the early name of trying to teach a computer to do something.
- 40:34I mean, it dates back from the 60s and 70s, where basically in the US, for example, at MIT, you had labs that are basically called AI labs.
- 40:42And machine learning is kind of a, I would say, more restricted set of problems that compared to AI,
- 40:53which is, say, when you do AI and you want to do work with text or linguistic, you want to build a system that understands linguistic.
- 41:02That would be an AI problem.
- 41:05But machine learning is kind of a saying, okay, I've got a loss function.
- 41:08I want to optimize my criteria.
- 41:10I've got something that I want to train my system on.
- 41:15And in a sense, you teach a system to learn.
- 41:17And so you create some kind of intelligence.
- 41:21But it's not, I would say it's a, I would say simpler thing to say than saying intelligence, which is kind of a hard concept.
- 41:28That's maybe part of my personal answer to this.
- 41:31Yeah, no, it's a great answer.
- 41:33Just from my limited exposure to it, it seems like machine learning is more about classification and prediction,
- 41:39whereas the AI concept is a, there's a strong autonomous component that is just completely lacking for machine learning.
- 41:47Yeah, I guess I would say, I would explain it simply like this, exactly.
- 41:52What things have you seen people using scikit-learn for that surprised you?
- 41:58Or like, wow, you guys are doing that?
- 42:00That's amazing.
- 42:03So on scikit-learn, we have this testimonial page where we ask typically companies or institutes that are using scikit-learn to write a couple of sentences to say, okay, what they're using scikit-learn for and why they think it's great.
- 42:23I'm trying to find this.
- 42:25And I remember there was this, I think, a dating website.
- 42:30Saying that they were using scikit-learn to optimize dates between people.
- 42:36That was great.
- 42:38That was like a funny one.
- 42:40That is funny.
- 42:41So there may be people out there who are married and maybe even babies who are born because of scikit-learn.
- 42:46Yeah, that would be great.
- 42:49I'm going to add this to my resume.
- 42:52It's awesome.
- 42:53Matchmaker.
- 42:54So if people want to get started with scikit-learn, they're out there listening, they're like, this is awesome.
- 43:00Where do I start?
- 43:01What would you recommend for sort of getting into this whole world of machine learning and getting started with scikit-learn in particular?
- 43:07They first start with the scikit-learn website, which is pretty extensive.
- 43:11But you also have a lot of tutorials that have been given by core devs of scikit-learn in different conferences like SciPy, EuroSciPy, or PyData events.
- 43:22And you can find all these videos online.
- 43:24I'll just tell you, just take some of them and just sit down and just listen and try to do it yourself afterwards.
- 43:35I mean, for example, in SciPy, you've got tutorials on scikit-learn that are pretty much a whole day of tutorials, which is hands-on.
- 43:41And all these are taped.
- 43:42So you can really look and get the materials online from the tutorial and get started.
- 43:48Oh, that's excellent.
- 43:49Yeah, I think it's really amazing these days that there's so many of these videos online that you can...
- 43:56There's some topic you imagine, like, hey, I want to know this thing in Python.
- 43:59There's a very good chance that someone gave some kind of conference talk on it and it's online.
- 44:03Yeah.
- 44:05Anything you want to give sort of a shout-out to or a final call to action before we sort of wrap things up a bit?
- 44:10So if you have free time, you like machine learning, come give us a hand to maintain this cool library.
- 44:18Yeah, absolutely.
- 44:20Yeah, like I said, there's 457 contributors, but, you know, you guys are looking to stabilize things and move forward.
- 44:26So I'm sure there's a lot to be done around that.
- 44:28Yeah.
- 44:29I mean, basically, you also have two types of contributors.
- 44:32You have these one-time contributors that are really expert in something that contributes something that is really specific and valuable that gets merged to the main code base.
- 44:42And you have, I would say, less people that are investing their time to read the code from others, keep their library consistent in terms of API.
- 44:51And that's really this big reviewing work that I would say.
- 44:55I would say the historical core devs of scikit-learn are pretty much mostly doing these days and invest little time to do really new stuff that is basically left to the newcomers.
- 45:05And I think what would be, if I had to wish something for the future is that these people or these one-time contributors also spend a bit of their time to help us maintain the entire library in longer run.
- 45:21Yeah, that makes sense.
- 45:22I can see in something like scikit-learn where it's kind of a family of all these different algorithms and little techniques that if you want to add your technique, you just go in there and you do that little bit and you kind of stay out of the rest of the code.
- 45:36And I can see how that would definitely lead to inconsistencies and so on.
- 45:40Yeah, and in terms of policy, I mean, in terms of scikit-learn, that's why maybe there's less things that are coming in these days is that we're not trying to build a library that contains all the algorithms that you can ever think of or that get published every year.
- 45:54We're trying to keep or have the algorithms that are better on some clear use case in the current state of the art.
- 46:04And so we cannot implement everything, but at least if you have a particular type of problem, you should have something in scikit-learn that does a good job.
- 46:12So before I let you go, I have two more final questions for you.
- 46:16So if you're going to open, if you're going to write some Python code, what editor do you open up?
- 46:21So I've been a big user of TextMate over the years.
- 46:27And I have to admit, I switched to Sublime recently because I got convinced by my neighbor.
- 46:34So no Vim or Emacs troll with me.
- 46:37Yeah, that's cool.
- 46:39Yeah, I like Sublime Text a lot.
- 46:41Very nice.
- 46:41And of all the cool machine learning and Python in general packages out on PyPI, what are some that you think people maybe don't know about that you're like, hey, this is awesome.
- 46:52You should know about it.
- 46:53Well, maybe I'm biased because I do a lot of machine learning for brain science.
- 46:57And so unrelated to scikit-learn per se, but I've been working for the last five years on this project that's called MNE, which allows you to process brain waves and classifying brain states.
- 47:09Like, for example, build brain-computer interfaces or analyze clinical data of electrophysiology.
- 47:15That's basically, if you want to play with brain waves, you can check it out.
- 47:18That's really cool.
- 47:20And when you say brain-machine interfaces, is it like EEGs and stuff like that?
- 47:24Exactly.
- 47:25EEG, MEG.
- 47:26Yeah.
- 47:27Okay.
- 47:27Wow.
- 47:28Very awesome.
- 47:28Yeah, I hadn't heard of that one.
- 47:29That's cool.
- 47:30So again, I'm biased.
- 47:32That's more my second baby.
- 47:34Yeah, that's great.
- 47:36So, Alexander, it's been really great to have you on the show.
- 47:40And this has been a super interesting conversation.
- 47:42Thanks.
- 47:42Thank you very much.
- 47:44You bet.
- 47:44Talk to you later.
- 47:46This has been another episode of Talk Python To Me.
- 47:49Today's guest was Alexandra Gramfort.
- 47:51And this episode has been sponsored by Hired and CodeShip.
- 47:55Thank you guys for supporting the show.
- 47:57Hired wants to help you find your next big thing.
- 48:00Visit Hired.com slash Talk Python To Me to get five or more offers with salary and equity presented right up front.
- 48:06And a special listener signing bonus of $4,000.
- 48:09CodeShip wants you to always keep shipping.
- 48:13Check them out at CodeShip.com and thank them on Twitter via at CodeShip.
- 48:17Don't forget the discount code for listeners.
- 48:19It's easy.
- 48:20Talk Python.
- 48:21All caps.
- 48:22No spaces.
- 48:24You can find the links from today's show at talkpython.fm/episodes slash show slash 31.
- 48:30Be sure to subscribe to the show.
- 48:33Open your favorite podcatcher and search for Python.
- 48:35We should be right at the top.
- 48:36You can also find the iTunes and direct RSS feeds in the footer of the website.
- 48:40Our theme music is Developers, Developers, Developers by Corey Smith, who goes by Smix.
- 48:46You can hear the entire song on talkpython.fm.
- 48:49This is your host, Michael Kennedy.
- 48:52Thank you very much for listening.
- 48:54Smix, take us out of here.
- 48:56Thank you.
- 48:57Stating with my voice.
- 48:58There's no norm that I can feel within.
- 49:00Haven't been sleeping.
- 49:01I've been using lots of rest.
- 49:03I'll pass the mic back to who rocked it best.
- 49:06First of all, first of all.
- 49:08First of all, first of all.
- 49:15developers, developers, developers, developers.