当前位置:网站首页>机器学习(上)吴恩达
机器学习(上)吴恩达
2022-07-17 16:13:00 【starmultiple】
文章目录
机器学习
机器学习是一门多领域交叉学科,涉及概率论、统计学、逼近论、凸分析、算法复杂度理论等多门学科。专门研究计算机怎样模拟或实现人类的学习行为,以获取新的知识或技能,重新组织已有的知识结构使之不断改善自身的性能。
它是人工智能核心,是使计算机具有智能的根本途径。
第二章
模型描述
在监督学习里有一个数据集他被称为一个数据集。
监督学习算法工作原理:
向学习算法提供训练集(比如房价训练集),并输出一个函数,通常用h(假设函数)表示,这里把房子的大小作为输入变量得到输出的对应房价。
代价函数

梯度下降法
用梯度下降法最小化任意函数,(用于线性回归上)而不仅仅是最小化线性回归的代价函数J
a:=b(a赋予b的值)
a:=a+1(使a值加1)
a=b(声明)

线性回归的梯度算法
求0、 1的偏导数

第三章
矩阵和向量
矩阵表达方式

向量这里为一种特殊的矩阵,为只有一列的矩阵。
n行1列

加法和标量乘法


矩阵向量乘法


转置和逆


第四章
多功能

多元梯度下降法

特征缩放

特征和多项式回归


正规方程(区别于迭代方程的直接解法)
这位博主对正规方程的解释http://t.csdn.cn/VpD1A
其中示例三个点的最佳直线拟合
点: (-1.0,-1.2)、(0.0,1.0) 和 (1.0,2.8)
import numpy as np
import matplotlib.pyplot as plt
def process_features(X):
m, n = X.shape # 求X矩阵的行数和列数
X = np.c_[np.ones((m, 1)), X] # 将m行1列的矩阵与X拼接
return X
def fit(X, y): # 求正规方程
w = np.linalg.inv(X.T.dot(X)).dot(X.T).dot(y) # w*=(XT⦁X)-1⦁X⦁y
return w
def predict(X,y): # 预测X对应的Y值
w = np.linalg.inv(X.T.dot(X)).dot(X.T).dot(y)
return X.dot(w) # Y_pred = X ⦁ w*
def mean_squared_error(y_true, y_pred): # 求均方误差
return np.average((y_true - y_pred) ** 2, axis=0)
def r2_score(y_true, y_pred): # 求决定系数
numerator = (y_true - y_pred) ** 2
denominator = (y_true - np.average(y_true, axis=0)) ** 2
return 1 - numerator.sum(axis=0) / denominator.sum(axis=0)
dots = np.array([[-1.0, -1.2],
[0.0, 1.0],
[1.0, 2.8]]) # 点坐标
X = dots[:, [0]] # 取出每个坐标X轴的值
Y = dots[:, [1]] # 取出每个坐标Y轴的值
X_1 = process_features(X) # 首位置1
theta = fit(X_1, Y) # 求解正规方程
Y_pred = predict(X_1,Y) # 求解X的预测值
mse = mean_squared_error(Y, Y_pred) # 求均方误差
r2 = r2_score(Y, Y_pred) # 求决定系数
print("theta:{}".format(theta))
print("mse = {}".format(mse))
print("r2 = {}".format(r2))
plt.figure()
plt.title("Scatter Fitting")
plt.plot(X, Y, "bs", ms=3) # 画散点
plt.plot(X, Y_pred, color='red') # 打印直线
plt.show()
————————————————
版权声明:本文为CSDN博主「Time like water」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_43839907/article/details/105252463
边栏推荐
- Tikv memory parameter performance tuning
- 【机器学习】多标签分类的评价指标与代码实现
- Fundamentals of scala (3): operators and process control
- The adaptation of go language under windows10:vscode
- STL string输入输出重载2
- 微机原理与技术接口 实验四 子程序及中断实验
- Use native JS to realize the function of selecting all buttons, which is simple and clear
- Genesis与BlueRun Ventures展开深度交流
- 项目建设,谋事在人,成事亦在人!
- MAPGIS igserver Kyushu - expand service development under the control of localization environment
猜你喜欢

Use native JS to realize the function of selecting all buttons, which is simple and clear

Leetcode skimming -- find and minimum k-pair number 373 medium

编辑技巧篇

The concept of binary tree and three traversal methods (C language)

mysql学习笔记-约束

psd.js 解析PSD文件

Mysql-1366 - Incorrect string value: ‘\xE5\xBC\xA0\xE4\xB8\x89‘ for column ‘userName‘ at row 1

HCIP(8)

01 knapsack interview questions series (I)

getchar()
随机推荐
Leetcode 20. Valid parentheses
In 2022, how to choose cross end technology solutions?
李宏毅《机器学习》|1. Introduction of this course(机器学习介绍)
C语言绘图示例-调色板
Project construction depends on people, and success depends on people!
核芯基站_启动CPA文件报错‘No gateways configured’
Leetcode 239. Sliding window maximum
HCIP(6)
STL string input / output overload
One click backup of files
C语言绘图示例-分色调图20例
HCIP(4)
LeetCode_17_电话号码的字母组合
psd.js 解析PSD文件
STL string 输入输出重载1
【Flutter】dart:一些不容忽视的特性
Example of C language painting - progress bar
七月集训(第17天) —— 广度优先搜索
TiKV Follower Read
How to apply applet container technology to develop hybrid app