自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(42)
  • 资源 (1)
  • 收藏
  • 关注

原创 python zip压缩成文件和bytes io

python zip压缩成bytes io

2022-12-09 10:20:52 456 1

原创 python asyncio socket

asyncio对socket封装了一个高级api, 可以方便的启一个TCP server跟client。

2022-11-28 15:47:34 897

原创 python 协程asyncio使用

python 协程asyncio使用

2022-10-27 17:50:33 591

原创 python实现只读属性, 常量

python实现只读属性

2022-10-26 10:54:25 933

原创 flask集中处理异常

flask集中处理异常

2022-06-30 13:45:59 238

原创 python unittest以及coverage report

python 单元测试 unittest以及覆盖率报告

2022-06-30 13:29:08 475

原创 python 发邮件 带附件

环境python==3.7代码from io import BytesIOimport smtplibimport emailfrom email.mime.application import MIMEApplicationfrom email.mime.text import MIMETextfrom email.mime.multipart import MIMEMultipartfrom email.header import Headerclass Email:

2022-05-18 17:49:11 2443

原创 文本数据增强(data augmentation)nlpaug使用

环境python==3.7nlpaug==1.1.7文档https://nlpaug.readthedocs.io/en/latest/overview/overview.htmlhttps://github.com/makcedward/nlpaug安装pip install numpy requests nlpaug数据增强主要方式https://zhuanlan.zhihu.com/p/150600950nlpaug简单介绍Support textual and a

2022-04-21 17:35:48 1788

原创 python 根据父子信息 还原成json树

python 树还原需求有一组数据 ([1,2], [2, 3], [1, 5], [5, 6]), 列表里的数据分别为父节点,子节点。将这组数据还原成树状json数据。

2022-02-15 17:57:09 1562

原创 RNN维度

Pytorch RNN参数import torchfrom torch import nnrnn = nn.RNN(input_size=4, hidden_size=5, num_layers=2, batch_first=True, bidirectional=True)input_size (输入维度)hidden_size (hidden state h)num_layers (RNN堆叠层数)nonlinearity (non-linearity 默认tanh)bia

2022-01-13 15:01:56 416

原创 去除字符串中的符号

import stringclass Preprocessor: def __init__(self): pass @staticmethod def remove_punctuation(content: str, remove_blank=True, lower=True): """ 把文本里的符号去除 以及空格 :param content: :param remove_blank: defa

2022-01-10 15:15:34 816

原创 基于预训练模型Bart的英文文本摘要summary生成

环境python==3.7transformers==4.9.2rouge-score==0.0.4数据准备将数据放在一个txt中,每行为一条,文章正文跟label的摘要用\t分割构建数据集from datasets import Datasetclass Data: def __init__(self, data_path, tokenizer): self.path = data_path self.max_input_length =

2021-10-26 14:23:05 3018 4

原创 文本分类pytorch Bert fine tune

基于Bert预训练模型的文本分类fine tune环境python==3.7torch==1.7.1transformers==4.9.2scikit-learn==0.21.3pandasnumpy构建数据集将数据放到如下图格式的dataframe中,label对应的数字为每种类别的下标。random seed设置import torchimport numpy as nprandom_seed = 2018np.random.seed(random_seed)t

2021-09-15 10:49:14 687 3

原创 文本数据增强(data augmentation)textattack使用

环境python==3.7textattack==0.3.3数据增强主要方式https://zhuanlan.zhihu.com/p/150600950textattack文档https://textattack.readthedocs.io/en/latest/apidoc/textattack.transformations.word_swaps.html#word-swaptextattack使用import nltkfrom textattack.transformations

2021-08-25 13:48:07 1569 4

原创 Linux统计文件夹下文件数量

统计当前文件夹下面 文件夹的数量(包括子文件夹)ls -lR | grep "^d" | wc -l统计当前文件夹下 文件的个数(不会递归进子文件夹)ls -l | grep "^-" | wc -l统计当前文件夹下 文件的个数(会递归进子文件夹)ls -lR| grep "^-" | wc -l...

2021-08-12 14:16:01 149

原创 NLTK英语停用词

nltk en_stopwordsen_stopwords = ["i", "me", "my", "myself", "we", "our", "ours", "ourselves", "you", "your", "yours", "yourself", "yourselves", "he", "him", "his", "himself", "she", "her", "hers", "herself", "it", "its", "itself", "they",

2021-07-21 14:06:00 660

原创 word2vec 使用gensim训练词向量

用gensim训练word2vec 英文词向量模型环境python==3.7gensim==4.0.1文档gensim官方文档 https://radimrehurek.com/gensim/models/word2vec.html预处理全部转成小写,去除符号,stopwords, 分词构建sentence生成的格式类似[[“i”, “love”, “you”],[“you”, “like”, “apple”],]可以是个迭代器。1. LineSentence

2021-07-20 15:53:31 899

原创 网格搜索GridSearchCV

网格搜索用来寻找模型最佳的超参数环境python==3.7scikit-learn==0.24.1使用方式import numpy as npfrom sklearn import datasetsfrom sklearn.model_selection import GridSearchCVfrom sklearn.pipeline import Pipelinefrom sklearn.preprocessing import StandardScalerfrom skle.

2021-07-05 17:07:09 192

原创 early stopping softmax批量梯度下降(BGD)手动实现

环境scikit-learn==0.21.3python==3.7numpy==1.16.4jupyter数据集使用sklearn鸢尾花数据集,是个字典,keys有[‘data’, ‘target’, ‘target_names’, ‘DESCR’, ‘feature_names’, ‘filename’], data有四个特征from sklearn import datasetsiris = datasets.load_iris()print(list(iris.keys()))

2021-07-02 15:55:20 195

原创 混淆矩阵confusion matrix

混淆矩阵(confusion matrix)True Positive(TP)(真正类):predict=1,actual=1True Negative(TN)(真负类): predict=0, actual=0False Positive(FP)(假正类): predict=1, actual=0False Negative(FN)(假负类): predict=0, actual=1混淆矩阵图示如下:T P第二位可以理解为predict的结果,predict==1为P, predict

2021-06-18 16:47:56 189

原创 python深浅拷贝

浅拷贝浅拷贝方式a = [3, [66, 55, 44], (7, 8, 9)]# 方式1import copya1 = copy.copy(a1)# 方式2a2 = list(a)# 方式3a3 = a[:]浅拷贝拷贝的是 最外层容器,副本中的元素是源容器中元素的引用从下面的结果可以看出来,浅拷贝出来的a1相当于建了一个跟a最外层一样的容器,但里面的内容跟a里面的是一样的,里面的引用跟id是一致的。>>> id(a)1851391485448>&gt

2021-05-31 14:43:38 44

原创 python实现二分搜索binary_search

python实现二分搜索binary_search条件:给定一个升序列表,返回target值的下标,没有则返回-1def binary_search(data, target): target_index = -1 start_index = 0 end_index = len(data) - 1 while True: middle_index = (end_index + start_index) // 2 middle_value

2021-05-27 15:23:50 361

原创 python3中浮点数float的四舍五入,round跟decimal区别

python3中浮点数float的四舍五入round在四舍五入时 round会存在偏差,不推荐使用round# 2.1 2.5 2.61取整时结果是对的>>> round(2.1)2>>> round(2.5)2>>> round(2.61)3四舍六入五成双需要舍弃的最后一位是>=6,直接进位需要舍弃的最后一位是<=4,不进位需要舍弃的最后一位是5, 判断前面那位是奇数还是偶数,奇数进位例如 2.215 保留

2021-05-27 11:12:29 1257

原创 Docker基本使用方法(build image \run...)

docker安装sudo apt-get updatesudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ gnupg \ lsb-releasecurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archiv

2021-05-20 16:59:43 393

原创 nginx基础配置,转发所有

upstream flask { server 127.0.0.1:5001;}server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html; # Add index.php to the list if you are using PHP index index.html index.htm index.nginx-debian.html; server_nam

2021-05-19 14:33:29 2803

原创 python property使用

python property使用python==3.7@property把方法变成属性调用self._price是一个私有变量,如果想在绑定属性时做一些限制,可以实现一个set方法class Car(object): def __init__(self, price=1): self._price = price def get_price(self): return self._price def set_pric

2021-04-27 14:03:04 61 1

原创 python 异步api ThreadPoolExecutor 、ProcessPoolExecutor(多线程、多进程)

python 异步api ThreadPoolExecutor 、ProcessPoolExecutor(多线程、多进程)python==3.7线程import timefrom concurrent.futures import ThreadPoolExecutor, as_completedfrom concurrent.futures._base import Futurefrom random import randintworker_num = 5executor = Thr

2021-04-09 14:27:36 599

原创 python retry retrying使用

python retrying使用installpip install retrying==1.3.3retrying==1.3.3python==3.7from retrying import retryretry次数 ,每次retry的时间限制, 每次retry的时间间隔(毫秒)# stop_max_attempt_number次数 ,stop_max_delay每次retry的时间限制,每次retry的时间间隔@retry(stop_max_attempt_number=2,

2021-04-01 17:03:07 644

原创 sqlalchemy用in_ 批量delete

sqlalchemy用in_ 批量delete# 删除记录时,默认会尝试删除 session 中符合条件的对象,而 in 操作估计还不支持,于是就出错了。解决办法就是删除时不进行同步,然后再让 session 里的所有实体都过期history_delete_num = session.query(Model).filter(Model.id.in_(id_list))\ .delete(synchronize_session=False)id_list...

2021-03-05 15:29:41 1007

原创 python list 分批batch

python list 分批batchdef split_batch(init_list, batch_size): groups = zip(*(iter(init_list),) * batch_size) end_list = [list(i) for i in groups] count = len(init_list) % batch_size end_list.append(init_list[-count:]) if count != 0 else end_l

2021-01-05 11:03:28 2385

原创 python连接MongoDB,以及常用操作

python连接MongoDBMongoDB: 多用于文档数据库存非结构化数据,NoSQL非关系型数据库。python连接mongoconfigMONGODB: USER: $MONGODB_USER PASSWORD: $MONGODB_PW HOST: host PORT: 27017 QUERY_STRING: 'replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=fa

2020-12-10 16:03:12 324 1

原创 python 连接Oracle数据库,cx_Oracle

python 连接Oracle数据库from cx_Oracle import makedsn, Connection, Cursorimport cx_Oracledsn = makedsn(dev_host, port, service_name=dev_service_name)def get_connection() -> Connection: connection: Connection = cx_Oracle.connect(dev_user, dev_pw, ds

2020-08-21 13:56:33 148

原创 sqlalchemy按月水平分表、python元类、动态映射表名automap_base\ 模型类

sqlalchemy按月水平分表1.事先按月建表根据sqlalchemy 模型类建表from sqlalchemy.ext.declarative import declarative_base,from sqlalchemy import Column, StringBase = declarative_base(engine)class TestTable(Base):...

2020-01-16 14:21:24 1251

原创 包管理conda操作,常用conda命令

conda操作,常用conda命令conda操作,常用conda命令1.查看环境conda info –-envsconda info –-e2.激活环境conda activate py363.退出环境conda deactivate4.安装和更新库pip install scipypip install scipy --upgrade#或者conda install s...

2019-08-20 17:07:21 229 1

原创 Ubuntu下mysql跟换datadir,数据库存放路径,支持更改单个库的存放路径

Ubuntu16.04下mysql5.7(8.0)跟换datadir,数据库存放路径,支持更改单个库的存放路径采用软链接,不需要更改my.cnf配置文件将datadir(或者单个大库)跟换至挂载的大硬盘达到节省存储空间的目的步骤拷贝datadir中的数据库文件# cp -a 连文件夹权限一起复制# /var/lib/mysql 为默认mysql datadir路径sudo c...

2019-04-23 09:52:44 347 2

原创 原生Django常用API 参数

原生Django一 . 工程搭建环境搭建创建虚拟环境mkvirtualenv django_py3_1.11 -p python3安装Djangopip install django==1.11.11工程创建1.创建工程django-admin startproject 工程名称2.创建子应用python manage.py startapp 子应用名称...

2019-03-10 16:44:29 540

原创 jupyter notbook远程连接配置(Ubuntu16.04)

jupyter notbook远程访问配置(Ubuntu16.04)jupyter 版本:4.4.0系统版本:Ubuntu16.041.生成配置文件默认无配置文件,需要手动生成jupyter notebook --generate-config生成完之后,会显示配置文件路径在当前用户home路径下的 /.jupyter/jupyter_notebook_config.py2....

2019-01-16 11:14:01 186

原创 Git

Git介绍分布式版本控制工具作用管理源代码代码备份(存档)有利于团队协作开发集中式版本控制与分布式版本控制git本地结构创建本地仓库,必须先进项目文件夹设置作者信息以及邮箱全局设置设置之后所有giti项目都用这个邮箱本地结构操作基本操作git status (查看本地状态,当前文件状态)git add 文件名 (将工作区文件放...

2018-11-28 21:29:52 99

原创 python里常用的正则表达式

python里常用的正则表达式1.用户名import re# 4到16位(字母,数字,下划线,减号)if re.match(r'^[a-zA-Z0-9_-]{4,16}$', &quot;abwc&quot;): print(&quot;匹配&quot;)2.整数import re#正整数正则if re.match(r'^\d+$',&quot;42&quot;): print(&quot;匹配&

2018-11-10 13:56:01 283

原创 Ubuntu-16.04网络IP配置(静态IP\DHCP)

Ubuntu-16.04网络IP配置(静态IP\DHCP)配置IP方式有两种:

2018-11-05 14:34:22 7159

putty_ssh等远程客户端

putty是Telnet、SSH、rlogin、纯TCP以及串行接口连接软件

2018-11-05

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除