getUglyNumber
获取前N个丑数如果一个数的素因子只有 2,3,5 ,我们称它为丑数,1 是第一个丑数, 要求按大小输出前N个丑数
思路
每一个丑数都是由前面的某个丑数乘2,乘3, 或乘5得来
我们当然可以遍历前面所有丑数都分别乘 2、3、5 ,取其中的最小值来得到当前的丑数
一种很好的方法是选取前面若干丑数中最可能乘2产生当前丑数的数 a ,最可能乘 3 产生当前丑数的数 b, 和最可能乘 5 产生当前丑数的数 c ,取 2a,3b,5c 的最小值,就是当前丑数
如何选取并在遍历中更新 a, b, c :
a,b,c 为前面已经求得的丑数
每次寻找丑数时用到的 a,b,c 在以后寻找丑数的过程中不能重复使用
pythonDataStructure
ML中的数据结构1. numpy1. ndarray 多维数组1. 创建ndarray 是一个通用的同构数据容器,即其中的所有元素类型相同。当创建好一个ndarray数组是,同时会在内存中存储 ndarray 的shape 和dtype, shape是 ndarray 的维度大小的元组,dtype 是解释说明 ndarray 数据类型的对象。
data = [1,2,3]
data = (1,2,3)
data = [[1,2,3],[4,5,6]]
arr = np.array(data)
2. zerosnp.zeros(3)
np.zeros((3,4))
3. onesnp.ones(
Lecture2-ImageClassificationPipeline
1. First classifier:Nearest Neighbor Classifier
数据集:CIFAR-10,提供10个label,50,000 个训练样本,10,000个测试样本。K-NN 中最重要的一个部分就是 距离的计算方法,下面是曼哈顿距离的计算方法。
import numpy as np
class NearestNeighbor:
def __init__(self):
pass
def train(self,X,y):
'''X is NxD where each row is an examp
Chapter17-RecommenderSystem
Chapter17-RecommenderSystemContent-based recommender systems
Collaborative filtering
Collaborative filtering algorithm这里 \(x \in R^n\) \(\theta \in R^n\) ,不设置截距项。
Vectorization: Low rank matrix factorization
Implementational detail: Mean normalization
扩展阅读Chapter18-LargeScaleMachingLearningChap
Chapter16-AnomalyDetection
Chapter16-AnomalyDetectionGaussian distribution
algorithm
Developing and evaluating an anomaly detection system
Anomaly detection vs. supervised learning
Choosing what features to use
Multivariate Gaussian distribution前一节介绍的高斯分布式基于单个变量 \(x^i\) ,当多个变量具有相关性的时候,对于测试样本的单个变量来说,符合高斯分布,模型就会误判定为正常样本。
Anoma
Chapter15-DimensionalityReduction
Chapter15-DimensionalityReductionPCA -principal component analysis找到一个低维的平面,来对数据进行投影,以便最小化投影误差的平方,以及最小化每个点,与投影后的对应点之间距离的平方。
choose K
compressed representa1on
X_{approx} = U_{reduce}Z (\(X{approx} \in R^{nx1}\),\(U{reduce}\in R^{nxk}\),\(Z\in R^{kx1}\))
Advice for applying PCA扩展阅读Chapter18-LargeScal
Chapter14-Clustering
K-means algorithminput:
K (number of clusters)
Training set \((x^{(1)},x^{(1)},…,x^{(1)})\)
\(x^{(i)} \in R^n(drop x_0=1 convention)\)
Optimization Objective
Random initialization
choose the number of clusters
扩展阅读Chapter18-LargeScaleMachingLearningChapter17-RecommenderSystemChapter16-AnomalyDet