09 2021 档案

摘要:动量优化 想象一下,一个保龄球在光滑的表面上沿着平缓的坡度滚动:它开始速度很慢,在很快会获得动量,直到最终达到终极速度(如果有摩擦或空气阻力)。相比之下,常规的梯度下降法只是在斜坡上采取小的、常规的步骤,因此算法将花费更多时间到达底部 回想一下梯度下降通过直接减去权重的成本函数$J(\theta)\ 阅读全文
posted @ 2021-09-30 09:13 里列昂遗失的记事本 阅读(312) 评论(0) 推荐(0)
摘要:用Keras进行迁移学习 假如Fashion MNIST数据集包含了8个类别,例如,除凉鞋和衬衫之外的所有类别。有人在该数据集上建立并训练的Keras模型,并获得了相当不错的性能(精度>90%)。将此模型称为模型A。现在要处理另一项任务:有凉鞋和衬衫的图像,想要训练一个二元分类器(正=衬衫,负=凉鞋 阅读全文
posted @ 2021-09-28 20:15 里列昂遗失的记事本 阅读(71) 评论(0) 推荐(0)
摘要:IMDB数据集 它包含来自互联网电影数据库(IMDB)的50000条严重两极分化的评论 数据集被分为用于训练的25000条评论与用于测试的25000条评论 训练集和测试集都包含50%的正面评论和50%的负面评论 加载IMDB数据集 import tensorflow as tf from tenso 阅读全文
posted @ 2021-09-27 21:15 里列昂遗失的记事本 阅读(346) 评论(0) 推荐(0)
摘要:def f(x): return x ** 3 - 2 * x + 1 # 返回函数的值 def f1(s0, s1, s2): return (((s1 ** 2 - s2 ** 3) * f(s0) + (s2 ** 2 - s0 ** 2) * f(s1) + (s0 ** 2 - s1 ** 阅读全文
posted @ 2021-09-26 22:35 里列昂遗失的记事本 阅读(140) 评论(0) 推荐(0)
摘要:梯度消失与梯度爆炸问题 反向传播算法的工作原理是从输出层到输入层次,并在此过程中传播误差梯度。一旦算法计算出损失函数相对于每个参数的梯度,可以使用这些梯度以梯度下降步骤来更新每个参数。 随着算法向下传播到较低层,梯度通常会越来越小。结果梯度下降更新使较低层的连接权重保持不变,训练不能收敛到一个良好的 阅读全文
posted @ 2021-09-26 21:15 里列昂遗失的记事本 阅读(524) 评论(0) 推荐(0)
摘要:构造字典 DIAL_COODES=[ # 一个承载成对数据的列表,可以直接用在字典的构造方法中 (86,'China'), (91,'India'), (1,'United States'), (62,'Indonesia'), (55,'Brazil'), (92,'Pakistan'), (88 阅读全文
posted @ 2021-09-26 20:37 里列昂遗失的记事本 阅读(62) 评论(0) 推荐(0)
摘要:def fun(x): return x ** 3 - 2 * x + 1 def solve(a, b, epsilon): lamd = (5 ** 0.5 - 1) / 2 delta = b - a p = a + (1 - lamd) * (b - a) q = a + lamd * (b 阅读全文
posted @ 2021-09-26 20:17 里列昂遗失的记事本 阅读(868) 评论(0) 推荐(0)
摘要:利用顺序API构建回归MLP 用回归神经网络解决加州的住房问题 用Sickit-Learn中的fetch_california_housing()函数加载数据 from sklearn.datasets import fetch_california_housing from sklearn.mod 阅读全文
posted @ 2021-09-19 17:01 里列昂遗失的记事本 阅读(1097) 评论(0) 推荐(0)
摘要:import os import tarfile import urllib DOWNLOAD_ROOT = 'https://raw.githubusercontent.com/ageron/handson-ml2/master/' HOUSING_PATH = os.path.join('dat 阅读全文
posted @ 2021-09-19 09:46 里列昂遗失的记事本 阅读(159) 评论(0) 推荐(0)
摘要:from sklearn.datasets import load_iris import numpy as np from scipy import sparse import matplotlib.pyplot as plt import pandas as pd from IPython.di 阅读全文
posted @ 2021-09-19 09:43 里列昂遗失的记事本 阅读(447) 评论(0) 推荐(0)
摘要:什么是可散列的数据类型 在Python词汇表(https://docs.python.org/3/glossary.html#term-hashable)中,关于可散列类型的定义有这样一段话: 如果一个对象是可散列的,那么在这个对象的生命周期中,它的散列值是不变 的,而且这个对象需要实现__hash 阅读全文
posted @ 2021-09-19 09:31 里列昂遗失的记事本 阅读(188) 评论(0) 推荐(0)
摘要:数组 from array import array # 引入数组类型 from random import random floats=array('d',(random()for i in range(10**7))) # 利用一个可迭代对象来创建一个双精度浮点数的列表(类型码是'd'),这里的 阅读全文
posted @ 2021-09-19 09:11 里列昂遗失的记事本 阅读(40) 评论(0) 推荐(0)
摘要:为什么切片和区间会忽略最后一个元素 当只有最后一个位置信息时,可以快速看出切片和区间里有几个元素:range(3)和my_list[:3]都返回三个元素 当起止位置信息都可见时,我们可以快速计算出切片和区间长度,用最后一个数减去第一个下标(stop-start)即可 方便用任意一个下标来把序列分割成 阅读全文
posted @ 2021-09-18 21:28 里列昂遗失的记事本 阅读(57) 评论(0) 推荐(0)
摘要:from collections import namedtuple City=namedtuple('City','name country population coordinates') '''创建一个具名元组需要两个参数,一个是类名,另一个是类的各个字段的名字。 后者可以是由数个字符串组成的 阅读全文
posted @ 2021-09-15 10:26 里列昂遗失的记事本 阅读(67) 评论(0) 推荐(0)
摘要:第二周作业 计算矩形面积 if __name__ == '__main__': x = eval(input('请输入矩形的长:')) y = eval(input('请输入矩形的宽')) print('矩形的面积为:{:.2f}'.format(x * y)) 格式化输出 import math 阅读全文
posted @ 2021-09-13 20:09 里列昂遗失的记事本 阅读(75) 评论(0) 推荐(0)
摘要:残差神经网络(ResNet) 为什么神经网络的层数越来越深 由图可知随着神经网络层数的增加,神经网络的训练误差和测试误差相较于较低层数的神经网络都要更高。但是这个与越深的网络,训练误差和测试误差都要更小这个第一感觉相违背。 在相同的迭代次数下,更深的神经网络的误差更容易趋向于平稳。 神经网络随着层数 阅读全文
posted @ 2021-09-11 16:54 里列昂遗失的记事本 阅读(1347) 评论(0) 推荐(0)
摘要:构建高级卷积神经网络 以Google Net为例 GoogleNet的模型图为 可以看到其中有一个模块反复使用 Inception Module Inception Module 模型的具体结构图为 个人理解这个模块是将数据经过不同的卷积方式并保持图像大小不变得到不同的通来获得更多的信息,然后将最后 阅读全文
posted @ 2021-09-09 21:36 里列昂遗失的记事本 阅读(203) 评论(0) 推荐(0)
摘要:使用Keras加载数据集 import tensorflow as tf from tensorflow import keras fashion_mnist=keras.datasets.fashion_mnist (X_train_full,y_train_full),(X_test,y_tes 阅读全文
posted @ 2021-09-08 19:12 里列昂遗失的记事本 阅读(86) 评论(0) 推荐(0)
摘要:lax_coordinates = (33.9425, -118.408056) # 洛杉矶国际机场的经纬度 city, year, pop, chg, area = ('Tokyo', 2003, 32450, 0.66, 8014) # 东京市的一些信息:市名、年份、人口、人口变化和面积 tra 阅读全文
posted @ 2021-09-08 11:00 里列昂遗失的记事本 阅读(109) 评论(0) 推荐(1)
摘要:symbols = '$%^&*♕' codes = [] # 创建一个codes列表 for symbol in symbols: # 用for循环迭代symbols codes.append(ord(symbol)) # 将symbols中的元素迭代取出后转化为Unicode码并添加到列表中 c 阅读全文
posted @ 2021-09-08 10:34 里列昂遗失的记事本 阅读(65) 评论(0) 推荐(1)
摘要:PyTorch的配置 这里附上官网的链接https://pytorch.org/get-started/locally/ CPU版本 选择PyTorch版本(PyTorch Build),Stable(稳定版),Nightly(测试版) 系统版本,这里只介绍Windows系统的PyTorch环境配置 阅读全文
posted @ 2021-09-06 23:01 里列昂遗失的记事本 阅读(320) 评论(0) 推荐(0)
摘要:import torch from torchvision import transforms from torchvision import datasets from torch.utils.data import DataLoader import torch.nn.functional as 阅读全文
posted @ 2021-09-06 22:34 里列昂遗失的记事本 阅读(124) 评论(0) 推荐(0)
摘要:import torch # 引入模块PyTorch from torchvision import transforms # 从torch视觉中引入转换函数 from torchvision import datasets # 导入数据库 from torch.utils.data import 阅读全文
posted @ 2021-09-06 22:10 里列昂遗失的记事本 阅读(235) 评论(0) 推荐(0)
摘要:import torch import torch.nn.functional as F # 从torch引入激活函数 x_data = torch.tensor([[1.0], [2.0], [3.0]]).cuda() # 将数据放在GPU上 y_data = torch.tensor([[0. 阅读全文
posted @ 2021-09-06 21:39 里列昂遗失的记事本 阅读(367) 评论(0) 推荐(0)
摘要:这里选择将模型和loss还有数据都在GPU上,方便后续能够将大型神经网络的计算图放在GPU上来加快训练速度 import torch # 引入PyTorch模块 x = torch.tensor([[1.0], [2.0], [3.0]]).cuda() # 创建张量x,y并使用cuda()将数据存 阅读全文
posted @ 2021-09-06 17:34 里列昂遗失的记事本 阅读(273) 评论(0) 推荐(0)
摘要:利用特殊方法,来使得自定义对象来实现一个二维向量(Vector)类 一个简单的二维向量类 from math import hypot class Vector: def __init__(self, x=0, y=0): self.x = x # 将输入的x,y分别赋值给类属性x,y self.y 阅读全文
posted @ 2021-09-06 16:57 里列昂遗失的记事本 阅读(77) 评论(0) 推荐(0)
摘要:import collections # 引入collections模块 Card = collections.namedtuple('Card', ['rank', 'suit']) # 用namedtuple创造了一个简单的类Card class FrenchDeck: ranks = [str 阅读全文
posted @ 2021-09-05 20:24 里列昂遗失的记事本 阅读(110) 评论(0) 推荐(0)
摘要:从零开始学Python 第一节课 学会了Python的变量赋值、运算符使用和强制类型转换 if __name__ == '__main__': print('Hello World') print('人因梦想而伟大') print('▁▄▇▇▄▁') print('人是唯一会交易的动物,因为没有狗会 阅读全文
posted @ 2021-09-04 20:18 里列昂遗失的记事本 阅读(101) 评论(0) 推荐(0)
摘要:使用Python的print函数来输出植物大战僵尸中的石头怪 根据给出的图片用字符串来拼接植物大战僵尸中的石头怪 print(' ' * 2 + '* ' * 5 + '\n' + ' ' + '*' + ' ' * 10 + '*' + '\n' \ + '*' + ' ' * 4 + '@' + 阅读全文
posted @ 2021-09-04 20:05 里列昂遗失的记事本 阅读(187) 评论(0) 推荐(0)