Introduction To Machine Learning Report 1

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

INTRODUCTION TO MACHINE

LEARNING
Gabriela Fonseca, 4th Semester Mechatronics

FEBRUARY 13, 2024


SDU
Introduction to Python-1
Goal
The goal of this lab is get familiarized with some basics of python language. We will get familiar with
some Python useful tools and libraries for coming labs.

Development
I have background in programming C and RTOS. Therefore, I could see resemblances in the code sintax
and structures, as well as differences, as example, the “printf” statement in C is “print” in python
and each statement in python does not require a “;” termination as they do in C.

1st Part

Task 1: Hello World! Name Age and Height challenge


This task helped me learn basic programming concepts like if statements, for loops, functions and print
statements.
Task 2: Addition, Subtraction, Multiplication and Division
In this exercise the use of arithmetic operations was put in practice, as well as a continuation of before
learnt programming concepts like print statements.

Task 3: For Loop and While loop


Task 4: Greet function and Fruits

2nd Part

Task 1: Exception Handling


In this task, exception handling was learnt. If the user input is non valid, the program instead of crashing
will output a “invalid input” function.

Zero as an input:

Char as an input
2 as an input

In the examples seen above, we can see that try and except works like an if-else loop. If everything is ok
and the result is valid, it will print the result. If not (“else”) it will print one of the error messages.

Task 2: Modules and Libraries

A module is a file containing definitions and statements. They can define, functions, classes, and
variables for example. In this case, we use the line “import math” to use the module math.

Using modules is crucial for organizing code. Some of the benefits are:

• Globality: the modules can be used if different parts of the same code.
• Conflicts: they avoid conflicts by providing simple and accessible ways fir naming functions,
classes etc.
• Modularity: The code can be simplified by breaking it down into multiple different and smaller
parts.
Task 3: Object Oriented Programming Basics

This code demonstrates the fundamentals of object-oriented programming:

• Class: Dog
• Attributes: “name”, “age” //shared variables associated with the class
• Method: “bark” //function tied to a class performing actions on class data

To access the attributes, it is used a dot;


Task 4: Inheritance and Polymorphism

Inheritance allows a class to inherit properties and methods from another class. It works in the line
“class Cat (animal)” being Animal the parent class.

Polymorphism is the ability of a function to work with different types of objects or classes.

Introduction to NumPy
It creates a 1D array “v” from a python list, prints its values and data type. Then it does the same for a
2D array “M”. It generates a vector “col_vec” from the initial 1D array and then it creates arrays filled
with zeros and ones.

NumPy Array Attributes

We create a 3D array names gaussian using random values and reshape it. The code prints the number of
dimensions, shape and number of items and the space consumed by each.
Array Indexing

Creates a 1D array containing 10 random integers between 0 and 22. Then prints the array.

Create a 2D array of 46 elements and shape it to have 3 rows using .reshape (3, -1) where -1 is a
placeholder indicating that NumPy should automatically determine the number of columns based on the
specified number of rows.

This prints the entire 3D array first and then the last 2D array contained within the gaussian array.
This will print the first row of the altered array.

Index Slicing

We start by retrieving the last 5 elements of the array, then we skip one element at a time, then we print
the last 7 numbers, then the first 4 numbers
Linear Algebra

Vec is a 1D array created using np.arrange(0,5)

Arr is a 2D array with a shape of (4,5) created using no.arrange(4*5).reshape(4,5)


Plotting sine and cosine

This code generates 256 spaced values between -pi and pi using linspace then it calculates the sine and
cosine values for each point and plots both.
This code creates a cosine and sine function plot. It evenly spaces between -pi and pi. The size and dots
per inch are set and a subplot is created. The color, line width and style are also customizable.
Figure and subplots
Histogram

Introduction to Pandas - Part 1


Introduction to Pandas – Part 2
Introduction to Pandas – Part 3

Conclusion
This lab shows that Python is a good choice for machine learning and data processing as it offers easy-to-
use functions for quick development and efficient algorithms for fast processing of large datasets.

You might also like