timerring

Python Function Parameter

December 21, 2024 · 4 min read
Tutorial
Python

This blog will review the function parameter of Python. Mainly about the parameter passing, Keyword and Position Parameter, Anonymous Function, and unit test with assert.

...


Python Basic Data Type

December 21, 2024 · 6 min read
Tutorial
Python

This article will explore data types and common methods for them in Python. The content of this review is as follows: number type, string type, boolean type and type conversion.

...


Python Basic Syntax Elements

December 20, 2024 · 3 min read
Tutorial
Python

Sometimes you may forget about the basic of Python, so let us take a look at the summary of Python basic summary. The content of this review is as follows: data type, variable, control flow, input & output, PEP8 format.

...


Python Linear Algebra

July 14, 2024 · 7 min read
Tutorial
Python

Scalar #

Scalar variables are denoted by ordinary lowercase letters (for example, $x$, $y$, and $z$). $\mathbb{R}$ denotes the space of all (continuous) real-valued scalars, and $x\in\mathbb{R}$ is the formal way to say that $x$ is a real-valued scalar. A scalar is represented by a tensor with only one element.

...


Python Data Preprocessing

July 12, 2024 · 1 min read
Tutorial
Python

Reading the Dataset #

The data is stored in the CSV (comma-separated values) file ../data/house_tiny.csv.

import os

os.makedirs(os.path.join('..', 'data'), exist_ok=True)
data_file = os.path.join('..', 'data', 'house_tiny.csv')
with open(data_file, 'w') as f:
    f.write('NumRooms,Alley,Price\n')  # Column names
    f.write('NA,Pave,127500\n')  # Each row represents one data sample
    f.write('2,NA,106000\n')
    f.write('4,NA,178100\n')
    f.write('NA,NA,140000\n')

# To load the raw dataset from the CSV file we created, import `pandas` and call `read_csv`.
# !pip install pandas
import pandas as pd

data = pd.read_csv(data_file)
print(data)

#    NumRooms Alley   Price
# 0       NaN  Pave  127500
# 1       2.0   NaN  106000
# 2       4.0   NaN  178100
# 3       NaN   NaN  140000
...


Python Data Manipulation

July 12, 2024 · 4 min read
Tutorial
Python

An $n$-dimensional array is also called a tensor. Regardless of the deep learning framework, its tensor class (ndarray in MXNet and Tensor in PyTorch and TensorFlow) is similar to NumPy’s ndarray. During deep learning training, we usually do not read images one at a time. Instead, we might read 128 images at once. This is a batch, represented by a four-dimensional array. Deep learning frameworks also offer important features beyond NumPy’s ndarray:

  1. Strong support for GPU-accelerated computation, while NumPy supports only CPU computation;
  2. Automatic differentiation in tensor classes.

A tensor with one axis corresponds to a mathematical vector; A tensor with two axes corresponds to a mathematical matrix.

...


Density Plotting

August 31, 2023 · 13 min read
Tutorial
Python

Seaborn’s kdeplot() function is one way to draw density plots in Python. At present, Matplotlib does not have a specific function for drawing density plots, and plotting is generally performed in combination with the result of the gaussian_kde() function in the Scipy library.

The neighbors.KernelDensity () module in Python’s scikit-learn library provides six kernel functions—Gaussian, Tophat, Epanechnikov, Exponential, Linear, and Cosine—for kernel density estimation calculations. Python’s KDEpy library provides as many as nine kernel functions, including Gaussian, Exponential, Box, Tri, Epa, Biweight, Triweight, Tricube, Cosine.

A schematic diagram of the nine kernel functions in the KDEpy library is shown below:

...


Types of Univariate Plots for Continuous Variables

August 29, 2023 · 8 min read
Tutorial
Python

A univariate plot (chart for one variable) refers to drawing a corresponding plot using one variable from a dataset. To visualize this variable, a plot must be drawn according to the different data variable types. Data variables are divided into continuous variables and discrete variables.

...