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 ...

Dec 30, 2020

Ways to format the code snippet and tables in the blog

 


I'm trying to embed the Python code into the the blog posts. I have played around the format and found there is no good support in blogger to fulfill this task. After a deep dive, I have found two ways to embed the code snippet in a good format. 

One way is to use the HTML format site - http://hilite.me/.  Here is a sample Python code to judge if a number is null or not.

# import numpy
import numpy as np

# function to judge if a number is null
def is_null(x):
   return x != x

# test samples
is_null(np.nan)
is_null(2)

Or you are not comfortable to use HTML, simply copy and paste the code below in the HTML view and modify it in the Compose view.

<!-- HTML --><div style="background: #f0f0f0; overflow:auto;width:auto;border:None gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #60a0b0; font-style: italic"># print</span>
<span style="color: #007020; font-weight: bold">print</span>(<span style="color: #4070a0">&quot;All About Python&quot;</span>)
</pre></div>

The output of the above embedding.

# modify the code here
print("All About Python")

The other way is to use gist - https://gist.github.com/. Here are the steps to create the formatted code in the gist. An example of Python code is showed below.

  1. Sign up a account with GitHub if you don't have it
  2. Enter the file name with proper extension. For example, I use isnull.py as the file name
  3. Copy or type your code
  4. Select "Create public gist" and click on it. Now the code is ready to share
  5. Choose "Embed" and Copy the link address and paste in the blog editor in HTML mode.

To add tables to the blog, it's easier to use tableizer to format table in HTML code. It's simply to copy the table from the excel sheet to the tableizer and choose the proper font size, color, and font style. Click on the "Tableize it!" and copy the HTML, and paste it in the HTML view. An example is showed below.

DateOpenHighLowClose
10/18/19128.34129.21127.38129.12
10/27/19128.21129.39127.1129.31
10/26/19127.31128.21127.03128.12
10/25/19126.41127.56125.98127.21

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)