(1)特征 feature 属性 attribute 训练集 training set 标称型:变量的结果只在有限目标内取值(离散型数据)
(2)类 class 回归 regression 监督学习 supervised learning 监督学习:利用一组已知类别的样本调整分类器的参数,使其达到所要求性能的过程 分类器 classifier
from numpy import*
aArray = array([
[1,1],
[2,2],
[3,3]])
print(aArray.shape[0])
输出:3
print(aArray.shape[1])
输出:2
tile(A, rep) 功能:扩展A的各个维度 ,rep:沿各个维度扩展的次数
inX = [1,2,3]
print(tile(inX,(2,1)))
输出:[[1 2 3]
[1 2 3]]
array.sum(axis, keepdims) 功能:求和计算,axis = 1(按行相加),axis = 0 (按列相加),keepdims = 1 保持维度,无此参数默认为0
bArray = array([[1,2],[3,4],[5,6]])
print(bArray.sum(axis=1, keepdims=True))
输出:[[ 3]
[ 7]
[11]]
print(bArray.sum(axis=0, keepdims=True))
输出:[[ 9 12]]
print(bArray.sum(axis=1))
输出:[ 3 7 11]
argsort(axis) 功能:返回数组从小到大索引值,axis = 1 按行排序,axis = 按列排序 默认为1
cArray = array([2,1,3])
print(cArray.argsort())
输出:[1 0 2]
cArray = array([[2,1,3],
[1,4,3]])
print(cArray.argsort(axis=1))
输出:[[1 0 2]
[0 2 1]]
print(cArray.argsort(axis=0))
输出:[[1 0 0]
[0 1 1]]
sorted() 功能:排序,items() 分解成元祖列表如:{2:1}->[(2,1)], operator.itemgetter(i)获取第i+1个域的值
reverse = True 逆序从大到小排列
from numpy import*
import operator
aDict = {'A':1,'B':2,'C':3}
sortedDict = sorted(aDict.items(), key=operator.itemgetter(1), reverse=True)
print(sortedDict)
输出:[('C', 3), ('B', 2), ('A', 1)] 可用max(classCount,key=classCount.get)替代,返回最大的key
strip() 功能:移除字符串开头或结尾指定的字符,默认为空格或者换行符
aStr = "\n I love Machine Learning,and Math as well \n"
print(aStr)
bStr = aStr.strip()
print(bStr)
输出:
I love Machine Learning,and Math as well I
love Machine Learning,and Math as well
split(str,num) 功能:分割字符 str 无,默认所有空字符,换行等,num分割次数,默认-1分割所有
cStr = "I love Machine Learning,and Math as well"
dStr = cStr.split()
print(cStr,dStr,sep="\n")
输出:I love Machine Learning,and Math as well
['I', 'love', 'Machine', 'Learning,and', 'Math', 'as', 'well']