- 博客(12)
- 收藏
- 关注
原创 吴恩达机器学习python实现8 异常检测及推荐系统
异常检测1、可视化数据def visualize_dataset(X): plt.scatter(X[..., 0], X[..., 1], marker="x", label="point")2、估计参数def estimate_parameters_for_gaussian_distribution(X): mu = np.mean(X, axis=0) sigma2 = np.var(X, axis=0) return mu, sigma23、根
2022-03-25 12:48:44 2259
原创 吴恩达机器学习python实现7 K-means及PCA
K-means1、找到所属簇def find_close_centroids(X, centroids): res = np.zeros((1,)) for x in X: res = np.append(res, np.argmin(np.sqrt(np.sum((centroids-x)**2, axis=1)))) return res[1:]2、计算新的簇中心def compute_centroids(X, idx): K = in
2022-03-24 14:11:37 1719
原创 吴恩达机器学习python实现6 支持向量机
支持向量1、导入所需的库import scipy.io as sioimport matplotlib.pyplot as pltfrom sklearn import svmimport numpy as np2、绘制散点图、绘制决策边界、计算高斯内核# 绘制散点图def plot_scatter(x1, x2, y): plt.scatter(x1, x2, c=y) plt.xlabel("x1") plt.ylabel("x2")# 绘制..
2022-03-22 21:11:25 1521
原创 吴恩达机器学习python实现5 偏差和方差、训练集&验证集&测试集
1、导入数据并可视化 data = sio.loadmat(文件路径) X = data["X"] # (12,1) y = data["y"] # (12,1) Xval = data["Xval"] yval = data["yval"] Xtest = data["Xtest"] ytest = data["ytest"] # 可视化训练集 plt.scatter(X, y, marker="o", c="b")
2022-03-22 14:22:03 2335
原创 吴恩达机器学习python实现4 神经网络
1、对数组进行一维和多维变化# 将多维参数数组映射到一个向量上def serializer(thetas): res = np.array([0]) for t in thetas: res = np.concatenate((res, t.ravel()), axis=0) return res[1:]# 将向量还原为多个参数def deserialize(theta): return theta[:25*401].reshape(25, 4
2022-03-20 15:11:25 1315
原创 吴恩达机器学习python实现3 多元分类及前馈神经网络
多元分类1、从images中随机选取numbers张图片def randomly_select(images, numbers): m, n = images.shape[0], images.shape[1] res = np.zeros((1, n)) for i in range(numbers): index = random.randint(0, m - 1) res = np.concatenate((res, images[in
2022-03-19 15:56:43 586
原创 吴恩达机器学习python实现2 Logistic回归
Logistic回归0、读取数据def read_dataset(filename, type_tuple, separator=','): with open(filename) as f: lines = f.readlines() data = [] for line in lines: line = line[:-1] line = line.split(sep=separator)
2022-03-15 21:45:24 2421
原创 吴恩达机器学习python实现1 单变量线性回归
0、引入要用到的库import numpy as npimport matplotlib.pyplot as plt1、读取数据,绘制图像with open(r'E:\zl\机器学习\1\ex1_linear_regression_ex1data1.txt') as f: populations = [] profit = [] for line in f.readlines(): populations.append(float(line...
2022-03-11 21:18:51 1810
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人