Featured Post

Set up machine learning and deep learning on AWS

Here is the simple instructions to set up a EC2 instance to run machine learning and deep learning on AWS 1.  Run an EC2 instance from ...

Showing posts with label tutorial. Show all posts
Showing posts with label tutorial. Show all posts

Dec 28, 2020

Python installation and environment setup

 


There are many ways to install Python on your machine. The easiest and most popular way is to download and install Anaconda. A pure Python without any packages is useless, as we are using a list of Python packages to do the work. To use Python for numerical computation, we need NumPy and SciPy. To process data and tables, we would need the Pandas, and for data visualization, Matplotlib is the basic package. You may also need machine learning packages, such as scikit-learn, TensorFlow, etc. To manage the dependencies of the package version,  it's essential to use a Python package manager. Anaconda is the best of the Python package mangers that provides the essential Python tools to get started. 

For individual uses, you can find the Anaconda for your machine specifics here on Anaconda's download page. Choose the operation system and the corresponding installer, follow the instruction and install the Anaconda on your machine. 

Suppose you are using a Mac OS and you have installed the Anaconda using the Graphical Installer. There are multiple ways to open Python.

1. Open the terminal and type 'python'

$ python

2. Open the graphical Anaconda-Navigator and click on the notebook

3. Open the terminal and type 'jupyter notebook'

$ jupyter notebook

Introduction to Python language

 


There are so many programming languages. Why do we need to learn Python? What are the advantages that make Python unique for beginners to learn coding? Well, there might be many answers to this question. The best answer would be that Python is popular, especially in data science and machine learning. Python is now becoming the basic and almost unique tool to data scientist and model developers. 


Another advantage of the Python is the availability in open source libraries. Python has now been used prevalently in machine learning and deep learning with a list of high level packages available in open source, such as scikit-learn, TensorFlow, PyTorch, etc.

Python as a programming language was designed with simple syntax, emphasizing on the readability and prototyping. 

Writing the first line of code with Python on terminal or Jupyter notebook

print('All About Python')

Define a sequence of numbers

alist = [2, 3, 5, 9, 10]
print(alist)

Write a function to filter the even numbers in a list

def get_even_numbers(a):
    even_nums = []
    for x in a:
        if x % 2 == 0:  
            even_nums.append(x)
    return even_nums

get_even_numbers(alist)




Apr 24, 2020

Python map and filter function

Python provides map and filter functions to process computations on the list of items. Here is a list of examples how to use map and filter.

Python map function examples

Compute the square of 1 to 10

def f(x):
    return x*x

map(f, range(1, 11))

or use lambda functions

map(lambda x: x*x, range(10)) 


Python filter function examples

Extract the event numbers from 1 to 10

def f(x):
    return x%2 == 0

filter(f, range(1, 11))

or use lambda functions

filter(lambda x: x%2 == 0, range(1, 11))