[Tutor] Learning Object Oriented Programming

avi.e.gross at gmail.com avi.e.gross at gmail.com
Sat Jun 11 17:42:06 EDT 2022


Alan,

My first post was moderated and I have not received a copy here showing me
it was shared. My main point was not that some aspects could not be
discussed here but that others would be better done elsewhere or 1:1 with
someone as this forum is dedicated for other purposes. I am adding or
expanding on some of what you wrote as I have no disagreement.

The part I found relevant was asking what aspects of Python the language to
focus on for some purpose, albeit I find such questions hard to answer.

Should you learn all about using sets in Python? Some people never find a
need to use them and many languages have no such construct. But not learning
them may confuse you later when you encounter what to you looks like a very
badly formed dictionary that seems to be missing values, or is it keys?

AI is not only a very broad field but a moving target that also keeps
evolving. If you are interested in the AI I was studying while working on a
Ph.D. in AI at Rutgers in the early 80's, it is barely recognizable and
definitely did not use Python. Much of what was seen as new and interesting
ended up migrating out from the umbrella of AI into other aspects of
computer science and has become so commonplace that it is not considered
challenging any more. Other aspects have fallen out of favor or been shown
to not be a great approach.

I have revisited many aspects of what is now AI in recent years and am
especially focused on many kinds of statistical methods that overlap AI and
I Machine Learning.  Much of that is done using Python extensions but I have
done much work you would consider to be aspects of AI in other languages
such as R or stand-alone applications. 

So the question here struck me as having several parts and that the person
asking was either not very clear in their mind and sort of hoping to find
some direction to get started. And, of course, sometimes it may simply be
that they are just not that proficient yet in English.

So if the question is whether learning a bit about Object-Oriented
techniques in Python if your plan is to study AI, then the answer might be
YES. But only up to a point. No need to be an expert at first.

Many aspects of AI are mostly done using modules and packages others have
already written and often tested. They come with pre-made objects that often
are usable as black boxes with details well hidden within and the manuals
tell you how to access or modify them, albeit good ones often hide much of
that too and provide you with all the interfaces you normally need. Of
course if you later want to tweak some things, you may need more, let alone
if you want to share your own creations.

Consider one of many scenarios in the scikit-learn module. You may want to
do SOMETHING (and I am being abstract) that has variations.

Typically you ask for a new object to be created that encapsulates what you
want to do. You call code like:

MyProblemSolver = doSomething(initializers)

You now have an object which has used one of the initializers defined within
that you do not need to see anything unless you feed it something wrong. It
can set  all kinds of parameters,  maybe check validity, maybe creates
accessory objects within and who knows what.

You may also tweak it using methods supplied in additional lines of code
like:

MyProblemSolver.dosomething(...)

I mean objectName.fit(...), objectName.transform(...),
objectName.predict(...) and so on.

One key part is giving it the data you want to use. For that, you may end up
calling it with a method you hand something to that can range from a python
list or some exotic object like a numpy Series or pandas DataFrame and so
on.

There are quite a few such object types  used for various purposes and you
can make many of them and tweak each and compare results and so on.

But you can use many of these tools without having the slightest idea what
an object is. A well designed tool may be easy to use by setting reasonable
defaults so if you want one of many other possible tweaks, like adjusting
the level of an alpha variable or choosing a different algorithm for some
part of a transaction by name or even supplying your own function for use in
comparing two things internally, you can tweak it quite a bit and even make
your own customizations. Beginners rarely need to.

As I mentioned, if you want to do something with some Machine Learning such
as a sort of neural network, a beginner is often better off skipping
learning powerful multi-purpose packages like TensorFlow and going straight
to Keras which is built on top of TensorFlow and pandas and other things and
largely removes you even further from seeing the endless details beneath BUT
may let you dip lower if you wish.

Much depends on whether you are just interested in the topic, are a student
hoping to major in something, or even looking at specific jobs. Many skills
are not worthwhile to spend lots of time on except as a hobby.

And, as noted, some of the modules written that encapsulate TensorFlow have
a rather different but still pythonic aspect as what they do is less
object-oriented and more function-oriented as you add layers by
encapsulating functions within functions.  To use those you need to focus on
other aspects of python.

But here is an important point. Generally you do NOT do machine learning or
other forms of AI alone. You often do lots of things in base python or other
modules to read in the data, clean it up or do calculations on it, perhaps
present graphics about it, and much more. Then you do one or more analyses
as described above and often do more calculations on the various parts
created in the process such as combining several and choosing which model
made better results on your test cases and perhaps more analyses and graphs
and ...

So your overall knowledge of other aspects of python and the many modules
people like for these tasks is important. I personally like to do some
things using other languages and tools and often do programming using
environments that create documents (as in a PDF or HTML or WORD documents)
that include marking up all kinds of text as well as including snippets of
python and R code that inter-operate with each other on the same data where
each does what it is good at or provides what I like. This is what happens
not at the beginning of a learning process but way later.  You sound like
you need some baby steps headed in the right direction. 

So, as others have said, learn enough about python without worrying if you
have mastered ALL the many ways to create formatted text and so on. I
suggest that much of AI is data intensive and that learning numpy decently
(but not expertly) should come next. Depending on your future needs, pandas
would come next, or might be studied only if it ever is needed. You can
always come back and learn missing things such as how to use sets. Man/most
languages have no such thing built in and yet people make do using things
like vectors of items along with abilities to make the contents unique() or
do various union() and intersection() and setdiff() operations OR creating
your own object-like creations or using packages from others. 

But you do not need to do this linearly. You can use later stages to help
guide you by seeing what code they discuss that you have not understood. You
can fill in the gaps. And you would be amazed how much (along with
misleading nonsense) you can pick up with a web search or two if you include
things like the name of the language and module as in "python numpy remove
duplicates" or whatever you can phrase well enough.  Frankly, it can be a
mistake to study python in a multi-volume way when the vast majority of what
you learn is overkill. An intro book or two and maybe something intermediate
but focused such as found using "book machine learning in python" or one
about graphics and python may let you make progress.

Now if you have specific questions about some code you read about use of
objects and want to understand, this could be the place, but not if you have
read nothing and want one on one attention to learn as that may require a
real full-time dedicated person as a tutor.

Again, good luck. Questions deeper than basic python, though, often have a
better place, or even better, find resources you can read and practice with
on your own as such learning can be longer-lasting. 


-----Original Message-----
From: Tutor <tutor-bounces+avi.e.gross=gmail.com at python.org> On Behalf Of
Alan Gauld via Tutor
Sent: Saturday, June 11, 2022 7:56 AM
To: tutor at python.org
Subject: Re: [Tutor] Learning Object Oriented Programming

On 11/06/2022 09:40, Aliyan Navaid wrote:
> To be honest every AI project I've seen amazes me whether it is about 
> finding insights in data, NLP, or Image generation. However, could you 
> list down stuff (in order) that is essential to all these applications?
> 

I see Avi has already posted a reply suggesting you won't get your answes
here. That is true in terms of the ultimate and specific answers to your
question however I do think its a fair question for a beginner to ask here.
The reason is, and your question and follow-up suggest it is true of you
too, that most beginners see an interesting field but have no idea of the
complexity involved.
In your case AI is a whole sub genre of computing with many specialisms
within it. Until you know which specific sub-branch you want to explore it
is impossible to give specific advice.

What we can say is a that a good knowledge of general programming techniques
will never go amiss and Functional Programming (which is not the same thing
as just writing/using functions!) and the use of classes and objects are
both worth studying. I don't think you need to study the full OOP paradigm
since most AI projects seem to be more likely to be functional in nature
with just a few classes or objects used as data carriers. This list and
other python resources are certainly able to help with that.

Other areas of general programming that may be worth considering include
data storage(RDBMS, NO-SQL, and other "Big Data" solutions) as well as
generic algorithms for searching/sorting etc. Wikipedia is probably a good
starting place for these areas.

Once you get into AI domain specific subjects you will probably find
domain-specific fora that are better placed to help.


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


_______________________________________________
Tutor maillist  -  Tutor at python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list