paddlepaddle是百度提出来的深度学习的框架,个人感觉其实和tensorflow差不多(语法上面),因为本人也是初学者,也不是很懂tensorflow,所以,这些都是个人观点。
百度的paddlepaddle提出貌似有一段时间了,我是最近才知道的,好奇去看了看,而且最近在看tensorflow,所以想看看paddlepaddle是不是友好一点,说实话,tensorflow还是比较难懂的(对于个人来说)。感觉paddlepaddle比tensorflow好的地方在于,paddlepaddle有百度的工程师给出对应视频和代码进行讲解,对于入门深度学习比较好。
以下就是paddlepaddle的第一讲,利用波士顿房价讲解线性回归。

模型训练:

#-*- coding:utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
import os
import paddle.v2 as paddle
import paddle.v2.dataset.uci_housing as uci_housingwith_gpu = os.getenv('WITH_GPU', '0') != '0'def main():# 初始化PaddlePaddlepaddle.init(use_gpu=with_gpu, trainer_count=1)# 模型配置x = paddle.layer.data(name='x', type=paddle.data_type.dense_vector(13))#利用前13因数来预测房价y_predict = paddle.layer.fc(input=x, size=1, act=paddle.activation.Linear())#预测的房价值,线性激活函数y = paddle.layer.data(name='y', type=paddle.data_type.dense_vector(1))#实际的房价值cost = paddle.layer.square_error_cost(input=y_predict, label=y)#损失函数# 保存网络拓扑inference_topology = paddle.topology.Topology(layers=y_predict)with open("inference_topology.pkl", 'wb') as f:inference_topology.serialize_for_inference(f)# 创建参数parameters = paddle.parameters.create(cost)# 创建traineroptimizer = paddle.optimizer.Momentum(momentum=0)#learning_rate=0.0001 学习率trainer = paddle.trainer.SGD(cost=cost, parameters=parameters, update_equation=optimizer)#随机梯度下降算法feeding = {'x': 0, 'y': 1}# 读取数据且打印训练的中间信息def event_handler(event):if isinstance(event, paddle.event.EndIteration):if event.batch_id % 100 == 0:print "Pass %d, Batch %d, Cost %f" % (event.pass_id, event.batch_id, event.cost)if isinstance(event, paddle.event.EndPass):if event.pass_id % 10 == 0:with open('params_pass_%d.tar' % event.pass_id, 'w') as f:trainer.save_parameter_to_tar(f)result = trainer.test(reader=paddle.batch(uci_housing.test(), batch_size=2),feeding=feeding)#读取房价数据,将数据打乱,每次取出2条print "Test %d, Cost %f" % (event.pass_id, result.cost)# 开始训练trainer.train(reader=paddle.batch(paddle.reader.shuffle(uci_housing.train(), buf_size=500),batch_size=2),feeding=feeding,event_handler=event_handler,#提供一个 event_handler,来打印训练的进度:num_passes=30)# 生成测试数据test_data_creator = paddle.dataset.uci_housing.test()test_data = []test_label = []#取出测试集中5条数据用于最后的预测for item in test_data_creator():test_data.append((item[0], ))test_label.append(item[1])if len(test_data) == 5:break#推测inferenceprobs = paddle.infer(output_layer=y_predict, parameters=parameters, input=test_data)for i in xrange(len(probs)):print "label=" + str(test_label[i][0]) + ", predict=" + str(probs[i][0])if __name__ == '__main__':main()

运行结果:

Pass 0, Batch 0, Cost 886.077026
Pass 0, Batch 100, Cost 236.768433
Pass 0, Batch 200, Cost 555.669922
Test 0, Cost 56.372781
Pass 1, Batch 0, Cost 558.157104
Pass 1, Batch 100, Cost 17.486526
Pass 1, Batch 200, Cost 49.110359
Test 1, Cost 22.666769
Pass 2, Batch 0, Cost 2.017142
Pass 2, Batch 100, Cost 5.376208
Pass 2, Batch 200, Cost 1.576212
Test 2, Cost 18.296844
Pass 3, Batch 0, Cost 103.864586
Pass 3, Batch 100, Cost 84.158134
Pass 3, Batch 200, Cost 5.564497
Test 3, Cost 17.668033
Pass 4, Batch 0, Cost 2.316584
Pass 4, Batch 100, Cost 9.555552
Pass 4, Batch 200, Cost 74.418373
Test 4, Cost 17.311696
Pass 5, Batch 0, Cost 9.540855
Pass 5, Batch 100, Cost 22.676167
Pass 5, Batch 200, Cost 123.998085
Test 5, Cost 16.799527
Pass 6, Batch 0, Cost 56.558044
Pass 6, Batch 100, Cost 33.035114
Pass 6, Batch 200, Cost 58.189980
Test 6, Cost 16.333503
Pass 7, Batch 0, Cost 7.590010
Pass 7, Batch 100, Cost 34.771137
Pass 7, Batch 200, Cost 44.883244
Test 7, Cost 16.017060
Pass 8, Batch 0, Cost 42.311310
Pass 8, Batch 100, Cost 24.567163
Pass 8, Batch 200, Cost 33.340485
Test 8, Cost 15.520346
Pass 9, Batch 0, Cost 178.452744
Pass 9, Batch 100, Cost 10.791793
Pass 9, Batch 200, Cost 0.137641
Test 9, Cost 15.214742
Pass 10, Batch 0, Cost 10.072014
Pass 10, Batch 100, Cost 11.594021
Pass 10, Batch 200, Cost 24.404564
Test 10, Cost 14.916112
Pass 11, Batch 0, Cost 5.649694
Pass 11, Batch 100, Cost 31.902603
Pass 11, Batch 200, Cost 11.218608
Test 11, Cost 14.600422
Pass 12, Batch 0, Cost 87.761772
Pass 12, Batch 100, Cost 53.684475
Pass 12, Batch 200, Cost 37.861378
Test 12, Cost 14.326864
Pass 13, Batch 0, Cost 5.141076
Pass 13, Batch 100, Cost 0.324465
Pass 13, Batch 200, Cost 2.333709
Test 13, Cost 14.124264
Pass 14, Batch 0, Cost 9.482045
Pass 14, Batch 100, Cost 22.704296
Pass 14, Batch 200, Cost 12.826228
Test 14, Cost 13.945640
Pass 15, Batch 0, Cost 41.819580
Pass 15, Batch 100, Cost 10.353182
Pass 15, Batch 200, Cost 13.374403
Test 15, Cost 13.767083
Pass 16, Batch 0, Cost 83.044785
Pass 16, Batch 100, Cost 27.363625
Pass 16, Batch 200, Cost 5.347357
Test 16, Cost 13.665516
Pass 17, Batch 0, Cost 0.994224
Pass 17, Batch 100, Cost 0.298174
Pass 17, Batch 200, Cost 140.061615
Test 17, Cost 13.568394
Pass 18, Batch 0, Cost 11.832894
Pass 18, Batch 100, Cost 8.340067
Pass 18, Batch 200, Cost 30.967430
Test 18, Cost 13.465723
Pass 19, Batch 0, Cost 15.379287
Pass 19, Batch 100, Cost 123.313614
Pass 19, Batch 200, Cost 36.328705
Test 19, Cost 13.377999
Pass 20, Batch 0, Cost 12.842525
Pass 20, Batch 100, Cost 54.218903
Pass 20, Batch 200, Cost 18.377592
Test 20, Cost 13.266518
Pass 21, Batch 0, Cost 49.386784
Pass 21, Batch 100, Cost 215.253906
Pass 21, Batch 200, Cost 0.260682
Test 21, Cost 13.237288
Pass 22, Batch 0, Cost 469.974213
Pass 22, Batch 100, Cost 8.073731
Pass 22, Batch 200, Cost 0.810365
Test 22, Cost 13.192008
Pass 23, Batch 0, Cost 145.341141
Pass 23, Batch 100, Cost 15.787022
Pass 23, Batch 200, Cost 4.965213
Test 23, Cost 13.133022
Pass 24, Batch 0, Cost 10.377566
Pass 24, Batch 100, Cost 3.863908
Pass 24, Batch 200, Cost 15.857657
Test 24, Cost 13.113067
Pass 25, Batch 0, Cost 6.239013
Pass 25, Batch 100, Cost 15.914387
Pass 25, Batch 200, Cost 48.752701
Test 25, Cost 13.137239
Pass 26, Batch 0, Cost 57.843086
Pass 26, Batch 100, Cost 0.732344
Pass 26, Batch 200, Cost 48.501846
Test 26, Cost 13.141359
Pass 27, Batch 0, Cost 443.271545
Pass 27, Batch 100, Cost 227.696655
Pass 27, Batch 200, Cost 1.482114
Test 27, Cost 13.094058
Pass 28, Batch 0, Cost 11.784382
Pass 28, Batch 100, Cost 1.334578
Pass 28, Batch 200, Cost 16.487831
Test 28, Cost 13.122105
Pass 29, Batch 0, Cost 10.043719
Pass 29, Batch 100, Cost 26.890572
Pass 29, Batch 200, Cost 11.034937
Test 29, Cost 13.203439
label=8.5, predict=11.7476
label=5.0, predict=13.6822
label=11.9, predict=10.7325
label=27.9, predict=18.0696
label=17.2, predict=13.0193

房价预测:

#-*- coding:utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
import paddle.v2 as paddle# Initialize PaddlePaddle.
paddle.init(use_gpu=False, trainer_count=1)# Configure the neural network.
x = paddle.layer.data(name='x', type=paddle.data_type.dense_vector(13))
y_predict = paddle.layer.fc(input=x, size=1, act=paddle.activation.Linear())# Infer using provided test data.
probs = paddle.infer(output_layer=y_predict,parameters=paddle.dataset.uci_housing.model(),input=[item for item in paddle.dataset.uci_housing.test()()])for i in xrange(len(probs)):print 'Predicted price: ${:,.2f}'.format(probs[i][0] * 1000)

运行结果:

Predicted price: $12,316.63
Predicted price: $13,830.34
Predicted price: $11,499.34
Predicted price: $17,395.05
Predicted price: $13,317.67
Predicted price: $16,834.08
Predicted price: $16,632.04
Predicted price: $15,384.20
Predicted price: $7,697.38
Predicted price: $13,657.83
Predicted price: $6,329.62
Predicted price: $12,153.18
Predicted price: $13,890.60
Predicted price: $11,367.41
Predicted price: $13,269.13
Predicted price: $14,979.35
Predicted price: $17,539.03
Predicted price: $16,686.41
Predicted price: $16,810.74
Predicted price: $13,620.53
Predicted price: $14,720.09
Predicted price: $12,533.42
Predicted price: $15,835.49
Predicted price: $16,064.76
Predicted price: $14,566.97
Predicted price: $13,783.11
Predicted price: $16,211.73
Predicted price: $16,362.79
Predicted price: $18,183.92
Predicted price: $16,298.03
Predicted price: $16,084.58
Predicted price: $14,406.07
Predicted price: $15,309.62
Predicted price: $12,104.60
Predicted price: $9,865.44
Predicted price: $14,116.36
Predicted price: $14,552.37
Predicted price: $16,381.32
Predicted price: $16,992.90
Predicted price: $16,722.93
Predicted price: $13,468.48
Predicted price: $13,622.97
Predicted price: $16,512.31
Predicted price: $17,004.60
Predicted price: $16,492.97
Predicted price: $16,179.70
Predicted price: $15,989.17
Predicted price: $17,289.17
Predicted price: $16,975.07
Predicted price: $18,950.22
Predicted price: $15,513.54
Predicted price: $15,652.08
Predicted price: $14,162.51
Predicted price: $14,665.31
Predicted price: $16,724.47
Predicted price: $17,369.51
Predicted price: $17,330.55
Predicted price: $17,923.71
Predicted price: $18,018.71
Predicted price: $19,392.96
Predicted price: $18,379.00
Predicted price: $17,187.61
Predicted price: $14,920.71
Predicted price: $15,435.08
Predicted price: $16,458.07
Predicted price: $17,390.93
Predicted price: $17,520.05
Predicted price: $18,763.72
Predicted price: $18,698.70
Predicted price: $20,425.67
Predicted price: $15,431.77
Predicted price: $14,803.56
Predicted price: $17,336.69
Predicted price: $13,052.34
Predicted price: $16,874.23
Predicted price: $18,547.62
Predicted price: $19,574.30
Predicted price: $21,303.89
Predicted price: $22,053.60
Predicted price: $18,862.40
Predicted price: $17,969.15
Predicted price: $19,496.96
Predicted price: $17,676.56
Predicted price: $18,699.87
Predicted price: $14,520.48
Predicted price: $12,410.05
Predicted price: $9,987.12
Predicted price: $15,381.11
Predicted price: $16,906.17
Predicted price: $21,538.57
Predicted price: $21,566.74
Predicted price: $19,905.33
Predicted price: $17,938.98
Predicted price: $20,776.08
Predicted price: $21,715.28
Predicted price: $20,169.60
Predicted price: $21,148.05
Predicted price: $22,589.09
Predicted price: $21,913.31
Predicted price: $24,388.41
Predicted price: $23,748.72
Predicted price: $22,013.94

PaddlePaddle 波斯顿房价预测训练结果相关推荐

  1. scikit-learn线性回归实践 - 波斯顿房价预测

    Educoder实训平台机器学习-线性回归:scikit-learn线性回归实践 - 波斯顿房价预测 (下方代码已成功通过平台测试) 文章目录 机器学习:波士顿房价数据集 任务描述 相关知识 Line ...

  2. 波士顿房价预测python代码_Python之机器学习-波斯顿房价预测

    AI 人工智能 Python之机器学习-波斯顿房价预测 波士顿房价预测 导入模块 import pandas as pd import numpy as np import matplotlib.py ...

  3. 数据挖掘竞赛-美国King County房价预测训练赛

    美国King County房价预测训练赛 简介 DC上的一个回归题(正经的回归题). 比较简单. 时间原因(暂时没什么时间看国内旧赛),看了一下网上的解答,改善了一下神经网络就提交了. 过程 数据获取 ...

  4. bagging回归 波斯顿房价预测

    #bagging回归 波斯顿房价预测from sklearn.datasets import load_bostonboston = load_boston()from sklearn.model_s ...

  5. 数据分析 回归问题: 美国King County房价预测训练赛

    这是DC竞赛网的一道基础回归问题, 美国King County房价预测训练赛 竞赛详细信息:美国King County房价预测训练赛 任务:从给定的房屋基本信息以及房屋销售信息等,建立一个回归模型预测 ...

  6. 极简PaddlePaddle的房价预测Demo

    简 介: ※利用最简单的线性关系预测数据之间的相关性. 关键词: 线性相关,预测# #mermaid-svg-7sGsiuDJBmN3r5cU {font-family:"trebuchet ...

  7. Eudcoder scikit-learn线性回归实践 - 波斯顿房价预测

    任务描述 本关任务:你需要调用 sklearn 中的线性回归模型,并通过波斯顿房价数据集中房价的13种属性与目标房价对线性回归模型进行训练.我们会调用你训练好的线性回归模型,来对房价进行预测. 相关知 ...

  8. 02-06 普通线性回归(波斯顿房价预测)+特征选择

    文章目录 普通线性回归(波士顿房价预测) 导入模块 获取数据 打印数据 特征选择 散点图矩阵 关联矩阵 训练模型 可视化 普通线性回归(波士顿房价预测) 导入模块 import pandas as p ...

  9. 机器学习 | 一个基于机器学习的简单小实践:波斯顿房价预测分析

    本文采用Kaggle上面的Boston HousePrice数据集展示了如何建立机器学习模型的通常过程,包括以下几个阶段: 数据获取 数据清洗 探索性数据分析 特征工程 模型建立 模型集成 标签变量( ...

最新文章

  1. oracle数据库视图存放位置,oracle数据库审计
  2. Web内核微信小程序框架实践
  3. leetcode991. 坏了的计算器(贪心)
  4. php如何删除数据mysql数据库_php如何删除数据库
  5. mysql怎么分组查询所有数据库_Mysql-4 分组查询与子查询
  6. 下载 6g 概念及愿景白皮书_6G,到底有多6?6G概念及愿景白皮书正式发布!
  7. t检验的显著性p值python_Python P值
  8. python实现 模糊C均值聚类算法(Fuzzy-C-Means)-基于iris数据集
  9. 自然语言处理Java开源包FNLP(FudanNLP)的使用
  10. xslx-style导出,表头样式表格样式,指定条件
  11. ei拼音的四个声调对应的字_幼儿园学前班拼音教案复习ei以及四声调
  12. 定制开发 app 的好处都有哪些?
  13. 康托尔悖论:大全集不存在,即包含一切集合的集合是否存在
  14. 计算机毕业设计JAVA共享充电宝系统mybatis+源码+调试部署+系统+数据库+lw
  15. 梦行扫码付(收银台条码支付 微信钱包条码支付 支付宝二维码支付 手机APP钱包支付 PHP扫码支付 )
  16. 这段代码不讲武德,劝你耗子尾汁
  17. 这次,AMD又将数据中心标准提高了一大截
  18. 解决只读文件系统问题
  19. 最牛ks短视频评论采集软件
  20. [ WARN] [1588040435.867625184]: MessageFilter [target=odom ]: Dropped 97.37% of messages so

热门文章

  1. 在线EXCEL编辑器-Luckysheet
  2. 零基础想学大数据?别急!先搞清这一点
  3. 背景运动补偿具体思路
  4. SpringSecurity之授权
  5. 转《MCU低功耗设计》
  6. 晚上改吃水果+牛奶(防止营养不够)
  7. 基于C++实现(控制台+界面)通讯录管理系统【100010012】
  8. python tkinter 表格 怎么设置字体大小_更改字体大小而不影响Tkinter按钮大小
  9. 一作发表8篇SCI,这位双一流高校博士生是怎么做到的?
  10. 变态矿工源码、闪电鸡app等软件的应用及发展方向的个人见解