Intro to OOP (Part 2)

Continuing my journey through OOP has brought me to the self parameter and the __init__ method.

The self parameter is required in every method of a class.  In OOP, a method operates on a specific object’s data attributes.  When a method executes, it must have a way of knowing which object’s data attributes it is supposed to operate on.  That’s where the self parameter comes in.  When a method is called, Python makes the self parameter reference the specific object that the method is supposed to operate on.  When a method is called, Python automatically passes a reference to the calling object into the method’s first parameter.  As a result, the self parameter will automatically reference the object on which the method is to operate.

__init__ is commonly known as the initializer method because it initializes the object’s data attributes.  __init__ is automatically executed when an instance of the class is created in memory.  The __init__ method is usually the first method inside a class definition.

class Fish():
def __init__(self, type):
self.type = type

trout = Fish("trout")

  1. An object is created in memory from the Fish class.
  2. The Fish class’s __init__ method is called, and the self parameter is set to the newly created object.
  3. After these steps take place, a Fish object will exist with its type attribute set to the argument passed to the class (in this case trout).
  4. the = operator assigns the Fish object that was just created to the trout variable.
  5. the trout variable will reference the Fish object, and that object’s type attribute will be assigned the string “trout”
Posted in Uncategorized | Tagged , , , | Leave a comment

Intro to OOP

I’ve been learning and coding with Python for roughly four years now. But one of its greatest features, object oriented programming, is something that I have never really understood. Starting in March of this year, I taught
a Python class at the University of San Francisco (USF) to business students. I did not talk about OOP during this class but it got me thinking, if I am to be an ‘expert’ of this language and teach it to students, then maybe
OOP is something that I should know like the back of my hand. So yesterday, Monday May 14th, I whipped out the text book being used for the class, and started to plough through the OOP chapters. The textbook is Starting Out
With Python by Tony Gaddis. Turns out Gaddis is a master when it comes to writing textbooks. Anyway, here is an overview of my learnings from OOP in Starting Out With Python.

Up until now, I have been programming procedurally, meaning a program was made of one or more procedures. Whereas procedural programming is centered on creating procedures (functions), OOP is centered on creating objects.

Objects is a software entity that contains both data and procedures. the data contained in an object is known as the object’s data attributes. This is simply variables that reference data. The procedures that an object performs are
known as methods. An object’s methods are functions that perform operations on the object’s data attributues. Conceptually speaking, the object is a self-contained unit that consists of data attributes (data) and methods (functions)
that operate on the data attributes.

OOP addresses the problem of cose and data separtion through excapsulation, the combining of data and code into a single object. Only the object’s methods may directly access and make changes to the object’s data attributes.

A class is code that specifies the data attributes and methods for a particular type of object. Think of a class as a blueprint from which objects may be created, much like a blueprint for a house. The blueprint itself is not
a house, but is a detailed descripion of a house. When used to build an actual house, I could say I am building an instance of the house described by the blueprint. I can build multiple identical houses from the same blueprint.
Each house is a separate instance of the house described by the blueprint. In summary, the blueprint is a class and the house(s) is/are the object(s)

A simple example I’ve created of this is with a class named Fish. This class specifies characteristics that are common to all types of fish and used to create objects. Next, I create an object names salmon, which is an instance
of the Fish class. The salmon object is an entity that occupies computer memory and stores data about a salmon. It has the data attributes and methods specified by the Fish class. I then create another object named halibut.
Again, the halibut object is an instance of the Fish class. It has its own memory and stores data about a halibut. Although these are two different objects, they were both created from the same Fish class and therefore
means that each of the objects has the data attributes and methods described by the Fish class.

To be continued ….

Posted in Uncategorized | Leave a comment

The Resistance

Just do a damn Kaggle competition……..
This is what I have been telling myself to do for the past couple of years.  but to no avail, I did not.  I would spend the time doing half assing another online tutorial of the same material I have already learned.  it was the resistance that was keeping me from actually doing something.  I learned about the Resistance in Stephan Pressfeilds book “The War on Art”.  In short, the resistance is what holds us back from starting a creative project and/or doing something new.  Its always the starting part that is the hardest and where the resistance hits the hardest.  Its always “I’ll check my phone again or email” etc.
With me, the Resistance has kept me from presueing a career in Data Science/Machine Learning.  I got started in this journey a few years back while in graduate school, where I got a solid foundation in data analytics and machine learning algorithms.  After I graduated I knew I wanted to shift my career into this field.  However, that is where the resistance hit.  Not having any work experience in this field, it was hard to get my foot in the door.  The Recommendation was to “create projects” or do kaggle competitions.  Everytime I started to do one of these, I quickly shifted and put this off.
Fast forward a couple years to now, I have made zero progress except completing a couple tutorials and throwing together a couple Tableau dashboards.  But no longer will this be an issue.  I am finally going to conquer the resistance and pursue the career that I want.  Here is my detailed plan to achieve this:
  1. As the first line says, join a Kaggle competition.  Don’t worry about how you place, just DO IT!!!!!!!
  2. Read all the text books I have on the subject concurrently to the above.
    1. List of books I have:
      1. Artificial Intelligence
      2. Machine Learning
      3. Introduction to Algorithms
      4. Deep Learning
      5. Applied Predictive Modeling
      6. An Introduction to Statistical Learning
      7. The Elements of Statistical learning
      8. Data Mining
  3. Bring this knowledge to my current job.
    1. Already working on a predictive algorithm to forecast interchange rates
  4. Finally, blog about the journey
    1. Spending money on wordpress will help conquer the resistance by having skin in the game
Please come along on this journey with me and I hope you enjoy the ride!


Posted in Uncategorized | Leave a comment