标签 Python 下的文章

Pytorch 分类网络实例


TransformsData does not always come in its final processed form that is required for training machine learning algorithms. We use transforms to perform some manipulation of the data and make it suitable for training.All TorchVision datasets have two parameters -transform to modify the features and target_transform to modify the labels - that accept callables containing the transform...

Dataset&DataLoader


dataset需要实现def __getitem__(self, index) -> T_co: # 基于一个索引返回一个训练样本(x, y)构成的训练对 raise NotImplementedError("Subclasses of Dataset should implement __getitem__.") def __len__(self): # 将数据放进去,返回数据总大小 return len(self.img_labels) return self.tensors[0].size(0)import os import pandas as pd from torchvision.io import read_image # 从磁盘中读取训练数据、__getitem__中能够根据idx返回相对...

TORCH.GATHER


torch.gather(input, dim, index, *, sparse_grad=False, out=None) → [Tensor]Gathers values along an axis specified by dim.Parametersinput (Tensor) – the source tensordim (int) – the axis along which to indexindex (LongTensor) – the indices of elements to gatherKeyword Argumentssparse_grad (bool, optional) – If True, gradient w.r.t. input will be a sparse tensor.out (Tensor, optional) ...

Pandas对缺失值的处理


Pandas使用这些函数处理缺失值:isnull和notnull:检测是否是空值,可用于df和seriesdropna:丢弃、删除缺失值axis:删除行还是列,{0 or "'index', 1 or 'columns'}, default o how:如果等于any则任何值为空都删除,如果等于all则所有值都为空才删除inplace :如果为True则修改当前df,否则返回新的dffillna:填充空值value:用于填充的值,可以是单个值,或者字典(key是列名,value是值)method:等于ffill使用前一个不为空的值填充forword fill;等于bfill使用后一个不为空的值填充backword fillaxis:按行还是列填充,{0 or 'index', 1 or 'columns"} inplace :如果为True...

Pandas新增数据列


在进行数据分析时,经常需要按照一定条件创建新的数据列,然后进行进一步分析。直接赋值实例:清理温度列,变成数字类型实例:计算温差df. apply方法Apply a function along an axis of the DataFrame.Objects passed to the function are Series objects whose index is either the DataFrame's index(axis=0) or the DataFrame's columns (axis=1).实例:添加一列温度类型:1.如果最高温度大于33度就是高温2.低于-10度是低温3.否则是常温df.assign方法Assign new columns to a DataFrame.Returns a new object with all ori...

召唤看板娘