How to use Python with Mathematics for Data Science
(Specifically, Machine Learning)
Prepared by:
Rhoda Grace A. Ilisan
DEDICATION
The researcher would like to dedicate this research study to her families, friends and
classmate who supported her to conduct this research study, for the teachers who help
and guide her to make a final output and for the future researchers who can use this
study as their guide or reference.
TABLE OF CONTENTS
Page
PART I - Anaconda and Jupyter -------------------------------------------------------------- 1
a. Installation of anaconda -------------------------------------------------------- 2
b. How to use Jupyter ------------------------------------------------------------ 3
PART II – Fundamentals of Python ------------------------------------------------------ 1
a. Variables, Data Types and Script ---------------------------------------------- 2
b. Decision Statement and Repetition Statement ------------------------------ 3
c. User Defined Function --------------------------------------------------------- 4
d. List and Dictionary ------------------------------------------------------------- 5
PART III – Machine Learning ------------------------------------------------------------ 1
a. Using Numpy --------------------- ---------------------------------------------- 2
b. Using Scipy ---------------------------------------------------------------------- 3
c. Pandas ---------------------------------------------------------------------------- 4
d. Using Plotly --------------------------------------------------------------------- 5
e. Implement Simple Linear Regression -------------------------------------------- 5
f. Implement Multivariate Liner Regression ----------------------------------------- 5
Bibliography--------------------------------------------------------------------------------------- 37
PART I
Anaconda and Jupyter
a. Installation of anaconda
This tutorial will demonstrate how you can install Anaconda, a powerful package
manager, on Microsoft Windows. Anaconda is a package manager, an environment
manager, and Python distribution that contains a collection of many open source
packages. This is advantageous as when you are working on a data science project,
you will find that you need many different packages (numpy, scikit-learn, scipy, pandas
to name a few), which an installation of Anaconda comes preinstalled with.
Download and Install Anaconda
1. Go to the Anaconda Website and download the application.
2. Locate your download and right click it. Then click the run administrator.
3. When the screen below appears, just click next.
4. Read the license agreement and click on I Agree.
5. Choose Just Me and Just click next.
6. Note your installation location then click next.
7. This is the important part of the installation process. Just click recommended
approach to add Anaconda to your path. Then Click Install.
8. When it’s already completed just click next.
9. Just click next again.
10. Click on Finish.
b. How to use Jupyter.
1. Locate your Jupyter Application then right click open.
PART II
Fundamentals of Python
Python is an interpreted, high-level and general-purpose programming language.
Created by Guido van Rossum and first released in 1991, Python's design philosophy
emphasizes code readability with its notable use of significant whitespace. Its language
constructs and object-oriented approach aim to help programmers write clear, logical
code for small and large-scale projects. Python is dynamically typed and garbage-
collected. It supports multiple programming paradigms, including structured (particularly,
procedural), object-oriented, and functional programming. Python is often described as
a "batteries included" language due to its comprehensive standard library.
Python was created in the late 1980s as a successor to the ABC language.
Python 2.0, released in 2000, introduced features like list comprehensions and a
garbage collection system with reference counting. Python 3.0, released in 2008, was a
major revision of the language that is not completely backward-compatible, and much
Python 2 code does not run unmodified on Python 3. The Python 2 language was
officially discontinued in 2020 (first planned for 2015), and "Python 2.7.18 is the last
Python 2.7 release and therefore the last Python 2 release. No more security patches or
other improvements will be released for it. With Python 2's end-of-life, only Python
3.6.x[33] and later are supported. Python interpreters are available for many operating
systems. A global community of programmers develops and maintains CPython, a free
and open-source reference implementation. A non-profit organization, the Python
Software Foundation, manages and directs resources for Python and CPython
development.
a. Variables, Data Types and Script
A variable is a memory address that can change and when memory address
cannot change then it is known as constant. Variable is a name of the memory location
where data is stored. Once a variable is stored then space is allocated in memory. It
defines a variable using a combination of numbers, letters, and the underscore
character.
Variables Memory
Name = ‘rhoda’
Name = ‘rhoda’
A = 20
A = 20
B = 10
B = 10
A Variable in python is created as soon as a value is assigned to it. It does not
need any additional commands to declare a variable in python. There are a certain rules
and regulations we have to follow while writing a variable, lets take a look at the variable
definition and declaration to understand how we declare a variable in python.
Variable Definition & Declaration
Python has no additional commands to declare a variable. As soon as the value
is assigned to it, the variable is declared.
There are a certain rules that we have to keep in mind while declaring a variable:
1. The variable name cannot start with a number. It can only start with a
character or an underscore.
2. Variables in python are case sensitive.
3. They can only contain alpha-numeric characters and underscores.
4. No special characters are allowed.
There are several data types in python. Let’s take a look at the data types in
python. Every value that we declare in python has a data type. Data types are classes
and variables are the instances of these classes.
Data Types in Python
According to the properties they possess, there are mainly six data types in
python. Although there is one more data type range which is often used while working
with loops in python.
Numerical Data Types
Numerical data type holds numerical value. In numerical data there are 4 sub
types as well. Following are the sub-types of numerical data type:
1. Integers
2. Float
3. Complex Numbers
4. Boolean
Integers are used to represent whole number values.
Float data type is used to represent decimal point values.
Complex numbers are used to represent imaginary values. Imaginary values are
denoted with ‘j’ at the end of the number.
Boolean is used for categorical output, since the output of boolean is either true or false.
Variables and data types in python as the name suggests are the values that
vary. In a programming language, a variable is a memory location where you store a
value. The value that you have stored may change in the future according to the
specifications.
Script in Python
The Python script is basically a file containing code written in Python. The file
containing python script has the extension ‘.py’ or can also have the extension ‘.pyw’ if it
is being run on a windows machine.
b. Decision Statement and Repetition Statement
A repetition statement is used to repeat a group (block) of programming
instructions. Most beginning programmers have a harder time using repetition
statements than they have at using selection statements. At the same time, the use of
repetition statements is at least (if not more) important than using selection statements.
Therefore, it is a good idea to expect to spend more time trying to understand and use
repetition statements.
Repetition statements fall into two general categories; while loops and for loops.
Although it is possible to write every loop as a while loop (or every loop as a for loop),
this is not a good idea. While loops should be used if the number of repetitions is not
fixed. In many cases, the number of repetitions that a while loop executes depends on
user input. On the other hand, for loops should be used when the number of repetitions
is fixed. In many cases, the number of repetitions a for loop executes for is determined
by the number of elements in an array or an array-like object (such as a list or a tuple in
Python). This is why for loops are often associated with some indexed quantity like a
list.
While Loops
c. User Defined Function
d. List and Dictionary