tf.get_variable('x')
获取变量x的值,如果变量名为x的变量没有的话就创建,有的话就引用
详情:https://blog.youkuaiyun.com/weixin_36670529/article/details/97646462
tf.variable_scope()
变量的作用域管理器
tf.variable_scope()的意义,在大项目中,变量很多,第114行有一个v的变量,第339行又出现了v的变量,后面写代码都晕了,搞不清楚。怎么办?搞一个变量管理器,即使变量名一样,但是变量作用域不一样,引用的时候就不会出现穿插问题了,方便代码的维护
详情看:https://blog.youkuaiyun.com/tian_jiangnan/article/details/105047745
np.random.permutation()
随机排列序列。如np.random.permutation(5) [ 2 , 4 , 1 , 0 , 3 ]
np.arange()
函数返回一个有终点和起点的固定步长的排列,如[1,2,3,4,5],起点是1,终点是6,步长为1。
详情看:https://blog.youkuaiyun.com/qq_41550480/article/details/89390579
np.unique()
该函数是去除数组中的重复数字,并进行排序之后输出。
使用sklearn库函数来切分训练集和测试集
from sklearn.model_selection import train_test_split
train_set, test_set = train_test_split(housing, test_size = 0.2, random_state=42)
sk-learn中提StratifiedShuffleSplit()提供分层抽样功能,确保每个标签对应的样本的比例
详情看:https://blog.youkuaiyun.com/wtzhu_13/article/details/93903868
split.split
详情看:https://blog.youkuaiyun.com/dss_dssssd/article/details/82818601
loc函数:通过行索引 “Index” 中的具体值来取行数据(如取"Index"为"A"的行)
iloc函数:通过行号来取行数据(如取第二行的数据)
astype(np.int8)
类型转换
data.info() 查看数据详情,可以查看数据缺失情况和数据类型
sgd_clf.decision_function([some_digit])
通过decision_function可以获得一种"分值",这个分值的几何意义就是当前点到超平面(hyperplane)的距离
fit_transform 和transform的区别:
一般训练集用fit_transform,测试集用transform
详情:https://blog.youkuaiyun.com/quiet_girl/article/details/72517053
np.r_是按列连接两个矩阵,就是把两矩阵上下相加,要求列数相等。
np.c_是按行连接两个矩阵,就是把两矩阵左右相加,要求行数相等。
predict返回的是一个预测的值,predict_proba返回的是对于预测为各个类别的概率。
numpy.apply_along_axis(func, axis, arr, *args, **kwargs)
将arr数组的每一个元素经过func函数变换形成的一个新数组
详情:https://blog.youkuaiyun.com/starmoth/article/details/83832458
n_jobs:用来设定CPU运行情况,n_jobs=-1便是使用全部的CPU。
GridSearchCV
详情:https://blog.youkuaiyun.com/weixin_41988628/article/details/83098130
reshape
reshape(-1) 变成数组/行向量
reshape(-1,1) 不知道多少行,1列
详情:https://www.zhihu.com/question/52684594
求范数
x_norm=np.linalg.norm(x, ord=None, axis=None, keepdims=False)
https://blog.youkuaiyun.com/hqh131360239/article/details/79061535
画图
plt.axis(“off”) 关闭坐标轴详情: [https://www.cnblogs.com/shuaishuaidefeizhu/p/14034415.html](https://www.cnblogs.com/shuaishuaidefeizhu/p/14034415.html)
ax = fig.add_subplot(349) 参数349的意思是:将画布分割成3行4列,图像画在从左到右从上到下的第9块 [https://blog.youkuaiyun.com/rootkiss/article/details/88191336](https://blog.youkuaiyun.com/rootkiss/article/details/88191336)