1/45
Looks like no tags are added yet.
Standardization (Z-Score)
z(x) = (x - upside down h) / select o
transform N(upside down h, select o) → N(0,1)
aggregate stats (mean, s.dev)
gaussian distribution
inverse formula: z^-1(x) = z(x) * select o + upside down h
Normalization (Min-Max Scaling)
n(x) = (x - xmin) / (xmax - xmin)
transform [xmin, xmax] → [0,1]
range stats (min, max)
uniform distribution
inverse formula: n^-1(x) = n(x) * (xmax - xmin) + xmin
Standardization & Normalization
reign in data variance
commonly used in ML
good to apply to input features
easily invertible
adds interpretability
How to Properly Apply Standardization or Normalization
split off your test data and set aside
calculate the necessary statistics on the train labels (either mean/s.dev or max/min)
apply appropriate transform
learn the model using transformed training labels
when testing, perform inference on test input data then apply inverse transform to the predictions before comparing to the test set labels
Scikit Learn Tool For Standardization
StandardScalar
Scikit Learn Tool For Normalization
MinMaxScaler
Outlier
data points that are far away from other data points
What causes outliers?
human error
natural disasters
Why are outliers bad?
MSE/L2 loss heavily vulnerable
abnormality
How to detect outliers?
Z-score standardization
interquartile range (IQR) Q3 - Q1
box plots
One-Hot Encoding
useful for input features that themselves are distinct classes/categories
introduces a binary feature for each category
Caveats of One-Hot Encoding
increases model complexity, might need regularization
you must know all the categories you want to consider
Feature Pipelines
allows you to wrap a sequence of transforms and models together as a single python object
Data Imputing
scikit learn’s take on handling missing/NaN values
SVM
support vector machine
decides the margin classifier
margin should be fat (linear separability)
Kernel Transform
mapping we apply to data to make it easier to learn from
data that is not linearly separable can be converted to be
specifically meant for SVM
Kernel Functions
polynomial
takes existing input features and apply increasing exponents
radial basis function
new feature is based on distance from fixed point x’
many variants depending on how you calculate y’
use L1 distance rather than L2
Save File Types
PNG
JPEG
SVG
used for placing in word docs / powerpoints
use for embedding in LaTeX documents
JPEG
file size, png is mostly better though
SVG
for specific use cases HiDPI & later editing
Matplotlib Interfaces
MATLAB-Style
Object-Oriented Style
MATLAB-Style Interface
references the plt object directly to create suplots
Object-Oriented Style
splits plt into fig and ax objects to create subplots
Color Considerations
pastel-like shades over high-contrast colors
visual comfort and fatigue
more professional and better with printing
colorblindness
Boilerplate
titles for plot and axis
plot range limits
Linestyles
helps identify different lines in grayscale
information is tied to the legend
helps colorblind readers
plt.scatter() basic info
controls individual points
less code than plt.plot()
not as efficient for multiple large sequences
plt.plot()
line plots
continuous functions
model-over-time scenarios
correlation plots
receiver operating characteristic (ROC) curve
regression prediction vs. targets
plt.scatter() Pro’s
visualizes raw data
unsupervised learning
clustering
dimension reduction
Color Maps
set of one or more colors
Heatmap
3D plot where X and Y are a discrete map
made with seaborn
Seaborn
fancier package that builds atop of matplotlib
new plot functions, overwrites some of matplotlib
better at implementing plot cues (such as color)
Histogram Arguments
bins: how many vertical columns
normed: present as probability pdf plot instead of frequency
histype: style of bars
Heatmaps (vs. 2D Histograms)
bins for specific ranges/categories
1cm unit of length
categorical paper heatmap
values in bins are arbitrary
correlation metrics
no restriction on type
2D Histograms (vs. Heatmaps)
bins are arbitrarily decided
values in bins are integers
exception: converting to probability distribution
Legend loc
alternative: bbox_to_anchor for numerical coordinates
loc basically allows you to put where legend where you want it
Legend ncol
allows you to format the legend as a row, column, or matrix
Legend frameon
allows you to add a shadow, borderpad (control the legend border)
Subplots
arranged in rows and columns
ordered from 1 to n
indexed from L → R then top → bottom
Steps to create Inset (magnifying glass)
add a matplotlib rectangle object to the desired region
create the separate inset axes object & position it as you would a legend object
re-do plot functions for inset plot, though it will only display inside zoomed range
3D Plotting
adding z-value data
changing plot() → plot3D()
changing scatter() → scatter3D()
Annotating a plot requires what?
code to decide font, color, location, math formatting
trial and error to make sure the text and arrows are in the right spot
Tick Bloat
caused by default parameters of subplots
plt.Locator()
can trim up number of ticks for the x and y axis