Python for Data Science - OOP, Clases and Inheritance

Nicholas Renotte · Intermediate ·💻 AI-Assisted Coding ·4y ago

Key Takeaways

This video covers classes and class inheritance in Python for data science, using tools such as Jupyter Notebook and TensorFlow Functional API. It demonstrates object-oriented programming concepts, including attributes, methods, and inheritance.

Full Transcript

what's happening guys welcome to the live stream in this video we're going to be going through a bunch of python stuff but specifically we're going to be handling object oriented programming and specifically classes class inheritance we'll also do a little bit on how we can define attributes and methods as well so specifically what are we going to be covering well we are going to be going through how to cover classes and specifically how to build custom classes if you need to and these classes come really really in handy particularly when you're doing some really hardcore deep learning stuff so i've been doing a lot with the tensorflow functional api and what i've actually noticed is that in order to build really specific models or really more slightly more advanced models you're going to want to have a handle on classes we'll also take a look at how we can deal with attributes and how we can attach methods to our classes and then one of my favorite topics is class inheritance so this is how we can build super classes or sub classes from existing classes and again this is a common theme that you'll actually pick up when you start to use specific deep learning models like pytorch or tensorflow as well so on that note let's actually get to it okay so let's go on ahead and we are going to start writing some code so as per usual what we're going to be doing is we're going to open up a jupyter notebook that we've previously used so i'm going to step into what are we stepping into our command prompt so i'm gonna open up command prompt and then i'm gonna go to where my jupyter notebook is so this jupiter notebook could pretty much be wherever but uh we need to obviously go to that specific location and be able to open it up so let's go do that so i'm going to type in or go to a directory so let's actually take a look at where that is first up so i'm just going to bring it up over here and we so my stuff is inside of youtube and then python basic so we need to go to that location so first up what we need to do is go to id drive and then everything is inside of a folder called youtube and again this could be in a different location based on where you're doing it so that's perfectly fine just go to where your existing jupyter notebook is and open it up so we're going to go to our location so i'm going to go to cd and then youtube and then go into python basics because that's where we've been doing all of our python for data science work so let's go there so cd nope cd python basics and then we're going to kick jupiter off so again how do we start jupiter we write jupiter notebooks from our command prompt and what have i written there uh jupiter notebook my bad jupiter notebook not jupyter notebooks okay then i can minimize that and then we're going to bring it over here so remember when we're working with our jupyter notebooks we've got the extension ipi mb so we can open this up and this is all the stuff that we've covered in our previous tutorials already so we've gone through a bunch of stuff so data types lists dictionaries loops conditions functions so we'll actually cover functions a little bit in here but specifically methods which are attached to our classes so as per usual we're going to start this off by creating a new section because we want to keep our things nice and structured so we are going to create a new section so i'm going to create so remember to convert a cell into a markdown cell so right now it's active so you can see it there it's green let's actually add some additional cells below so i can get this a little bit more centered so i'm going to hit bb bbb get a little bit more centered in the screen and then right now it's active so you can see that it's green so how do we get out of this we hit escape on our keyboard and then we want to convert it from a code cell to a markdown cell so we're going to hit m and that is a markdown cell now this section is going to be called classes because class is now in session all right so that's classes now the class that we're going to create is we're first i'm going to create and in continuing with our sort of space theme we're going to create a class for a person now we've already encountered classes a couple of times so specifically when we're going through uh what do we use classes for already well a string is a well string is a data type but i'm trying to think if we've actually encountered any classes we might not have yet okay we're going to create a class so the class that we're going to be creating well let's actually talk about what classes are first off so classes are objects with defined properties and methods now properties could be an attribute so for example a string a string had different methods attached to it and it had different attributes so we're going to create a reproducible class and this is like almost think of it like a boilerplate for an object so again if you think of your classes classes as boiler plates or objects right and the nice thing about classes is that you can inject different properties into them so say for example you're going to be using this for deep learning one example is you might be creating a new custom layer for a specific deep learning model what you might want to do is inject a specific number of layers or ensure that it has a specific type of activation functions classes are perfect for this because you have a shell or a boiler plate or a template which you can just plug in a bunch of values and have it set up the way you want so what's a really good example of a class well a great example which we'll also build upon when we go to use the inheritance is a person so think about what a person is right really we're a template and all that's been injected into us is different types of dna to be able to have a unique individual but really in our fundamental or in its fundamental sense we are we could be formed as a class so let's actually create a class for a person so what we're going to do is first up write class and this is the statement that we need to pass through to specify the fact that we're creating a class and then we're going to call it person and then close it with parentheses and hit colon and i'm just going to add in a few spaces so again as per python syntax in order to write anything under our class we need to hit tab and indent it so in this case that indenting looks a little bit weird so that it's now indented so what have we wrote written so far so i'm pretty lightweight at the moment i've written class and then person and you can see here that i've written it in capital so again this is just a preference i like writing it in cap so i know what is actually a class and then i've gone and written uh what have we gone as we've put in parentheses and then a colon so then what we can do is define a couple of things now the first thing that you need to define whenever you're defining a class is a method or a function called init so if we type in def underscore underscore init underscore underscore and then parentheses and then colon this is the method the method that runs as soon as you you create a class so as soon as we start using our template when we first run it the init method is going to run now you're probably thinking hey nick this looks really really similar to a function right so we covered functions already why why are you calling this method the methods that we're defining here or the function that i'm actually defining here is a specific function which is attached to a class that's why we call it a method now classes are typically combined of two key things you're going to have methods attached to them and these are like functions that are attached to a specific class and then they'll also have attributes or properties so these are values that are attached to a specific class now i'll show you how to get these out and how to use methods and how to get properties or values but let's actually go on a little bit further now when we are defining our class the first thing that we need to do is pass through the variable self this is basically telling us that we are going to pass through this instance of this class through this init function now self is a little bit of a weird concept but you've got to keep in mind that when you're creating a class you're creating a new instance of an object so you want it some way to refer to this particular object and that's where the self keyword comes in so when we use self we're basically saying hey we are using the current methods for this instance of this class in this particular case all right so we've written def and then underscore underscore init and then underscore underscore and then inside of parentheses we've passed through our first argument which in this particular case is going to be self then we want to pass through a couple of different parameters to our person because remember a person or in this particular case our person class is like a template so what are some unique characteristics for people well we're going to pass through name we're also going to pass through their age and we're also going to pass through their favorite color we'll just call it color in this case so right now this is pretty much a function but it's a specific type of function which is a method and it's a specific method which is attached to a class called init and remember init so it's short for initialize or initialization initialize it's going to run as soon as you go and create your in new instance of your class cool all right so now what we need to do is we need to take these parameters that we've gone and defined here so name age and color and we need to assign it to our class because right now these are just arguments that we're going to be passing through to our init function so how do we set these up well what we're going to do is we're going to assign them as attributes so i'm going to create a new comment and say we are going to create some attributes for our person class and the way to create an attribute is to specify self and then whatever that you want that name of that attribute to be so in this case we'll specify self.name and then we'll set it equal to the argument that we're getting from our init method so we're going to set it equal to name and then we're going to create another attribute so self dot age and we're going to set that equal to age and then we're going to create a last one self.color we're going to set that equal to color right so that is if we did nothing else that is a class now initialized or that is a class now defined not initialized so if i go and run that cell you can see that it's gone and run now if i wanted to go and create an instance of this class because remember our class is like our boilerplate or our template how do we actually go and create a an actual person now so we can go and say new person so we're going to create a variable and we are going to assign it so it equals our person class so we're going to type in person and then we need to pass through a couple of key arguments and these are the arguments that the init function is expecting so we don't need to pass through anything for self because our class is aware of itself so we just need to pass through our name our age and our color so in this case let's go and do i don't know elon so elon musk pass through our age and we're going to say i don't know i don't know how old he is let's say let's let's keep it on the low side so i don't don't make him feel bad we'll say 38 i don't know and then his favorite color is blue right so that is a new person now created now remember a person is like a template so what we can actually do with this template is we can actually go and extract these attributes remember name age and color so if i go and type in new person dot name that is me accessing an attribute let's add some commentary so accessing a class attribute and you can see there that i'm actually accessing that person's name so new underscore person dot name is giving me the name for that particular person right now we can also access our age and we can also access our color just by changing the value after dot pretty cool right now the beauty of this is that it is repeatable right so if we wanted to go and add additional attributes or if we wanted to go and add additional parameters we could definitely do that as well in this case we've created a really simple one so now what are we going to do so that is our baseline method so we've gone and defined our init function and again this is required when you go and create a class so you need to have an init function in order to set up your variables the next thing that we might want to do is let's say for example calculate the year of birth right and again we're going to do a really simple calculation so what we can do is we can actually create custom methods inside of our class so we can go back into our person class and now what i'm going to do is create another method so let's add a comment and we're going to create a method to calculate that date of birth so create oh let's actually say date of birth method and we are going to again we're going to define a function so def and then this time we don't need to specify underscore underscore init this is a built-in function for classes we don't need to do it for our other methods so what are we going to do we're going to call it uh year of birth and then we just need to pass through self so that this function or this method here has access to these attributes here because we're going to need this age value right and then finish off our function with a colon and then what we want to do is we want to return the year of birth so we're going to specify return and then we're going to keep it pretty simple and not fully parameterized in this particular case so we're going to return uh what are we doing so 2021 minus self dot age right so let's actually take a look at what we've written here so we've gone and defined a new method and remember it's a method because it's inside of a class and our new method is called year underscore of underscore birth and then to that we're going to be passing through our current instance of our class remember this allows us to access our attributes from within different methods and then we've gone and specified that this function is going to be really simple we're just going to return 2021 minus the person's age and remember this age is an attribute that we set up originally so if we go and hit shift enter now that is our person value oh that is our person class now updated so what can we do now now we can actually go and calculate their year of birth and remember so we haven't actually gone and passed through any additional arguments to this right so if we go and run this method now we're going to get our we should get our year of birth back so if we go and run it on a line again so i'm just going to recreate it so hit shift enter and then for our new underscore person we can now go and run our method that we just went and created so i'm going to type in new let's actually create a comment so we are going to run a method so if i type new underscore person dot and then this is the difference between using or accessing an attribute versus actually running a method so when we run a method we have to close it inside of parentheses so we're going to pass a year of birth and then add parentheses and then if i hit shift enter we are now getting our year of birth so again this is actually doing something now so we're not just accessing an attribute we're actually performing a calculation on some sort of value so again this could be repeatable another great application of this is say you were say you're doing something with layers like neural network layers actually what's a better one say you wanted to consistently create a pandas class right or create a specific data set for your model you might actually set up your data set as a class and actually have specific attributes and specific methods attached to that so say for example you knew that you consistently needed to bring in your data set from some random source you then needed to go and pre-process it but not always you then wanted to go and push it out somewhere right you would actually set up this class as say for example class and then data set inside of your initialization function you might choose to set your attributes and then you might also choose to go and bring in your data from wherever it might be you might then choose to have another method which is say for example export data set or import data set so you could actually structure this so you've got a repeatable set of steps that you can then go and run now so what have we gone and done there so we've gone and defined a class and this is allows us to work with object-oriented programming inside of python we've gone through how we can use the init method to set up our initial set of values there and we've also gone and defined our initial method now we can also define different methods so say for example we wanted to pass values to our method we can do that as well so what are we going to do this one say for example rather than just calculating year of birth say for example we wanted to project how old they were going to be let's actually create a method for this so we're going to add in a comment a projected age and we're again going to define a method so def and then i'm going to type in projected age so this is going to be the name of our method and remember we're going to be able to access that similar to this this time however we're again going to pass yourself but we're also going to take in a value for our projected age so we are going to pass through a keyword argument and remember there's a difference between arguments and keyword arguments or positional arguments and keyword arguments positional arguments order matters and they need to go before your keyword arguments keyword arguments have a predefined value and they can go in any order as long as they're after positional arguments so we are going to say um i don't know what's how let's add in a new argument we're going to set it equal to years and five so this is basically going to be the default so if we type in project underscore age this is going to take the person's age and add on five right so we're going to create a new keyword argument called years and set the default equals to five and then what we're going to do is we are going to return self dot age plus years yes and so this gives us the ability to pass through additional values and again pass through parameters to our specific class so if we go and run this now uh we need a colon there let's actually take a look at that error so basically we've got a syntax error and it's saying invalid syntax and it's on line 15. so 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15. so we've got an error on this line and it's pointing towards the end and that is because we don't have a colon there and if we shift enter all good no issues now let's go and create our class again but this time we're going to use a method that we are passing a value to so in this case our default is going to be 5 but we can also pass through our own value if we want to do or project a different age range so if we go and hit shift enter on our new class so we've got our color we've got our year of birth now let's actually run our project age method so if i type in new underscore person got project age you can see that it's projecting a person's age as 43 and this is basically saying that in five years elon is going to be 43 now we can pass through our own values to say for example we said years equals 10 you can see that we're now passing through a new keyword value or new keyword argument to go and project our age at a little bit further and again we can add in a comment because it's good practice guys comment your code so we're going to say run a method with a keyword argument pretty cool right and so again this is really really important because you'll often encounter classes with methods and with attributes and it's important to know how to access an attribute versus how to actually go ahead and run a method and this makes it super easy once you've got a good understanding of this the world's really your oyster when it comes to python so getting this down pat and makes your life a whole lot easier so that in a nutshell is how to create a class so let's take a look at what we've done so we went and created a class and our class in order to define it we just need to write class and then the name of the class we then went and defined a initialization method so we write d e f underscore underscore init and then pass through self because we want to refer to our current instance of our class or this particular instance of our template pass through a bunch of positional arguments and we went and set those as attributes we then went in to find a method and remember a method is a function attached to a class and this particular method is called year of birth and again we're passing through our self because we want to be able to reference this current instance of the class and that one's just returning a person's age to 2021 minus the person's age from our class and remember we can access our attributes from within our class as well so remember self.age is going to be able to get this value up here and then we also created a new method called project underscore age and this one is taken through a keyword argument and remember we need to pass through self that's our first positional argument that we need to be passing through and then we're going and specifying a keyword argument which in this case is years and so this gives us the ability to do this and be able to pass through additional values to our methods when we're actually going ahead and creating our classes to create a new class we need to define that particular class or in this case we need to specify that we're creating a instance of that class so person and then we pass through the positional arguments that are required inside of the initialization function so in this case we're passing through name elon age 38 favorite color blue then we can access our class attributes so again we can type in the instance of that person or the instance of that class remember the instance of the class that we just went and created is called new underscore person so to get our attribute we need to pass through the attribute value and remember it's separated by a dot so new person dot and then you can there was yours so grab whatever you want so in this case we're grabbing color but we could also easily grab the name grab the age so that's the way to access your attributes and we can also access all of the methods so we can type in the instance of that class a new underscore person and then we can run that specific method so again separated by a dot and then we call the method so year underscore of underscore birth and then pass through a set of parentheses to get our person's year of birth then we can also specify our methods and pass through keyword arguments to those all right i think we're doing pretty well so let's take a quick break and let's have a look to see who's talking who's he up what's happening power cube yeah it's super hard not to look at the chat while i'm coding thanks so much jack thanks for tuning in [Music] thanks express this is a really good question so we just got a question so why use um self.age over here instead of just using age keep in mind that this variable is going to be available within our initialization function we want this age value to be available across the board so by setting it through as an attribute where establishing good practices and we're also ensuring that we are referring to the variable that we've defined as part of our class so using self.age is going to mean that we're grabbing the specific variable that is attached to that class um what's happening guys comment your code yes always no power cube never is not the right answer always comment your code it's good practice alrighty we are going to keep powering through so we've now gone and defined our class i'm not going to go through it again because we've done it the next thing that we are going to go ahead and do is perform something called inheritance so this is really really important so inheritance should probably be a separate section but we'll include it still here say for example we want to extend our class right so in this particular case our class is a person what happens if we had specific types of people that we wanted to go and define let's say we had a formula one driver they might have some additional attributes say for example they might have a specific license that they have they might have specific cars that they've driven in our particular case what happens if we wanted to define a class for an astronaut well we've already gone to all the hard work to actually go and define a person so why can't we just take all the attributes and methods that are attached to a person and attach those to an astronaut but then we just add some extra stuff to our astronaut to build it out doing this is actually known as inheritance so basically we can take an existing class and take all of the good stuff inside that class and just add in the extra things that we need so this means that we don't have to go and redefine the entire class every single time and when we go and update our base class which in this case is our parent class which is a person these are going to flow through to eventually will flow through to our child class so in this particular case that's an important thing to note so this is going to be a parent class and what we're going to do is we're going to inherit or our child class is going to inherit all of these attributes and values so important thing to note so a parent is the person or is the class passing down attributes and methods and your let's add in another comment there and your child class is the class inheriting the methods and attributes so this is really really useful when you have frameworks that you're using that you want to sort of base on so if you actually go through to the 10th this is where i actually use this this week you actually go to the tensorflow functional api documentation for deep learning when you're actually going to find custom layers or custom models what you actually do is you use inheritance to access all of the attributes and the methods that are available to existing tensorflow models and tensorflow layers so you might think nick i'm probably never going to use this trust me now you will definitely use this or you'll at least see it at some point as you go through your data science journey so understanding inheritance is super useful so what we're going to do is we're going to step into our cell we're going to give us a little bit more room to breathe so i'm just going to hit shift enter and actually let's convert this cell to markdown so we've already got classes let's actually do inheritance so i'm going to hit escape out of this hit m and i'm going to get rid of these pound symbols just hit dash dash so we can have some dot points and we don't need this in caps because that's aggressive in hairy tense and this is going to be section 6. cool all righty so now what are we going to do so we're going to create our astronaut class and our astronaut is going to be our parent class so or sorry astronaut is going to be our child class so this is going to equal astro nought and our parent class is going to be person so this means that we don't need to go and redefine all of these parameters name age color our child class is going to be automatically able to inherit from that particular class so again we define it as per usual so we're going to create a class and we are going to call it astronaut so class astro nought but this time what we're going to do is we're going to pass through our parent class which in this case is person and then we're going to hit colon so that's the main difference so now we're going to be inheriting from the person class which is this class over here then we're going to create a new line and again as per usual we're going to define our init function initialization function so def underscore underscore init underscore underscore and then this time we are going to again pass through self self but we're also going to pass through a couple of additional values now key thing to note is that we still need to pass through the values that our in child or that our parent class is expecting so name age and color so let's first define those the name age color but now what we can also do is we can also pass through some additional arguments so we'll actually define um what's a good one so how long the astronaut's mission is going to be so the emission length for example is emission length and we'll do it in months in months and then close our init function and then what we're going to do is we're first up going to set up a class so that it inherits from our person so to do this we actually use the super method so super and then dot init and then we're going to pass through our name our age and our color so what this is actually doing is this is actually telling our child class in this particular case our astronaut to inherit all the stuff from person so that we then have name age and color available as attributes this is inheritance in a nutshell so this if you take nothing else away from this this this is what gives us inheritance super method just remember superman that's how i've got it in my memory path if you haven't checked out that video do check that out but the visual cue that i've got to remember that is just remembering superman doing random stuff so super allows us to inherit from our parent classes now the next thing that we're going to do is create a another attribute so we're going to save our mission length in months as an attribute so self dot mission length and then we'll say months equal to this value here cool so that is our astronaut class now defined so what we can then do is create a new astronaut so we'll say new astronaut and again to define our class we'll create our class we're just going to type it out and then we're going to pass through all of the positional arguments that we need or as defined by init function so we're going to pass through i don't know let's say i'm an astronaut so nick my age let's say 99 let's say our color have unknown purple and mission length in months let's say i'm going away from a while uh 48 months right i'll just stream from space what we can then do is access all of the existing attributes as well as methods so if i type a new astronaut dot you can see that i've actually got all of the same attributes let me bring that a little bit further down i've actually got all of the attributes that are were attached to my person class now attached to my astronauts remember we didn't actually go and define the age uh the age attribute or the what were the other methods or the project age or the year of birth methods we actually just inherited those from our person class this is inheritance in a nutshell so this means that we don't need to go and redefine old so that's our age method bit of a shame in it that's our h method that's our name method oh that's our name attribute um and then what else do we have color so you can see that we can actually access all of these attributes from our parent class which makes it a whole heap easier we don't need to go and define all of these custom classes every single time so again i've used this a ton of times and you'll probably use it when you do get to this specifically for deep learning when we're inheriting different components from layers or inheriting different components from other models this makes your life a ton easier now again we could also create a specific method so again let's actually just go through so we can use color and so this is accessing let's say access parent like e-a-r-e-n-t parent-like attribute uh and then we're gonna specify our method so new astronaut dot and let's uh what's a year of birth that means i was technically born in 1922 based on my age being 99. now we could also go and extend out our method so let's go on ahead and do that so we are going to add what are we going to do let's actually calculate their age on return so how old would i actually be in return so we're going to create a new method called age or df let's actually add that comment first a method for calculating age on return gonna specify new methods a def age on return and pass through self and we are going to again we don't actually need to pass anything through because we already have our mission length in months and we already have our age so what we are going to do is we are going to project our age right so this is the cool things that about this is that we don't actually need to go and create a full new function to actually do this we can actually use our existing project on age or project age method that we had from up here so i can type in return self dot project age so this gives us the ability to access the methods from our parent class as well because remember we've gone and used our super function or super what is that super function to be able to go and inherit from our parent class so by typing in self.project age i'm actually accessing this method over here from our parent class then what i can do is pass through um what do we need so self dot mission length in what did we call it mission length month and then divided that by 12 because right now our project age method is expecting the number of years to be passed through actually we need to specify this this as years equals so let's go on ahead and test that out let's make sure we've done that right reject age yes okay cool so let's actually test out that method now so if we type in uh let's create it again boom boom new astronaut dot on return yup so we've got an error there and that's just me typing way too fast so you can see it's on line one and it's saying syntax error unmatched parentheses that's because we need one of these beforehand and delete that one and you can see that is projecting our age on return so you can see there that we've returned 103.0 now remember right at the start we said that we could do something called typecasting so how might we actually convert this into an integer rather than a float well we can go on ahead and wrap it well we let's wrap this so we can wrap the value that we're passing through so int and if we can run it again now you can see that we're just returning 103. so that in a nutshell is inherited so we've gone through that reasonably quickly but let's go ahead and take a step back and take a look at what we did so we went and created a child class remember inheritance allows a child class to inherit a number of attributes as well as methods from a parent class in this particular case our parent class is our person and our child class is our astronaut so basically our astronaut class is going to be inheriting our age attribute and a bunch of the methods that we define as part of our person class then to define a child class we can type in class again so as per usual but then we're going to pass through the parent class that we want to inherit stuff from and again this just makes it easier and reproducible it also means that you have less code so a big thing about writing code is that you want to write stuff that's going to be as modular and as reproducible as possible so this is really where classes come in handy what was i saying so i've passed through the person to our child class and then we've gone and again defined our initialization function over here we've then gone and defined a super method or a super function which allows us to inherit from our parent class and we need to pass through the arguments that we want to use in that particular case and then we're going and passing through creating a new attribute in this case mission underscore length underscore months and we're going and extending out one of our functions so we're actually accessing one of the methods from our parent class and doing a little bit of and we're actually using this or attaching that particular method to another method so our age on return method is actually just using as project age method from our person class which is up here so again that gives us the ability to not have to write this all over and then when we're going and defining our tribe class again it's exactly the same so when you actually go and initialize it it's going to look no different to you actually just using the base class apart from the fact that you need to pass through all of the new positional arguments that you would have had to inside of the parent class as well as the child class so in this case these classes or these arguments over here these are actually arguments that are required for the parent class remember this is our name our age and our color and this is required by person class so name agent of color but we've also tacked on the mission length in months up here as well then again we can access the attributes and we can also access methods again comment your code access the methods and then run a method and that in a nutshell is classes so we've gone through a bunch of stuff so we specifically went through how we can define a class and remember you need to use the class statement and then you need to have an initialization method to be able to go and set up your attributes you can then go and attach a number of methods we also took a look at inheritance and this basically makes our code more reproducible and more modular so we can go and use it over and over and over again so we could also go and create a new child class called i don't know formula one driver or lawyer or accountant and have specific attributes and specific methods that are attached to that particular child class cool all right that is it in a nutshell let's take a look at some comments what's happening power cube you got me a bit of a shame in it thanks so much for zk blen thanks shadow slayer hero hey thanks for checking it out jose my gpu is 72 degree selfies this ouchy thanks so much cool rock glad you enjoyed it any additional questions guys shoot them through it's just water today no beer thanks so much for checking it out chen yeah so the data science tutorials we're definitely going to be going further into all of this stuff so again this is just basic so everyone can go up to speed question so we can we access the attributes of a method to another method if they are in the same class can we access the attributes so you can access the attributes of so you can actually go and set use a method to go and set an attribute value if that's what you're talking so yeah so that would mean that you can actually do something as part of your method and then return it back and have it as a attribute inside of your class so yeah you could do that as well cool all right no it doesn't look like we've got any additional questions so maybe let's wrap it up move this out of the way so again thanks so much for tuning in guys hopefully you enjoyed the video if you did be sure to give it a big thumbs up hit subscribe and tick that bell and again let me know if there's anything else you'd like to see hopefully you've enjoyed this tutorial thanks again
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Nicholas Renotte · Nicholas Renotte · 0 of 60

← Previous Next →
1 Face Detection - Build An Image Classifier with IBM Watson - Part 7
Face Detection - Build An Image Classifier with IBM Watson - Part 7
Nicholas Renotte
2 Food Image Classification - Build An Image Classifier with IBM Watson - Part 6
Food Image Classification - Build An Image Classifier with IBM Watson - Part 6
Nicholas Renotte
3 General Image Classification - Build An Image Classifier with IBM Watson - Part 5
General Image Classification - Build An Image Classifier with IBM Watson - Part 5
Nicholas Renotte
4 Installing Watson Developer Cloud - Build An Image Classifier with IBM Watson - Part 4
Installing Watson Developer Cloud - Build An Image Classifier with IBM Watson - Part 4
Nicholas Renotte
5 Generating Credentials - Build An Image Classifier with IBM Watson - Part 3
Generating Credentials - Build An Image Classifier with IBM Watson - Part 3
Nicholas Renotte
6 Creating A Service - Build An Image Classifier with IBM Watson - Part 2
Creating A Service - Build An Image Classifier with IBM Watson - Part 2
Nicholas Renotte
7 Getting an IBMid - Build An Image Classifier with IBM Watson - Part 1
Getting an IBMid - Build An Image Classifier with IBM Watson - Part 1
Nicholas Renotte
8 How to Analyse Review Data - Part 2 - Python Yelp Sentiment Analysis
How to Analyse Review Data - Part 2 - Python Yelp Sentiment Analysis
Nicholas Renotte
9 How to Lemmatize Text - Part 4 - Python Yelp Sentiment Analysis
How to Lemmatize Text - Part 4 - Python Yelp Sentiment Analysis
Nicholas Renotte
10 How to Calculate Sentiment Using TextBlob - Part 5 - Python Yelp Sentiment Analysis
How to Calculate Sentiment Using TextBlob - Part 5 - Python Yelp Sentiment Analysis
Nicholas Renotte
11 How to Collect Business Reviews Using Python - Part 1 - Python Yelp Sentiment Analysis
How to Collect Business Reviews Using Python - Part 1 - Python Yelp Sentiment Analysis
Nicholas Renotte
12 How to Clean Text Based Data for NLP - Part 3 - Python Yelp Sentiment Analysis
How to Clean Text Based Data for NLP - Part 3 - Python Yelp Sentiment Analysis
Nicholas Renotte
13 How to Setup a IBM Watson Personality Insights Service - Part 1 - Watson Personality Insights
How to Setup a IBM Watson Personality Insights Service - Part 1 - Watson Personality Insights
Nicholas Renotte
14 How to Create a Customer Profile with IBM Watson - Part 2 - Watson Personality Insights
How to Create a Customer Profile with IBM Watson - Part 2 - Watson Personality Insights
Nicholas Renotte
15 Visualising The Profile   Part 3   Watson Personality Insights
Visualising The Profile Part 3 Watson Personality Insights
Nicholas Renotte
16 How to Plot Personality Insights Features at Lightspeed - Part 4  - IBM Watson Personality Insights
How to Plot Personality Insights Features at Lightspeed - Part 4 - IBM Watson Personality Insights
Nicholas Renotte
17 Getting Started With IBM Watson Studio Machine Learning - Part 1 - Predicting Used Car Prices
Getting Started With IBM Watson Studio Machine Learning - Part 1 - Predicting Used Car Prices
Nicholas Renotte
18 Upload and Visualize Data In IBM Watson Studio - Part 2 - Predicting Used Car Prices
Upload and Visualize Data In IBM Watson Studio - Part 2 - Predicting Used Car Prices
Nicholas Renotte
19 Clean Data and Feature Engineer in IBM Watson Studio - Part  3 - Predict Used Car Prices
Clean Data and Feature Engineer in IBM Watson Studio - Part 3 - Predict Used Car Prices
Nicholas Renotte
20 Using Watson Model Builder to Predict Car Prices - Part 4 - Predicting Used Car Prices
Using Watson Model Builder to Predict Car Prices - Part 4 - Predicting Used Car Prices
Nicholas Renotte
21 Deploy and Make Predictions With Watson Studio - Part 5 - Predicting Used Car Prices
Deploy and Make Predictions With Watson Studio - Part 5 - Predicting Used Car Prices
Nicholas Renotte
22 Getting Started With IBM Watson Discovery - Part 1 - Stock News Crawler
Getting Started With IBM Watson Discovery - Part 1 - Stock News Crawler
Nicholas Renotte
23 How to Run Advanced Queries with Watson Discovery - Part 5 - Stock News Crawler
How to Run Advanced Queries with Watson Discovery - Part 5 - Stock News Crawler
Nicholas Renotte
24 How to Run Search Queries with IBM Watson Discovery - Part 4 - Stock News Crawler
How to Run Search Queries with IBM Watson Discovery - Part 4 - Stock News Crawler
Nicholas Renotte
25 How to Understand the Watson Discovery Data Schema  - Part 3 - Stock News Crawler
How to Understand the Watson Discovery Data Schema - Part 3 - Stock News Crawler
Nicholas Renotte
26 How to Build a Watson Discovery Web Crawler - Part 2 - Stock News Crawler
How to Build a Watson Discovery Web Crawler - Part 2 - Stock News Crawler
Nicholas Renotte
27 AI learns what to do next using Tensorflow and Python
AI learns what to do next using Tensorflow and Python
Nicholas Renotte
28 Chatbot Crash Course for Absolute Beginners - Full 20 Minute Tutorial
Chatbot Crash Course for Absolute Beginners - Full 20 Minute Tutorial
Nicholas Renotte
29 Shopify Customer Service Chatbot using Python Automation
Shopify Customer Service Chatbot using Python Automation
Nicholas Renotte
30 Building a Reddit Keyword Research Chatbot
Building a Reddit Keyword Research Chatbot
Nicholas Renotte
31 Chatbot App Tutorial with Javascript Node.js [Part 1]
Chatbot App Tutorial with Javascript Node.js [Part 1]
Nicholas Renotte
32 Javascript Chatbot From Scratch with React.Js [Part 2]
Javascript Chatbot From Scratch with React.Js [Part 2]
Nicholas Renotte
33 Predicting Churn with Automated Python Machine Learning
Predicting Churn with Automated Python Machine Learning
Nicholas Renotte
34 Sales Forecasting in Excel with Machine Learning and Python Automation
Sales Forecasting in Excel with Machine Learning and Python Automation
Nicholas Renotte
35 Automate Budgeting with Python and Planning Analytics
Automate Budgeting with Python and Planning Analytics
Nicholas Renotte
36 AI vs Machine Learning vs Deep Learning vs Data Science
AI vs Machine Learning vs Deep Learning vs Data Science
Nicholas Renotte
37 Optimizing Marketing Spend using Linear Programming || Marketing Opt PT.1
Optimizing Marketing Spend using Linear Programming || Marketing Opt PT.1
Nicholas Renotte
38 Solving Optimization Problems with Python Linear Programming
Solving Optimization Problems with Python Linear Programming
Nicholas Renotte
39 Loading Data into Planning Analytics with Python || Marketing Opt PT.2
Loading Data into Planning Analytics with Python || Marketing Opt PT.2
Nicholas Renotte
40 Building Marketing Dashboards with Planning Analytics Workspace || Marketing Opt PT.3
Building Marketing Dashboards with Planning Analytics Workspace || Marketing Opt PT.3
Nicholas Renotte
41 Optimizing Resource Allocation with Docplex and Planning Analytics || Marketing Opt PT.4
Optimizing Resource Allocation with Docplex and Planning Analytics || Marketing Opt PT.4
Nicholas Renotte
42 Exploratory Data Analysis With Pandas || Python Machine Learning PT.1
Exploratory Data Analysis With Pandas || Python Machine Learning PT.1
Nicholas Renotte
43 Preparing Pandas Dataframes for Machine Learning || Python Machine Learning PT.2
Preparing Pandas Dataframes for Machine Learning || Python Machine Learning PT.2
Nicholas Renotte
44 Python Machine Learning with Scikit Learn - Regression || Python Machine Learning PT.3
Python Machine Learning with Scikit Learn - Regression || Python Machine Learning PT.3
Nicholas Renotte
45 Deploying Machine Learning Models with Watson Machine Learning || Python Machine Learning PT.4
Deploying Machine Learning Models with Watson Machine Learning || Python Machine Learning PT.4
Nicholas Renotte
46 Mind Blowing Machine Learning Apps with Node.JS and Watson Machine Learning || Python ML PT.5
Mind Blowing Machine Learning Apps with Node.JS and Watson Machine Learning || Python ML PT.5
Nicholas Renotte
47 Build FAST Machine Learning Apps with Javascript React.Js and Watson || Python ML PT.6
Build FAST Machine Learning Apps with Javascript React.Js and Watson || Python ML PT.6
Nicholas Renotte
48 Analyzing Twitter Accounts with Python and Personality Insights
Analyzing Twitter Accounts with Python and Personality Insights
Nicholas Renotte
49 Converting Speech to Text in 10 Minutes with Python and Watson
Converting Speech to Text in 10 Minutes with Python and Watson
Nicholas Renotte
50 Build a Face Mask Detector in 20 Minutes with Watson and Python
Build a Face Mask Detector in 20 Minutes with Watson and Python
Nicholas Renotte
51 AI Text to Speech in 10 Minutes with Python and Watson TTS
AI Text to Speech in 10 Minutes with Python and Watson TTS
Nicholas Renotte
52 Pandas for Data Science in 20 Minutes | Python Crash Course
Pandas for Data Science in 20 Minutes | Python Crash Course
Nicholas Renotte
53 Language Translation and Identification in 10 Minutes with Python and Watson AI
Language Translation and Identification in 10 Minutes with Python and Watson AI
Nicholas Renotte
54 Analyse ANY Conversation in 10 Minutes with Python and Watson Tone Analyser
Analyse ANY Conversation in 10 Minutes with Python and Watson Tone Analyser
Nicholas Renotte
55 Deep Reinforcement Learning Tutorial for Python in 20 Minutes
Deep Reinforcement Learning Tutorial for Python in 20 Minutes
Nicholas Renotte
56 NumPy for Beginners in 15 minutes | Python Crash Course
NumPy for Beginners in 15 minutes | Python Crash Course
Nicholas Renotte
57 Real Time Pose Estimation with Tensorflow.Js and Javascript
Real Time Pose Estimation with Tensorflow.Js and Javascript
Nicholas Renotte
58 Transcribe Video to Text with Python and Watson in 15 Minutes
Transcribe Video to Text with Python and Watson in 15 Minutes
Nicholas Renotte
59 Serverless Functions for TM1/Planning Analytics in 20 Minutes
Serverless Functions for TM1/Planning Analytics in 20 Minutes
Nicholas Renotte
60 Building a AI Budget Bot for Planning Analytics with Watson Assistant in 20 Minutes
Building a AI Budget Bot for Planning Analytics with Watson Assistant in 20 Minutes
Nicholas Renotte

This video teaches object-oriented programming concepts in Python, including classes, inheritance, attributes, and methods. It demonstrates how to create custom classes, use inheritance to extend existing classes, and access attributes and methods within a class.

Key Takeaways
  1. Open Jupyter Notebook and create a new section
  2. Define a class using the class statement
  3. Use an initialization method to set up attributes
  4. Attach methods to a class
  5. Use inheritance to make code more reproducible and modular
  6. Access attributes and methods within a class
  7. Create a child class that inherits from a parent class
  8. Use the super function to access methods from the parent class
  9. Define a new method that calculates a specific value
💡 Inheritance allows you to take an existing class and add extra attributes and methods to create a new class, making code more reproducible and modular.

Related Reads

📰
I Cut 1,300 Lines of CLAUDE.md — My Token Bill Dropped 75%
Optimize your CLAUDE.md file to reduce token spend by 75% without deleting rules
Medium · Programming
📰
Anthropic Just Dropped a Banger on “Loops” and It Quietly Changes How You Should Use Your Coding…
Learn how to use coding agents like Claude effectively with the new 'loops' concept from Anthropic
Medium · Programming
📰
AI CLI Tools Are Eating Each Other's Lunch
AI CLI tools are becoming increasingly similar, making it difficult to choose between them, and their failure patterns are identical, highlighting the need for more transparency and accountability in AI development
Dev.to · Tracepilot
📰
Loop Engineering: The Skill That Just Made Your AI Workflow Obsolete
Learn how loop engineering can automate AI workflows, making traditional prompting methods obsolete
Medium · Machine Learning
Up next
Copilot Cowork: Setup, Skills, Plugins & Pricing
Matt Tutorials
Watch →