FTRL 使用tensorflow的实现
import tensorflow as tf
import numpy as np
from sklearn import metrics
from sklearn.datasets import load_svmlight_file
from sklearn.utils import shuffle # Define the placeholder
x = tf.placeholder("float", [None, 12568])
y_ = tf.placeholder("float", [None, 1]) # Define the variable of the model
W = tf.Variable(tf.random_uniform([1, 12568], -1.0, 1.0))
b = tf.Variable(tf.zeros([1]))
y = tf.sigmoid(tf.matmul(x, tf.transpose(W)) + b)
y_pred =tf.sigmoid(tf.matmul(x, tf.transpose(W)) + b)
# clipping y to avoid log(y) become infinite
y = tf.clip_by_value(y, 1e-10, 1-1e-10) # Minimize the negative log likelihood.
loss = (-tf.matmul(tf.transpose(y_), tf.log(y)) - tf.matmul(tf.transpose(1-y_), tf.log(1-y)))
optimizer = tf.train.FtrlOptimizer(0.03, l1_regularization_strength=0.01, l2_regularization_strength=0.01)
train = optimizer.minimize(loss)
auc = tf.metrics.auc(labels=y_,predictions=y)
# Before starting, initialize the variables. We will 'run' this first.
init = tf.group(tf.global_variables_initializer(),tf.local_variables_initializer()) # # Launch the graph.
sess = tf.Session()
sess.run(init) x_train, y_train = load_svmlight_file("./train_data_process")
x_train_new, y_train_new = shuffle(x_train, y_train) for sample_index in range(x_train_new.shape[0]):
sess.run(train, {x:x_train_new[sample_index].toarray(), y_:np.array([y_train_new[sample_index]]).reshape([1,1])})
train_W = sess.run(W)
train_b = sess.run(b)
if sample_index % 200 == 0:
size = 1000
if sample_index+1000 < x_train_new.shape[0]:
print(sample_index,sess.run(loss / size, {x:x_train_new[sample_index:sample_index+1000].toarray(), y_:np.array([y_train_new[sample_index:sample_index+1000]]).reshape([1000,1])})) #End print the model and the training accuracy
print('W:', train_W)
print('b:', train_b) # saver = tf.train.Saver()
# ckpt = tf.train.get_checkpoint_state("./model")
# if ckpt and ckpt.model_checkpoint_path:
# print("Success to load %s." % ckpt.model_checkpoint_path)
# saver.restore(sess, ckpt.model_checkpoint_path)
#
x_data,y_data = load_svmlight_file("./test_data_process")
#
# train_W = sess.run(W)
# train_b = sess.run(b)
# print('W:', train_W)
# print('b:', train_b) y_pre = sess.run(y_pred,feed_dict={x:x_data.toarray(),y_:np.array(y_data).reshape([-1,1])})
auc = metrics.roc_auc_score(y_data.reshape([-1,1]), y_pre)
print(auc) # # #predict_accuracy(train_y, y_data)
使用的是公司的模型训练数据,抽取了 一部分,测试的AUC是0.91
FTRL 使用tensorflow的实现的更多相关文章
- Ftrl in tensorflow
reference :点击这里https://github.com/tensorflow/tensorflow/issues/3725 讲解 http://www.tuicool.com/articl ...
- (转) TensorFlow深度学习,一篇文章就够了
TensorFlow深度学习,一篇文章就够了 2016/09/22 · IT技术 · TensorFlow, 深度学习 分享到:6 原文出处: 我爱计算机 (@tobe迪豪 ) 作者: 陈迪 ...
- TensorFlow深度学习,一篇文章就够了
http://blog.jobbole.com/105602/ 作者: 陈迪豪,就职小米科技,深度学习工程师,TensorFlow代码提交者. TensorFlow深度学习框架 Google不仅是大数 ...
- Tensorflow的基本概念与常用函数
Tensorflow一些常用基本概念与函数(一) 1.tensorflow的基本运作 为了快速的熟悉TensorFlow编程,下面从一段简单的代码开始: import tensorflow as tf ...
- TensorFlow API 汉化
TensorFlow API 汉化 模块:tf 定义于tensorflow/__init__.py. 将所有公共TensorFlow接口引入此模块. 模块 app module:通用入口点脚本. ...
- Tensorflow一些常用基本概念与函数(四)
摘要:本系列主要对tf的一些常用概念与方法进行描述.本文主要针对tensorflow的模型训练Training与测试Testing等相关函数进行讲解.为‘Tensorflow一些常用基本概念与函数’系 ...
- tflearn tensorflow LSTM predict sin function
from __future__ import division, print_function, absolute_import import tflearn import numpy as np i ...
- 5、Tensorflow基础(三)神经元函数及优化方法
1.激活函数 激活函数(activation function)运行时激活神经网络中某一部分神经元,将激活信息向后传入下一层的神经网络.神经网络之所以能解决非线性问题(如语音.图像识别),本质上就是激 ...
- 问题集录--TensorFlow深度学习
TensorFlow深度学习框架 Google不仅是大数据和云计算的领导者,在机器学习和深度学习上也有很好的实践和积累,在2015年年底开源了内部使用的深度学习框架TensorFlow. 与Caffe ...
随机推荐
- git子模块submodule
添加submodule: git submodule add 子模块git地址 把这个module放置的文件夹(这个文件夹须事先不存在) git submodule add http://xxx.x ...
- Oracle中查看建立索引和使用索引的注意点
一.查看和建立索引 select * from user_indexes where table_name = 'student' create index i_student_num on stud ...
- java中使用MD5对密码进行加密
import org.springframework.security.authentication.encoding.MessageDigestPasswordEncoder; import org ...
- Linux系统——文件系统与LVM 逻辑
格式化命令 mkfs. mkswap mkfs格式化数据磁盘 # mkfs -t ext4 /dev/sdb1 # mkfs.ext4 /dev/sdb1 -t 指定格式化文件类型 -b 指定bloc ...
- SQL Server DDL触发器
DDL 触发器作用: DDL 触发器主要用于防止对数据库架构.视图.表.存储过程等进行的某些修改. DDL 触发器事件: DDL 触发器在创建用来监视并响应该数据库或服务器实例中的活动的事件通知时,可 ...
- SQL Server自定义字符串分割函数——Split
我相信大部分人都碰到过,处理数据的时候,字段的值是以 ',' (逗号)分隔的形式,所以我也不能避免. 然后我才知道,sql 是没有类似于 C# 和 Javascript 这种分割字符串的方法.( Sp ...
- 运维自动化之salt笔记
1:saltstack的基本介绍 2:salt的安装 1:服务端1:安装2:配置文件3:运行4:注意事项2:客户端1:安装2:配置文件3:运行4:注意事项 3:salt的使用: 1:基础知识1:tar ...
- 2018秦皇岛ccpc-camp Steins;Gate (原根+FFT)
因为给定的模数P保证是素数,所以P一定有原根. 根据原根的性质,若\(g\)是\(P\)的原根,则\(g^k\)能够生成\([1,P-1]\)中所有的数,这样的k一共有P-2个. 则\(a_i*a_j ...
- centos上安装redmine
1.下载bitnami的redmine安装包 https://bitnami.com/stack/redmine/installer 2.安装remine ./bitnami-redmine-3.3. ...
- imx6q android 添加开机启动脚本
1.在xx/out/target/product/sabresd_6dq/root/init.rc中添加以下内容 ========================================== ...