0% found this document useful (0 votes)
39 views30 pages

Noddy 2

The document discusses a student's six week summer training on object oriented programming using Python. It includes a declaration, acknowledgements, and explanations of key programming terms related to OOP, Python, and machine learning.

Uploaded by

Whonoddy Music
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views30 pages

Noddy 2

The document discusses a student's six week summer training on object oriented programming using Python. It includes a declaration, acknowledgements, and explanations of key programming terms related to OOP, Python, and machine learning.

Uploaded by

Whonoddy Music
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Six weeks summer training

ON

Submitted to

LOVELY PROFESSIONAL UNIVERSITY

PHAGWARA, PUNJAB

SUBMITTED BY

Name of student: Saksham Rastogi


Registration Number: 12008593

Dated – (June-July 2022)

Page 1
DECLARATION

To whom so ever it may concern

I, Saksham Rastogi (12008593), hereby declare that the work done by me on Six weeks summer
training from J u n e - 2 0 2 2 t o J u l y - 2 0 2 2 , is done with full dedication to meet
the learning outcome and certificate criteria for Object Oriented Programming using Python
from CODETANTRA.

Name of the student: Saksham Rastogi


Registration no.: 12008593

Object Oriented Programming using Python Page 2


This is the training certificate provided by Codetantra for the completion of
my Summer Training on Object Oriented Programming using Python

Object Oriented Programming using Python Page 3


ACKNOWLEDGEMENT

I would like express my sincere gratitude towards CODETANTRA for providing the platform to
learn in depth about the programming language of Python. I would also like to thank my parents
and peers, who helped me to provide mental support for me to complete my training.

Finally, I would like to thank Lovely Professional University, for providing me the opportunity to
work on the training and produce my learning outcomes.

Object Oriented Programming using Python Page 4


TABLE CONTENT

Object Oriented Programming using Python Page 5


Introduction of Project/Training Undertaken

The world is tending towards an era of Automation from the past decade, devices are becoming
smart and intelligence is becoming artificial day by day. And the only way to create a control
over this fast paced automated world is to learn the language of the masses.

The masses translate to complex machines and languages translate to programming languages
which is one of the key reasons which prompted me to undergo this valuable training by
CODETANTRA

Learning any language helps us to reach to a limited number of machines at a certain time, or
take huge strides to reach any high complexity machine. But learning a popular language helps
us communicate with a wider array of machines which may vary from any zone of complexity.
This was another of my key reason to undergo this summer training on Object Oriented
Programming using Python from CODETANTRA

Object Oriented Programming using Python Page


Now, learning a language would help us communicate with devices, only. But what if we had to
assert dominance on machine, then we could make the machine do, whatever we wanted! From
predicting datasets to making complex gears move in free motion, we could do whatever we
want and wherever we want!

That was my most important point to undergo this training on Object Oriented
Programming using Python by CODETANTRA.

Object Oriented Programming using Python Page 7


Key Terms and Explanation

• OOP- Stands for Object Oriented Programming was a term coined by Alan Kay Circa in
the year 1967. The basics of OOP model states that any software should be a CLASS and
that class should comprise of OBJECTS and DATA, rather than any sort of
FUNCTION and LOGIC.OOP follows bottom up approach.

• POP- Stands for Procedure Oriented Programming follows a more primitive method of
programming associated with functions only. The functions are the point of object
utilization and each function can communicate without any hierarchical structure unlike
OOP. POP follows top down approach.

• IDE- Stands for Integrated Development Environment is a specialized Environment


created to run any programming language. With important packages and compilers pre
loaded, an IDE is a go to software to download and run any programs without much
difficulty. Example: IntelliJ, Android Studio, BlueJ, etc.

• SYNTAX- These are specialized arrangement of functions and objects in a programming


language which act as a fundamental for logic. These lines when compiled properly
according to user’s requirements gives a proper output whole as a class or singular as a
single syntax. Example: print(“my name is Aryan”).

• COMPILERS- Compilers are special programs, which converts High Level Codes into
machine level codes i.e low level codes. The main principle of compilers is to take the
whole program at one instance and convert it at a single go.

Object Oriented Programming using Python Page 8


• PACKAGES- They are combination of multiple classes and their respective functions.
The pre defined packages can be directly called by using a calling statement in order to
utilize their classes. Whereas the user defined packages needs to be defined first and then
can be call when the user needs it. The ‘import’ command followed by the package name
is used to import any particular package.

• VARIABLES: These are containers which holds changeable data in them. Variables are
one of the most essential components of any programming language. They are used to
pass the data used in the program to process an output.

• DATATYPES-Are the type of data stored in variables. Similar types of data type can be
used to perform similar types of functions. Examples of datatypes are- int,
double,char,etc.

• AI- Known as Artificial Intelligence is a term coined in 1956 is a system which


resembles or tries to resemble the human intelligence. The AI is a complex structure of
Artificial Neurons similar to human Neurons which passes data from one node to another
node. The main function of AI is to replace repetitive or high risk jobs from Humans.

• TENSORFLOW- An open source framework for machine learning has a lot of packages
and tools useful training and predictions of datasets. One of the packages use in my
project was keras from tensor flow, which provides optimization to the datasets passed in
the program.

Object Oriented Programming using Python Page 9


• CV2- Stands for Computer Vision 2 is a library in python used for analyzing images. The
CV2 library can analyze images and can alter it’s shape, size , resolution and anything at it’s
grasp. It can be also used to analyze faces in images or videos for face recognition.

• OVERFITTING- A problem encountered while training datasets, over fitting occurs


when a model tries to accommodate all the data points in a dataset leading to creation
of an extremely complex ML model.

• UNDERFITTING- A problem encountered also during training datasets, under fitting


occurs when a model has less data to accommodate the training of machines. Results in
less accurate predictions in testing datasets or values.

• EPOCHS- It is a cycle of machine training which gives a score at the end. EPOCHS are
cycles of to and fro from a Artificial Neuron. It uses the data provided to it and goes to
and fro until a suitable threshold value is achieved. The time taken to achieve the
threshold value is the EPOCH score.

Object Oriented Programming using Python Page 10


Reasons for choosing this technology

Looking upon the evolution of High Level Programming languages, one thing makes the
principle of evolution clear, increase of power and productivity.

So keeping these points in mind, let me state the reason for choosing to do a training Python
Programming Language:

• OOP capabilities: The POP approach for C was a good idea for the initial start,
but the most important drawbacks of POP is the reason, the OOP module was
opted by it’s successor C++, management. POP was based around functions and
logic, which proved to be huge challenge for storing and managing data, OOP on
the other hand is based around objects and classes modules, which proves to be
much easier to handle data for the software. Python being the latest iteration of
OOP programming language makes it an obvious choice for the above reason.

• A productive language: Might not be the most powerful language but definitely, a
productive language. Housing a huge amount package storage, Python is one of
those languages which can deploy machine learning models with relative ease.
With the “simple” installation of Tensor flow into any python IDEs, you can
easily deploy CV2 capabilities to detect images and produce revolutionary
products like face detectors, optical fingerprint sensors and a lot more.

Object Oriented Programming using Python Page 11


• Easy to use syntax: Not a key reason to choose a programming language being a
aspiring computer engineer, but an efficient reason to choose as a newbie. Python
has one of the most easy to use syntax lines. With the inclusion of semicolons(;),
the ability to modify the data types however you want without the extensive use
of type casting or conversion and a some valuable data structures like lists,
dictionaries which helps house easy sorting methods, it is definitely a good
reason for a newbie to choose this programming language.

• Leading programming languages: And last but not the least, the prime reasons
or me choosing this programming language is being one of the leading
programming languages in this growing market of technology. Being and
Artificial Intelligence enthusiast and a newbie to programming language
definitely puts me in a prior position to choose this programming language for
sure.

Object Oriented Programming using Python Page 12


Technology and Modules learnt

Lets talk about the modules and technology that I learnt:

• Classes and Objects: The most basic principle of OOP as discussed earlier is dividing a
software into classes and objects, but how are they co-related to each other? To speak in
Layman’s terms, a class is a collection of objects. It’s a key term every programming
student is taught at the starting of any OOP language. Lets elaborate it further,

Class can be compared to group of any things, these things have to be necessarily
placed inside the class one way or the other. For example: A Class of students were
every student in the class, belongs to that class.

Object similarly on the other hand can be compared to students who are present inside
the class, objects are functional things which constitute together to give an output whole
as a class, Effectively called objects are also called instances of a class. Looking from a
software’s perspective, objects are the individual modules which comprise together to
give an output to a class i.e Software in this case.

Object Oriented Programming using Python Page 13


Observing the above diagram of Class(phones) and Objects(types of phones), one
thing can be clearly observed, the grouping or the arrangement of all the functionalities
has a clear boundary on its accessibility as well as arrangement.

Comparing these things with the previous generations of POP languages like C, we can
understand how much important it is to group things under specific groups. This is the
most key factor for the usage of OOP languages as a trend.

• Methods/Functions: After grouping all the objects separately under separate classes, we
can proceed to the step of utilizing those things to produce the output we desire. That is
where methods come into play. Methods or Functions are one of the most
fundamental components of for a functioning class. In a single line, ‘functions
provide functionality to a class’. Combining with syntax and objects storing data,
functions help the class utilize the data to produce a productive output.

Think of functions as CA(Continuous Assessment), students as objects and data as the


things we learn in class, CA provides students a function to follow, whose outputs come
in the form of results.

Now, Functions are divided into two types, i.e Pre-defined and User Defined functions:

Pre-Defined functions are those type of functions which are already defined inside the
programming language, they are defined inside a particular package which when
called, can be utilized fully without any hindrance. Example: the print() statement.

Object Oriented Programming using Python Page 14


User Defined functions on the other hand are as the name suggests ‘User Defined’. The
name of a user defined function can be according to user’s choice and the functionality of
that function can also be set by the user according to their needs. Example: def sum():

a=1,b=2
print(a+b)

• Abstraction: A concept of OOP which says, ‘show essential details and hide
unnecessary details’. Abstraction is one of the key concepts of OOP which hides,
unnecessary information from the standpoint of users, in order to make them focussed
into the main program.
Abstraction also helps in security purpose also, as in hiding important information in the
program in the way we hide unwanted details. This is one of the valuable features of
OOP.

• Encapsulation: ‘Wrapping up of data into a single unit’, explained into a single line,
Encapsulation basically means constituting every objects, every functions and every
class into a single unit which collectively in programming language is a package.

The concept of encapsulation is one of the essential concepts in OOP languages. It is one
of the reason due to which, arranging and accessing of data is made simple in OOP
programming languages.

Let’s take a real life example, synonymous to the term encapsulation, we’ll take a capsule
for an example. The capsule comprises of ton of chemicals as classes and the chemicals
comprises of ton of matters as objects. All these things are packed inside a single small
unit of capsule .
Page 15
Inheritance: As much as it’s real world meaning, Inheritance is one of the key concepts of OOP. In a
single line ‘inheriting objects and classes from another class’. One of the best features of OOP languages
is the concept of hierarchy. This prompts a ‘parent child relationship’ where children inherit the objects
and classes of a parent child.

Inheritance in OOP allows functions and classes to communicate with other functions
and classes present in a particular package.
In Python, Association is also used as a type of inheritance, Association bascically states
the relationship between two classes without any bounded rules.Association comprises of
Composition and Aggregation.

Example: class Name:


def __init__(self, firs_name,
las_name): self.first_name = fname
self.last_name = lname

def disp_name(self):
print(self.first_name, self.last_name)

x = Person("John", "Doe")
x.disp_name()

Object Oriented Programming using Python Page 16


• Polymorphism: Another important concept of OOP which essentially states that a
function can alter its functioning according to the need of the program. In simple terms, a
single function can have multiple behaviours.
Example:
def add(x, y, z = 0):
return x + y+z

print(add(2, 3))
print(add(2, 3, 4))

The above function first prints the sum of 2 and 3 and in the next calling, performs
addition of 2,3 and 4.

• Lists: One of the most widely used data type in Python Programming Language, Lists
are mutable data types which helps in storing multiple values/data items of any data
types. The word mutable means any data item of any data type can be replaced without
any hindrance.
Example: a = ['Shayan', 4, 4.70, True, "World", 2.0, "False"]

In order to extract values from list, we use indexing along with the list’s name to extract a
particular data item at a particular area of the list.
Example: print(a[3]) will print “True”

Object Oriented Programming using Python Page 17


• Dictionaries: Another type of data type in python, dictionaries use ‘keys’ to keep track of
the values stored in them. The keys of the dictionaries are immutable but the values are
mutable.
Example: a = ['Shayan':10, 4:20, 4.70:30, True:40, "World":50, 2.0"60]

• Pandas: These are packages, which help in data analysis. Specialized in data
science, pandas are used to create relationship between multiple data values.
Syntax: import pandas as pd

• Matplotlib: Matplotlib is used to depict the relationship between two data items or
datasets in the form of graphs. The most basic use of Matplotlib is to visualize any
relation if we want to present to anyone or if we are having hard time in figuring out
any relationship
Syntax: import Matlplotlib.pyplot as plt

Object Oriented Programming using Python Page 18


Project Undertaken

The project that I undertook was an Handwriting Analysis Machine


learning Model using CV2 and Tensorflow.

The image shown above is an output of how the algorithm, dissects an handwritten
structure to change it’s properties according to one’s wish. Let me explain how wrote the
code.

Object Oriented Programming using Python Page 19


• Explanation: Handwriting analysis is one of those beginner level projects that you can do to
jumpstart in a Machine Learning environment. OOPs are a fundamental part for these
projects as arrangement of modules are one of the key factors to achieve the output.

• Packages: The Model uses, Keras, CV2 and our good old friend Numpy to achieve to
analyse any handwritten script and then, alter its shape, resolution and size according to
users wish.
How it does this is something worth explaining:

Keras as mentioned earlier is an optimizing package under Tensorflow, used in case to


simplify the user action numbers. Since we are using the Model to alter the properties of
our handwritten script which is this:

We dearly needed keras for this task.

Object Oriented Programming using Python Page 20


In the above image we imported some of the basic things from the keras package to
complete the machine learning model.

Sequential model present in keras provides training and inference features on the model.
Since we created a machine learning model, so it is destined to require training from
images. The way Sequential groups layers into tf.keras.Model is by stacking them into
linear layers.

Dense, Dropout and Flatten are used for feature engineering in the model grouped into
Sequential model. Dense layers can be used only when association can exists between
two features, Dropout in a single line, is used to prevent the problem of Overfitting.
Dropout sets the input frequency to 0. Flatten basically does what the word says,
‘Flattens the input’. Flatten basically adds an extra channel if the input does not have
a y-axis.

Convolutional in keras helps to create tensored outputs with the dimension provided during
declaration. Here, we use Convo2D because we are trying to achieve a 2D output.

Categorical is used to convert a class vector into binary class matrix. The class vectors
have to be of integer type essentially.ImageDataGenerator generally converts the
obtained image input into tensored object.

Numpy: Last but not the least, Numpy stands for Numerical Py(Python) provides
Numerical functions to any python class that’s running on it’s import.

Object Oriented Programming using Python Page 21


• The Code and explanation: Here’s the part by part detailed explanation of the
code.

Calling the features and importing packages:


import numpy as np
from keras.datasets import mnist from
keras.models import Sequential
from keras.layers import Dense,Dropout,Flatten
from keras.layers.convolutional import Conv2D,MaxPooling2D,Convolution2D
from keras.utils import to_categorical
from keras.preprocessing.image import ImageDataGenerator

#calling the features


(X_train,y_train),(X_test,y_test) = mnist.load_data()
X_train.shape
X_test.shape
import matplotlib.pyplot as plt
plt.imshow(X_train[100],cmap='gray')
plt.show()
y_train[100]
X_train = X_train.reshape(X_train.shape[0],28,28,1)
X_test = X_test.reshape(X_test.shape[0],28,28,1)

In the lines above, we are calling the feature and grouping them in training and
testing datasets. Reshapes are required if the features happened to be uneven,
uneven features lead to bad predictions, so it’s an important step.

Object Oriented Programming using Python Page 22


Scaling the features:
X_train = X_train.astype('float')
X_test = X_test.astype('float')

X_train /=255
X_test /=255
y_train = to_categorical(y_train,10)
y_test = to_categorical(y_test,10)
y_train[:3]

So, this is an essential step to produce a good Machine Learning model. Feature
scaling is the next step to features reshaping. Here we used the Categorical to
convert the integer vectors of the class into binary class matrix.

Building the model:


model = Sequential() #create an object for this seq.
model.add(Convolution2D(32,3,3,activation='relu',input_shape=(28,28,1))) #
first conv. layer
#no_filter,filter_size,a_f,input_shape
model.add(MaxPooling2D(2,2)) #max pooling layer
model.add(Convolution2D(64,3,3,activation='relu')) #second conv. layer
model.add(Dropout(0.25)) # dropout layer
model.add(Flatten())
model.add(Dense(1000,activation='relu')) #first hidden layer
model.add(Dropout(0.5)) # dropout layer
model.add(Dense(10,activation='softmax')) #output layer
model.summary()

In this step, we are using dimensions of Convolutional Convo2D to create the


model with the help of activation function.
Object Oriented Programming using Python Page 23
Compiling the model:
from keras.optimizers import Adam
model.compile(loss='categorical_crossentropy', optimizer=Adam(),
metrics=['accuracy'])
train_gen = ImageDataGenerator(shear_range=.2,
rotation_range=20,
width_shift_range=0.2,
height_shift_range=0.2,
zoom_range=.2,
horizontal_flip=True)

test_gen = ImageDataGenerator()
train_generator = train_gen.flow(X_train, y_train, batch_size=64)
test_generator = test_gen.flow(X_test, y_test, batch_size=64)
model.fit_generator(train_generator,steps_per_epoch=60000/64,
epochs=15,
validation_data=test_generator,
validation_steps=10000/64)

The final step for creation of the model is compiling the trained the model. By
using the generator() function, we can generate training scores in the form of
‘epochs’.

Object Oriented Programming using Python Page 24


The figure above shows how EPOCHs scores look like after the machine is compiled
properly.

Assigning training and testing data:


y_train = to_categorical(y_train,10)
y_test = to_categorical(y_test,10)
y_train[:3]

In this step, we assign categorical to make class vectors of integer value, in order to use
them in the trained Machine Learning Model.

Object Oriented Programming using Python Page 25


Testing the Model:
model.save('mnist_cnn.h5')
from keras.models import load_model
loaded_model = load_model('mnist_cnn.h5')

score = model.evaluate(X_test, y_test)


print()
print('Test accuracy: ', score[1])

In this step, we check the accuracy score of the model. How well it performed on testing
data after being trained on the training data.

Importing the image:


import cv2
import matplotlib.pyplot as plt

img=cv2.imread('sha.png')
img.shape
plt.imshow(img,cmap='gray')

We upload the image show below for the model to process, it’s a handwritten script:

Object Oriented Programming using Python Page 26


Altering the properties of the image:
img = np.invert(img)
plt.imshow(img,cmap='gray')

img = cv2.resize(img, (28, 28))


img.shape
plt.imshow(img,cmap='gray')

Object Oriented Programming using Python Page 27


img = cv2.resize(img, (10, 10))
img.shape
plt.imshow(img,cmap='gray')

img = cv2.resize(img, (30, 28))


img.shape
plt.imshow(img,cmap='gray')

Object Oriented Programming using Python Page 28


Conclusion and Future Perspective

While undertaking the project, there were a lot of things that I pinpointed
had helped me to learn new things:

• Knowledge boundaries: Being a new technology, Python provides a lot of


compatibility to touch newly budding projects. But the catch of this boon is the
knowledge boundaries, that stops newbie users to jump right into the program.

While implementing the ML project in Python, we needed a lot of installations,


lot of modifications and a lot of knowledge about syntaxes and their errors.
These things pushes the knowledge boundaries to a huge distance which
sometimes might prove challenging.

• Easy accessibility: Knowledge boundaries was set high for Python being a
relatively new language but this disadvantage is the biggest boon for the
language. Python has a huge technology accessibility boundary for usage of
new technology.

You can create, GUI based interfaces, mini games, train AI machines and a lot
more with this single language. This is a single reason which makes Python a
good language for beginners, may not be perfect. Maybe the weight of the
programs created might be a bit heavy but still, the style of commands make
the language easy to learn and use.

Object Oriented Programming using Python Page 29


• Huge industry potential: Since, I had to mention the future perspective, let’s start
of the biggest future perspective of all, Python has a great potential for industries.
Being one of the few languages which can analyze and predict patterns in datasets
makes it viable choice for companies focussed on machine learning.

Learning the language properly or mastering the language with more


pro-efficiency will be really beneficial for me with knowledge basis.

In conclusion, I would like to say that I learnt a lot from undergoing this training and Project
creation. It helped me introduce to new technologies and helped me in doing experimentation
with them. I look forward to extend this experience to fully fledged mastery and want to
extend an helping hand to the industry world.

Object Oriented Programming using Python Page 30

You might also like