
python
szfhy
这个作者很懒,什么都没留下…
展开
-
numpy中数据拼接的方法
a = np.floor(20 * np.random.random((2,2)))b = np.floor(20 * np.random.random((2,2)))c = np.floor(20 * np.random.random((2,2)))print(a)print(b)print(c)[[ 8. 2.] [16. 15.]][[ 7. 0.] [10. 12.]]...原创 2019-05-28 22:05:00 · 3774 阅读 · 0 评论 -
jupyter快捷键
Ctrl + Shift + - #将一个 cell拆分为两个cellesc dd #删除一个cell, esc 按一下,切换到命令模式Ctrl+enter #执行本cellshift+enter #执行本cell且 向下建立一个新cellesc+m ...转载 2019-05-07 14:57:38 · 3531 阅读 · 0 评论 -
python可视化50图
http://www.machinelearningplus.com/plots/top-50-matplotlib-visualizations-the-master-plots-python/原创 2019-05-14 20:35:46 · 2706 阅读 · 0 评论 -
pandas 学习笔记
pandas 是一个强大的时间序列数据处理工具包,由两个比较重要的数据结构,series和dataframe,可以简单的将其抽象为一个表格。series可以表达一行数据,理解为一维数组。s = pandas.Series([4,2,5,0,6,3])DataFrame表示二维数组, df = pandas.DataFrame(numpy.random.randn(6,4), columns...原创 2018-09-15 11:49:24 · 780 阅读 · 0 评论 -
matplotlib 修改坐标轴,添加注释及公式
坐标轴刻度import matplotlib.pyplot as pltimport numpy as npx=np.arange(1,11,1)plt.plot(x,x)ax = plt.gca()#ax.locator_params(nbins=5) #xy轴同时调整ax.locator_params('x',nbins=10) #只调整x轴ax.locator_para...原创 2018-09-15 09:55:48 · 9663 阅读 · 0 评论 -
matplotlib 配置色彩点线样式网格及图列
色彩配置import matplotlib.pyplot as pltimport numpy as npy = np.arange(5)plt.plot(y, color='g')plt.plot(y+1, color='0.5')plt.plot(y+2, color='#ff00ff')plt.plot(y+3, color=(0.1,0.2,0.3))plt.s...原创 2018-09-15 09:43:59 · 2897 阅读 · 0 评论 -
matplotlib实现热成像图colorbar和极坐标图
热成像图%matplotlib inlinefrom matplotlib import pyplot as pltimport numpy as npdef f(x, y): return (1 - x / 2 + x ** 5 + y ** 3) * np.exp(-x ** 2 - y ** 2)n = 10x = np.linspace(-3, 3, 4 * n...原创 2018-09-15 09:34:28 · 10228 阅读 · 1 评论 -
matplotlib 实现饼图pie和等高线图contourf
饼图import numpy as npimport matplotlib.pyplot as pltlabels='A','B','C','D'fracs = [15,30, 45, 10]explode = [0,0.1,0.05,0]#长宽比为1:1plt.axes(aspect=1)#autopct 控制百分比的设置,使用format字符串或者format funct...原创 2018-09-15 09:26:40 · 994 阅读 · 0 评论 -
matplotlib实现直方图hist和折线图
单变量直方图import numpy as npimport matplotlib.pyplot as pltmu = 100 # mean of distributionsigma = 20 #standard deviatioin of distributionx = mu + sigma * np.random.randn(200000)#绘制单变量的直方图plt.his...原创 2018-09-15 09:19:27 · 5142 阅读 · 0 评论 -
matplotlib 柱状图bar
import numpy as npimport matplotlib.pyplot as pltN = 5y = [20, 10, 30, 25, 15]index = np.arange(N)plt.bar(left=index, height=y,color='red', width=0.5) #left横坐标,height纵坐标, color颜色 widthplt.show(...原创 2018-09-15 09:13:45 · 1421 阅读 · 0 评论 -
matplotlib 实现区域颜色填充
import matplotlib.pyplot as pltimport numpy as npx= np.linspace(0,5*np.pi, 1000)y1 = np.sin(x)y2 = np.sin(2*x)#plt.plot(x,y1)#plt.plot(x,y2)plt.fill(x,y1,'b',alpha=0.5)plt.fill(x,y2,'r',a...原创 2018-09-15 08:52:13 · 28324 阅读 · 0 评论 -
python实现图像外边界跟踪
share一些python实现的code#!/usr/bin/env python#coding=utf-8import cv2img = cv2.imread("trace_border2.bmp")[img_h, img_w, img_channel] = img.shapetrace = []start_x = 0start_y = 0gray = img[:,...原创 2018-09-01 16:16:08 · 5512 阅读 · 2 评论 -
机器学习-分类性能评价指标-混淆矩阵confusion_maxtrix
关于混淆矩阵,之前看别人的一些教程,感觉作者很牛,图形化显示出来也很酷,最近深挖了一下文档,顿时感觉我们很牛人就间隔一张纸。详细的实现:confusion_matrix顺便添加自己的调试的代码,记个笔记。import numpy as npimport matplotlib.pyplot as pltfrom sklearn import svm, datasetsfrom ...原创 2019-05-10 11:05:17 · 2913 阅读 · 0 评论 -
jupyter notebook 引入交互式控件
安装pip install ipywidgets配置jupyter nbextension enable --py widgetsnbextension使用from ipywidgets import interactdef f2(x): return xinteract(f2, x='')显示效果原创 2019-05-07 22:51:41 · 2650 阅读 · 0 评论 -
scikit-learn xgboost 预测波士顿房价
xgboost需要单独安装pip install xgboost #安装xgboost库pip install --upgrade xgboost #更新xgboost库import xgboost as xgbfrom xgboost import XGBRegressor as XGBRfrom sklearn.ensemble import RandomForestRegr...翻译 2019-05-27 21:51:16 · 2688 阅读 · 0 评论 -
scikit-learn 以线性回归为例学习性能评估指标
代码:from sklearn.linear_model import LinearRegression as LRfrom sklearn.model_selection import train_test_splitfrom sklearn.model_selection import cross_val_scorefrom sklearn.datasets import fetc...翻译 2019-05-27 21:34:31 · 2093 阅读 · 1 评论 -
scikit-learn 支持向量机--图视化
代码笔记:from sklearn.datasets import make_blobsfrom sklearn.svm import SVCimport matplotlib.pyplot as pltimport numpy as npX,y = make_blobs(n_samples=50, centers=2, random_state=0, cluster_std=0....翻译 2019-05-27 21:20:38 · 732 阅读 · 0 评论 -
scikit-learn 支持向量机-乳腺癌数据集探索
代码笔记:from sklearn.datasets import load_breast_cancerfrom sklearn.svm import SVCfrom sklearn.model_selection import train_test_splitimport matplotlib.pyplot as pltimport numpy as npfrom time im...翻译 2019-05-27 21:13:43 · 5021 阅读 · 0 评论 -
scikit-learn 逻辑回归--调参
代码笔记:from sklearn.linear_model import LogisticRegression as LRfrom sklearn.datasets import load_breast_cancerimport numpy as npimport matplotlib.pyplot as pltfrom sklearn.model_selection import...翻译 2019-05-27 20:32:25 · 8515 阅读 · 0 评论 -
scikit-learn 主成分分析--数据降维
代码笔记import matplotlib.pyplot as pltfrom sklearn.datasets import load_irisfrom sklearn.decomposition import PCAiris = load_iris()y = iris.targetX = iris.dataimport pandas as pdpd.DataFrame(X...翻译 2019-05-27 20:25:06 · 1720 阅读 · 0 评论 -
scikit-learn 随机森林代码学习--乳腺癌检测
from sklearn.datasets import load_breast_cancerfrom sklearn.ensemble import RandomForestClassifierfrom sklearn.model_selection import GridSearchCVfrom sklearn.model_selection import cross_val_scor...翻译 2019-05-26 22:18:23 · 1236 阅读 · 0 评论 -
scikit-lean 随机森林代码学习--红酒
代码笔记%matplotlib inlinefrom sklearn.tree import DecisionTreeClassifierfrom sklearn.ensemble import RandomForestClassifierfrom sklearn.datasets import load_winewine = load_wine()from sklearn....翻译 2019-05-26 18:02:35 · 1274 阅读 · 1 评论 -
scikit-learn 决策树代码学习-红酒数据
代码笔记1.导库from sklearn import treefrom sklearn.datasets import load_winefrom sklearn.model_selection import train_test_split2. 加载数据,拆分wine = load_wine()Xtrain, Xtest, Ytrain, Ytest = train_...翻译 2019-05-26 16:23:43 · 2100 阅读 · 0 评论 -
机器学习模型评估混淆矩阵、ROC曲线和AUC以及PR曲线
在机器学习中,当我们基于某个业务建立模型并训练后,接下来我们需要评判模型好坏的时候需要基于混淆矩阵,ROC和AUC等来进行辅助判断。混淆矩阵也叫精度矩阵,是用来表示精度评价,为N *N的矩阵,用来判别分类好坏的指标。混淆矩阵中有以下几个概念:TP(True Positive): 被判定为正样本,实际也为正样本FN(False Negative):伪阴性 ,被判定为负样本,实际为正样...转载 2019-05-26 09:08:54 · 1528 阅读 · 0 评论 -
python机器学习常用参考手册
pandas:http://pandas.pydata.org/pandas-docs/stable/reference/index.htmlscikit-learn:https://scikit-learn.org/stable/seaborn:http://seaborn.pydata.org/numpyhttps://www.numpy.org/devdocs/原创 2019-05-25 19:51:04 · 421 阅读 · 0 评论 -
numpy newaxis与expand_dims
numpy.newaxis 为数组增加一个新维度,机器学习的常用框架中处理的数据大多是矩阵,经常需要将一个向量转换成列矩阵或者行矩阵;同样numpy.expand_dims也可以实现对应的功能,效果如下: ...原创 2018-08-28 14:40:38 · 619 阅读 · 0 评论 -
ipynb转换为python文件
使用jupyter-notebook打开ipynb,如下图所示,可以转换为其他格式的文件。 命令行的方式:ipynb转换为pythonjupyter nbconvert --to python my_file.ipynbipynb转换为mdjupyter nbconvert --to md my_file.ipynbipynb转为htmljupyter nbco...原创 2018-08-14 17:33:06 · 30996 阅读 · 1 评论 -
配置Jupyter notebook可以跨机器使用
创建key的步骤如下:step1 生成一个 notebook 配置文件: jupyter notebook --generate-configstep2 生成密码:jupyter notebook passwordjupyter notebook passwordEnter password: ****Verify password: ****[NotebookPasswordApp] Wrot...原创 2018-07-03 17:50:44 · 2876 阅读 · 0 评论 -
目标特征检测之ORB
ORB: Oriented Fast and Rotated BRIEF它是OpenCV_Labs 在2011年提出的,首先它是免费的,而SIFT 和 SURF 是受专利保护,并且要收费的,ORB 是他们的一个替代品,在计算能力比有限的设备上适合这个东西。它的效果: sift > orb > surf, 计算速度 orb > surf > sift#!/usr/bi原创 2016-04-10 11:31:50 · 7479 阅读 · 0 评论 -
目标特征检测之BRIEF描述符
BRIEF:Binary Robust Independent Elementary Rreatures占位原创 2016-03-09 21:22:33 · 6778 阅读 · 0 评论 -
目标特征检测之SIFT特征
#!/usr/bin/env pythonimport cv2img = cv2.imread('chess.png')gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)sift = cv2.SIFT()print sift.shapekp=sift.detect(gray, None)img = cv2.drawKeypoints(gr原创 2016-04-09 18:30:57 · 8117 阅读 · 0 评论 -
目标特征检测之FAST特征
Fast: Feature from Accelerated Segment Test适合在计算能力有限的设备上使用,其速度比SIFT 和SURF快,但是精度有限。#!/usr/bin/env pythonimport cv2img = cv2.imread('chess.png')gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)原创 2016-04-09 20:38:06 · 951 阅读 · 3 评论 -
目标特征检测之SURF特征
SURF: speeded-up robust features是SIFT 的加速版#!/usr/bin/env pythonimport cv2img = cv2.imread('chess.png')gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)surf = cv2.SURF(400)print surf.shapekp,原创 2016-04-09 20:20:19 · 6994 阅读 · 0 评论 -
目标检测之Harris角点特征
占位原创 2016-03-09 21:18:08 · 1263 阅读 · 0 评论 -
python+opencv图像金字塔融合
图像金字塔操作,又分为高斯金字塔和拉普拉斯金字塔,高斯金字塔简单的理解为图像的downsample和upsample. 拉普拉斯金字塔是图像A - up(down(A))的操作,看上去全是边缘。#!/usr/bin/env pythonimport cv2img = cv2.imread('frame.jpg')cv2.imshow('src', img)low原创 2016-04-08 16:34:36 · 8780 阅读 · 6 评论 -
python+opencv鼠标操作以及制作调色板并画图
鼠标操作:#!/usr/bin/env pythonimport numpy as npimport cv2events=[i for i in dir(cv2) if 'EVENT' in i]#events=[i for i in dir(cv2)]print eventsdef draw_circle(event, x, y, flags, param): if原创 2016-04-07 17:02:02 · 9901 阅读 · 3 评论 -
python+opencv画图操作
#!/usr/bin/env pythonimport numpy as npimport cv2img = np.zeros((512,512,3), np.uint8)cv2.line(img, (0,0), (511, 511), (255,0,0), 5) #line color (BGR)cv2.rectangle(img, (384,0), (510, 128), (原创 2016-04-07 11:26:54 · 10215 阅读 · 0 评论 -
python+opencv操作图像视频
直接上code吧,算是学习笔记。#!/usr/bin/env pythonimport numpy as npimport cv2#imread第二个参数为0,强制将图像转换为灰度图像,如果为1,强制转换为彩色图像,-1应该是根据图像自身的信息决定#img = cv2.imread("src.png", 0)img = cv2.imread("src.png", 1)cv2.im原创 2016-04-06 17:43:41 · 10503 阅读 · 0 评论 -
win_python+python_opencv安装配置
Winpython 下载地址:http://sourceforge.net/projects/winpython/?source=typ_redirect注意,里面有python2和python3对应的版本,自己根据实际需要选择一下,默认是下载V3的。下载后一路next安装就行了。里面已经默认包括了matlab对应的libwinpython安装目录下有一个spader.ex原创 2015-10-29 13:46:44 · 502 阅读 · 0 评论 -
python+opencv目标匹配技术
先上两个code吧#!/usr/bin/env pythonimport cv2import numpy as npimg1 = cv2.imread('box.png', 0)img2 = cv2.imread('box_in_scene.png', 0)orb = cv2.ORB_create()kp1, des1 = orb.detectAndCompute(img1原创 2016-04-10 22:34:20 · 8503 阅读 · 0 评论