logistic regression Tensorflow implement notes

python画散点图 和直线

for x1p, x2p, yp in zip(x1, x2, y):
    if yp == 0:
        plt.scatter(x1p, x2p, marker='x', c='r')
    else:
        plt.scatter(x1p, x2p, marker='o', c='g')

x = np.linspace(20, 100, 2)
y = []
for i in x:
    y.append((i * -w[1] - 100*b) / w[0])
plt.plot(x, y)

  

tf.matmul 和 tf.multiply都能用错..

 

归一化

知道归一化可以提高训练的效率,

但是不知道如果不归一化,训练速度和训练效果会差这么多

 

tf.random_normal([2, 1])*0.01和tf.zeros([1, 1])

初始化的值大小很重要,不然不小心就全部是 nan nan nan (无穷大)

tf.placeholder要用 tf.reshape

tY = tf.reshape(pY,[1,m])

tf.placeholder  1.2版的写法

pY = tf.placeholder(tf.float32,shape=(m,1))

 

两种训练方式 batch gradient descent和gradient descent

效果是不同的,代码的写法也完全不同

要清楚自己是在写哪一种...

线性回归 feed参数 的时候 是一个一个feed的,是batch gradient descent的一个极端

logistic regression的时候是一组一组一整个feed的

两个的目的和写法都是不同的,不要傻傻分不清楚

 

tf.split(x,truncate_length,0)

0才是第一维, 1是第二维了,都是因为该死的matlab是从1开始

 

tf.reduce_mean(tf.reduce_sum( aaa ,reduction_indices=[1]))

reduce_mean reduce_sum 每次会减少一个深度

如果只是2维深度的数组,sum之后再mean就没有效果了

 

numpy reshape -1

One shape dimension can be -1. In this case, the value is inferred from the length of the array and remaining dimensions.

 

python[:,0:1]

首先,python下标从0开始,matlab是1

然后,0:1读取的是第一列,0:2才是第一和第二列

 

python加载matlab.txt的数据

pandas函数read_csv可以将 csv(comma-separated values)文件中的数据读入df变量,通过df.values将 DataFrame 转化为二维数组

posted @ 2017-07-24 15:44  烧鸭饭真好吃  阅读(104)  评论(0编辑  收藏  举报