
python
文章平均质量分 67
Joy CR
欢迎关注我的公众号: 小秋的博客
https://blog.youkuaiyun.com/xiaoqiu_cr
https://github.com/crr121
https://segmentfault.com/u/chenrong_flying
联系邮箱:rongchen633@gmail.com
展开
-
python学习笔记一
python是一种解释语言,不需要编译,但是它的运行效率并不低,因为它产生的是一种近似机器语言的中间形式,是通过字节编译的。查看python解释器的安装路径 import sys print (sys.path) 3 输出方式和C语言相似num = raw_input('please input a number:')num = int(num)*2print ('dou原创 2017-07-24 22:08:25 · 195 阅读 · 0 评论 -
python3访问map
python2打印map对象可以直接print map但是python3需要将之转为list对象,print(list(map))原创 2018-01-15 17:01:04 · 1128 阅读 · 0 评论 -
python3 .6 下 报错 RuntimeError: dictionary changed size during iteration
循环字典键值,删除不符合要求的键值对def createTree(dataSet, minSup=1): #create FP-tree from dataset but don't mine headerTable = {} #go over dataSet twice for trans in dataSet:#first pass counts frequency of转载 2018-01-25 11:44:17 · 447 阅读 · 1 评论 -
k-均值聚类
1、k-均值聚类1.1、伪代码创建k个点作为起始质心(经常是随机选择)当任意一个点的簇分配结果发生改变时对数据集中的每个数据点. 对每个质心计算质心与数据点之间的距离将数据点分配到距其最近的簇对每一个簇,计算簇中所有点的均值并将均值作为质心1.2、核心代码from numpy import *#将数据集每一行按照tab符号分割,并转为float类型,原创 2018-01-09 18:11:32 · 624 阅读 · 0 评论 -
树回归-CART
1、树回归的提出背景线性回归需要拟合所有的样本(除了局部加权性回归),实际生活中大部分的问题是非线性的。所以需要将数据集进行切分成很多份容易建模的数据,然后利用线性回归的方法进行建模。但是一般一两次的切分仍然不能满足要求,所以就提出了树回归的方法2、CART(classification and regression trees) 分类回归树该算法不仅能用于分类,还能用于回归。2....原创 2018-01-03 14:33:25 · 482 阅读 · 0 评论 -
Apriori进行关联分析
一、术语解释关联分析:从大规模数据集中挖掘物品之间的隐含关系频繁项集:经常出现在一块的物品集合关联规则:暗示两种物品之间可能存在很强的关联关系项集支持度:数据集中包含该项集的记录比例(这里可以定义一个最小项集的支持度,筛选出那些项集出现次数不是那么多,项集支持度不是那么大的集合)关联规则{a}->{b}置信度:{a,b}的支持度/{a}的支持度二、目标与假设假设商店有4中商品:0 1 2 3而我们原创 2018-01-18 14:48:54 · 603 阅读 · 0 评论 -
python-类
1、类#新式类(后面会跟一个参数,用于单继承或者多继承的父类)class MyNewObject(object): pass#pass表示不执行任何操作但是在语法上需要一行语句#经典类(没有继承任何其他父类)class MyNewObject: pass2、类的实例化(实例对象的独有属性)#类的实例化(函数调用的形式)if __name__ == '__main__':原创 2018-01-19 11:06:22 · 185 阅读 · 0 评论 -
矩阵与列表取出行(左开右闭)
对于矩阵:import numpysimpDat = [['r', 'z', 'h', 'j', 'p'], ['z', 'y', 'x', 'w', 'v', 'u', 't', 's'], ['z'], ['r', 'x', 'n', 'o', 's'], ['y', 'r', 'x', 'z', '原创 2018-02-05 11:17:29 · 533 阅读 · 0 评论 -
TypeError: '<' not supported between instances of 'treeNode' and 'treeNode'
bigL = [v[0] for v in sorted(headerTable.items(), key=lambda p: p[1])]#(sort header table)TypeError: '这个的意思就是比较的对象不支持小于符号也就是我们的对象有问题,这里我的p[1]是节点类型 headerTable: {'p': [2, None], 'h': [1, None],原创 2018-02-05 16:34:15 · 2873 阅读 · 0 评论 -
构建FP-growth算法高效发现频繁项集
1、构建FP树1.1创建FP树的结构#创建FP树的数据结构#FP树的类定义class treeNode: def __init__(self, nameValue, numOccur, parentNode): self.name = nameValue self.count = numOccur self.nodeLink =原创 2018-02-05 17:28:59 · 408 阅读 · 0 评论 -
python 切片
from numpy import *if __name__ == '__main__': a = [[1,2,3,4,5],[3,4,5,6,7],[1,4,5,6,74],[23,4,5,6,7]] print(a[::1]) #正向开始,不取最后一个元素 print(a[:-1]) #从末尾开始到倒数第三个,步长为-1,最后一个数的正负表示方向,大小原创 2018-02-06 14:52:50 · 247 阅读 · 0 评论 -
数组与列表访问某一列的方法不同
from numpy import *if __name__ == '__main__': a = [[1,2,3,4,5],[3,4,5,6,7],[1,4,5,6,74],[23,4,5,6,7]] for x in a: print(x[0]) b = array(a) print(b[:,0])13123[ 1 3 1 23]原创 2018-02-06 15:04:15 · 271 阅读 · 0 评论 -
list indices must be integers or slices, not tuple
File "E:\Python36\regtree.py", line 45, in chooseBestSplit if len(set(dataSet[:,-1].T.tolist()[0])) == 1: #exit cond 1TypeError: list indices must be integers or slices, not tuple在测试树回归的时候,一直原创 2017-12-26 17:10:48 · 2585 阅读 · 0 评论 -
flatten的用法
from numpy import *if __name__ == '__main__': ''' flatten 用于数组 ''' a = array([[1,2,3,4,5],[3,4,5,6,7],[1,4,5,6,74],[23,4,5,6,7]]) print(type(a)) print(a.flatten()) '''原创 2018-02-06 16:05:35 · 656 阅读 · 0 评论 -
matrix.A
if __name__ == '__main__': from numpy import * a = mat([[0, 0, 0, 2, 2], [0, 0, 0, 3, 3], [0, 0, 0, 1, 1], [1, 1, 1, 0, 0], [2, 2, 2, 0, 0],原创 2018-02-07 14:41:03 · 504 阅读 · 0 评论 -
TypeError: list indices must be integers or slices, not tuple
由于dataset是一个列表>>> dataset[[1.658985, 4.285136], [-3.453687, 3.424321], [4.838138, -1.151539], [-5.379713, -3.362104], [0.972564, 2.924086], [-3.567919, 1.531611], [0.450614, -3.302219], [-3.487105,原创 2018-01-03 16:33:13 · 4657 阅读 · 2 评论 -
IndexError: tuple index out of range
错误代码:def loadDataSet(fileName): #general function to parse tab -delimited floats dataMat = [] #assume last column is target value fr = open(fileName) for line in fr.r原创 2018-01-03 16:12:05 · 3709 阅读 · 0 评论 -
python内建函数type()
print type('')s='xyd'print type(s)print type(199)print type(0+0j)print type(1+8j)print type('long')print type(0.0)print type([])print type(())print type(type)class Foo:passfoo = Foo()print原创 2017-08-06 23:22:06 · 409 阅读 · 0 评论 -
python-访问模型
1、访问模型的分类 python中数据分类的方式是按照数据的访问方式来进行分类 一共有三种方式: 直接访问:数字(标量)(不可更改) 顺序访问:字符串(标量)(不可更改),列表(容器)(可更改),元组(容器)(不可更改) 映射访问:字典(容器)(可更改)原创 2017-11-22 16:03:38 · 338 阅读 · 0 评论 -
python学习笔记二
for循环 python的for循环和我们传统的for循环不一样,python中的for循环迭代的是一个序列# for循环可以表示数组的每一个元素# for eachnum in [1,2,3]# print eachnum,# for 循环还可以表示迭代一个序列# for each in range(1,11):--->注意如果迭代是一个函数需要加冒号# print原创 2017-07-30 18:34:33 · 316 阅读 · 0 评论 -
python对象身份的比较
对象和类 对象=属性+方法 python是把所有的都当做一个对象,属性就是一个具体的值,而方法就是对于对象来说,可以通过什么方法来操作对象。对象身份的比较foo1=foo2=4.3 --->可能我们会认为这是一个多重赋值的过程,将4.3赋值为foo1,foo2这两个变量,但是实际上是创建了一个4.3的数字对象,然后将这个对象的引用赋值给foo1,foo2,也就是说foo1和foo2得到不是4原创 2017-08-02 21:36:21 · 2205 阅读 · 0 评论 -
python数字
1、复数aComplex = -1.33 + 2.44j;print aComplex;# (-1.33+2.44j)print aComplex.real;print aComplex.imag;# -1.33# 2.44print aComplex.conjugate();# (-1.33-2.44j) 共轭复数2、除法print (1/2);print (1.0/2.0);原创 2017-12-04 11:44:55 · 470 阅读 · 0 评论 -
numpy库
1、创建随机矩阵>>> from numpy import *>>> random.rand(4,4)array([[ 0.1801566 , 0.02580119, 0.02685281, 0.52768083], [ 0.45411008, 0.7831068 , 0.21375316, 0.5834276 ], [ 0.14515285, 0.56原创 2017-12-05 09:26:19 · 296 阅读 · 0 评论 -
矩阵降维-将矩阵按照某列进行排序
将三维矩阵转为二维矩阵矩阵降维-将矩阵按照某列进行排序from numpy import *a = mat([[1,34,3],[2,3,41],[2,34,41],[2,53,41]])print(a)srtInd=a[:,1].argsort(0)print(srtInd)print(a[srtInd])print("====")print(a[srtInd][:,原创 2017-12-22 11:22:53 · 2093 阅读 · 0 评论 -
python数字
1、切片操作#!/usr/bin/env python# -*- coding: utf-8 -*-# 切片操作names = ('aa','bb','cc','dd','ee');print names[0];print names[2];print names[:];print names[0:2];print names[2:];print names[::1];# aa原创 2017-12-04 14:25:30 · 192 阅读 · 0 评论 -
matplotlib
import matplotlib.pyplot as plt from numpy import * fig = plt.figure() ax = fig.add_subplot(223) ax.plot(x,y) plt.show() 参数223的意思是:将画布分割成2行2列,图像画在从左到右从上到下的第3块原创 2017-12-05 15:01:00 · 213 阅读 · 0 评论 -
矩阵转列表
矩阵转列表from numpy import *a = mat([[1,34,3],[2,3,41],[2,34,41],[2,53,41]])print(a.flatten())print(a.flatten().A)#矩阵转为列表print(a.flatten().A[0])'''[[ 1 34 3 2 3 41 2 34 41 2 53 41]][[ 1 34原创 2017-12-22 11:41:59 · 457 阅读 · 0 评论 -
python矩阵
B=min(A):获得矩阵A每一列的最小值,返回值B为一个行向量,其第i列对应A矩阵第i列的最小值。 C=max(A) :获得矩阵A每一列的最大值,返回值C为一个行向量,其第i列对应A矩阵第i列的最大值。import numpy as npa = np.array([[1,5,3],[4,2,6]])print(a.min()) #无参,所有中的最小值print(a.min(0)) # ax原创 2017-12-07 10:24:25 · 440 阅读 · 0 评论 -
python安装.whl文件失败
安装wheel pip install wheel以安装scipy为例,在官网下载安装包https://pypi.python.org/pypi/scipy一定要注意这里的版本一定要和你的python所支持的版本一直否则会出现C:\Users\xiaoqiu>pip install F:\browser\Google\scipy-1.0.0-cp36-cp36m-manylinux1_x86原创 2017-12-27 14:26:22 · 3151 阅读 · 0 评论 -
矩阵转列表
矩阵转列表>>> testMatmatrix([[ 1., 0., 0., 0.], [ 0., 1., 0., 0.], [ 0., 0., 1., 0.], [ 0., 0., 0., 1.]])>>> testMat[:,-1]matrix([[ 0.], [ 0.], [ 0.原创 2017-12-26 15:04:34 · 881 阅读 · 0 评论 -
正则表达式
str = "thon.exe H:/python_workspace/test/test.py"import re#\\w* : \ + \w + *# 转义\w 匹配任意字母或数字或下划线或汉字 \w出现0次或多次regEX = re.原创 2017-12-12 16:00:51 · 124 阅读 · 0 评论 -
支持向量机SVM
SVM的优缺点优点:泛化错误率低,计算开销不大,结果容易解释缺点:对参数的调节和核函数的选择敏感,原始分类器不佳修改仅适用于处理二分类问题SVM的目的:找到一个超平面,也就是分类的决策边界,使得离超平面最近的点尽可能的远,而那些最近的点就是支持向量如何寻找最大间隔:分隔超平面的形式:原创 2018-01-03 14:32:43 · 364 阅读 · 0 评论 -
TypeError: Only length-1 arrays can be converted to Python scalars
#p1Vect也是一个向量 p1Vect = math.log(p1Num / p1Denom) p0Vect = math.log(p0Num / p0Denom)报错如下:TypeError: Only length-1 arrays can be converted to Python scalars原因:math.log()不能直接处理矩阵reso...原创 2018-08-19 11:26:22 · 1458 阅读 · 0 评论