内置函数
array.flatten() # 将array数组多维边1维
OS
os.path.sep:路径分隔符 linux下就用这个了’/’os.path.altsep: 根目录os.path.curdir:当前目录os.path.pardir:父目录os.path.abspath(path):绝对路径os.path.join(): 常用来链接路径os.path.split(path): 把path分为目录和文件两个部分,以列表返回
random
# seed()没有参数时,每次生成的随机数是不一样的,# 而当seed()有参数时,每次生成的随机数是一样的random.seed(number) # list的值,打乱 随机排列random.shuffle(list)
numpy
import numpy as npnp.array([[1,2,3], [2,3,4]], dtype=np.float) #定义矩阵,float64
sklearn-learn
from sklearn.model_selection import train_test_splittrain_test_split # 函数是用来随机划分样本数据为训练集和测试集的,当然也可以人为的切片划分完整模板:train_X,test_X,train_y,test_y = train_test_split(train_data,train_target,test_size=0.3,random_state=5)参数解释:train_data:待划分样本数据train_target:待划分样本数据的结果(标签)test_size:测试数据占样本数据的比例,若整数则样本数量random_state:设置随机数种子,保证每次都是同一个随机数。若为0或不填,则每次得到数据都不一样返回值:X_train,y_train:得到的训练数据。X_test, y_test:得到的测试数据。------------------------------------------------------------------------------------------from sklearn.preprocessing import LabelBinarizer# 特征矩阵featureList=[[1,0],[1,1],[0,0],[0,1]]# 标签矩阵 转换标签,one-hot格式labelList=['yes', 'no', 'no', 'yes']# 将标签矩阵二值化lb = LabelBinarizer()dummY=lb.fit_transform(labelList)trainY = lb.fit_transform(trainY) # 训练数据testY = lb.transform(testY) # 测试数据