当前位置: 首页 > news >正文

阿甘网站建设网站怎么做出来的

阿甘网站建设,网站怎么做出来的,河北网站备案多久,网站做百度推广需要哪些条件Spark MLlib概述机器学习房价预测模型选型数据探索数据提取准备训练样本模型训练模型效果评估机器学习 机器学习的过程 : 基于历史数据,机器会根据一定的算法,尝试从历史数据中挖掘并捕捉出一般规律再把找到的规律应用到新产生的数据中,从而…

Spark MLlib概述

  • 机器学习
  • 房价预测
    • 模型选型
    • 数据探索
    • 数据提取
    • 准备训练样本
    • 模型训练
    • 模型效果评估

机器学习

机器学习的过程 :

  1. 基于历史数据,机器会根据一定的算法,尝试从历史数据中挖掘并捕捉出一般规律
  2. 再把找到的规律应用到新产生的数据中,从而实现在新数据上的预测与判断

在这里插入图片描述

机器学习(Machine Learning): 一种计算过程:

  1. 对于给定的训练数据(Training samples),选择一种先验的数据分布模型(Models)
  2. 借助优化算法(Learning Algorithms)自动地持续调整模型参数(Model Weights / Parameters)
  3. 让模型不断逼近训练数据的原始分布

模型训练 (Model Training) : 调整模型参数的过程

  • 根据优化算法,基于过往的计算误差 (Loss),优化算法以不断迭代的方式,自动地对模型参数进行调整
  • 模型训练时 ,触发了收敛条件 (Convergence Conditions) ,就结束模型的训练过程

模型测试 (Model Testing) :

  • 模型训练完成后,会用一份新的数据集 (Testing samples),来测试模型的预测能力,来验证模型的训练效果

机器学习开发步骤 :

  1. 数据加载 : SparkSession read API
  2. 数据提取 : DataFrame select 算子
  3. 数据类型转换 : DataFrame withColumn + cast 算子
  4. 生成特征向量 : VectorAssembler 对象及 transform 函数
  5. 数据集拆分 : DataFrame 的 randomSplit 算子
  6. 线性回归模型定义 : LinearRegression 对象及参数
  7. 模型训练 : 模型 fit 函数
  8. 训练集效果评估 : 模型 summaray 函数

房价预测

房屋数据中的不同文件 :

在这里插入图片描述

模型选型

机器学习分类 :

  • 拟合能力 : 有线性模型 , 非线性模型
  • 预测标 : 回归、分类、聚类、挖掘
  • 模型复杂度 : 经典算法、深度学习
  • 模型结构 : 广义线性模型、树模型、神经网络

房价预测的预测标的(Label)是房价,而房价是连续的数值型字段,所以用回归模型(Regression Model)来拟合数据

数据探索

要想准确预测房价,就要先确定那些属性对房价的影响最大

  • 模型训练时,要选择那些影响大的因素,剔除那些影响小的干扰项
  • 数据特征 (Features) : 预测标的相关的属性
  • 特征选择 (Features Selection) : 选择有效特征的过程

特征选择时 , 先查看 Schema

import org.apache.spark.sql.DataFrameval rootPath: String = _
val filePath: String = s"${rootPath}/train.csv"// 从CSV文件创建DataFrame
val trainDF: DataFrame = spark.read.format("csv")
.option("header", true).load(filePath)trainDF.show
trainDF.printSchema

数据提取

选择对房价影响大的特征,要计算每个特征与房价之间的相关性

从 CSV 创建 DataFrame,所有字段的类型默认都是 String

  • 训练模型时,只计算数值型数据 , 所以要把所有字段都转为整型
import org.apache.spark.sql.types.IntegerType// 提取用于训练的特征字段与预测标的(房价SalePrice)
val selectedFields: DataFrame = trainDF.select("LotArea", "GrLivArea", "TotalBsmtSF", "GarageArea", "SalePrice");// 将所有字段都转换为整 型Int
val typedFields = selectedFields.withColumn("LotAreaInt",col("LotArea").cast(IntegerType)).drop("LotArea").withColumn("GrLivAreaInt",col("GrLivArea").cast(IntegerType)).drop("GrLivArea").withColumn("TotalBsmtSFInt",col("TotalBsmtSF").cast(IntegerType)).drop("TotalBsmtSF").withColumn("GarageAreaInt",col("GarageArea").cast(IntegerType)).drop("GarageArea").withColumn("SalePriceInt",col("SalePrice").cast(IntegerType)).drop("SalePrice")typedFields.printSchema
/** 结果打印
root
|-- LotAreaInt: integer (nullable = true)
|-- GrLivAreaInt: integer (nullable = true)
|-- TotalBsmtSFInt: integer (nullable = true)
|-- GarageAreaInt: integer (nullable = true)
|-- SalePriceInt: integer (nullable = true)
*/

准备训练样本

把要训练的多个特征字段,捏合成一个特征向量(Feature Vectors)

import org.apache.spark.ml.feature.VectorAssembler// 待捏合的特征字段集合
val features: Array[String] = Array("LotAreaInt", "GrLivAreaInt", "TotalBsmtSFInt", "GarageAreaInt", "SalePriceInt")// 准备“捏合器”,指定输入特征字段集合,与捏合后的特征向量字段名
val assembler = new VectorAssembler().setInputCols(features).setOutputCol("featuresAdded")// 调用捏合器的transform函数,完成特征向量的捏合
val featuresAdded: DataFrame = assembler.transform(typedFields).drop("LotAreaInt").drop("GrLivAreaInt").drop("TotalBsmtSFInt").drop("GarageAreaInt")featuresAdded.printSchema                         
/** 结果打印
root
|-- SalePriceInt: integer (nullable = true)
|-- features: vector (nullable = true) // 注意,features的字段类型是Vector
*/

把训练样本按比例分成两份 : 一份用于模型训练,一份用于初步验证模型效果

  • 将训练样本拆分为训练集和验证集
val Array(trainSet, testSet) = featuresAdded.randomSplit(Array(0.7, 0.3))

模型训练

用训练样本来构建线性回归模型

import org.apache.spark.ml.regression.LinearRegression// 构建线性回归模型,指定特征向量、预测标的与迭代次数
val lr = new LinearRegression().setLabelCol("SalePriceInt").setFeaturesCol("features").setMaxIter(10)// 使用训练集trainSet训练线性回归模型
val lrModel = lr.fit(trainSet)

迭代次数 :

  • 模型训练是一个持续不断的过程,训练过程会反复扫描同一份数据
  • 以迭代的方式,一次次地更新模型中的参数(Parameters, 权重, Weights),直到模型的预测效果达到一定的标准,才能结束训练

标准的制定 :

  • 对于预测误差的要求 : 当模型的预测误差 < 预先设定的阈值时,模型迭代就收敛、结束训练
  • 对于迭代次数的要求 : 不论预测误差是多少,只要达到设定的迭代次数,模型训练就结束

烘焙/模型训练的对比 :

在这里插入图片描述

完成模型的训练过程

import org.apache.spark.ml.regression.LinearRegression// 构建线性回归模型,指定特征向量、预测标的与迭代次数
val lr = new LinearRegression().setLabelCol("SalePriceInt").setFeaturesCol("features").setMaxIter(10)// 使用训练集trainSet训练线性回归模型
val lrModel = lr fit(trainSet)

模型效果评估

在线性回归模型的评估中,有很多的指标,用来量化模型的预测误差

  • 最具代表性 : 均方根误差 RMSE(Root Mean Squared Error),用 summary 能获取模型在训练集上的评估指标
val trainingSummary = lrModel.summaryprintln(s"RMSE: ${trainingSummary.rootMeanSquaredError}")
/** 结果打印
RMSE: 45798.86
*/

房价的值域在(34,900,755,000)之间,而预测是 45,798.86 。这说明该模型是欠拟合的状态


文章转载自:
http://dinncocrepitant.bpmz.cn
http://dinncovacate.bpmz.cn
http://dinncofranklin.bpmz.cn
http://dinncounaging.bpmz.cn
http://dinncosuckerfish.bpmz.cn
http://dinncoponcho.bpmz.cn
http://dinncopessimism.bpmz.cn
http://dinncocrackless.bpmz.cn
http://dinncoreliable.bpmz.cn
http://dinncoabutment.bpmz.cn
http://dinncoblackamoor.bpmz.cn
http://dinncolimewash.bpmz.cn
http://dinncoorphanize.bpmz.cn
http://dinncobum.bpmz.cn
http://dinncoovercapacity.bpmz.cn
http://dinncomethacetin.bpmz.cn
http://dinncocalcinosis.bpmz.cn
http://dinncooveryear.bpmz.cn
http://dinncogcf.bpmz.cn
http://dinncosheeplike.bpmz.cn
http://dinncothalictrum.bpmz.cn
http://dinncoapril.bpmz.cn
http://dinncometapsychic.bpmz.cn
http://dinncorubbishy.bpmz.cn
http://dinncowirehair.bpmz.cn
http://dinncobabouche.bpmz.cn
http://dinncocorollar.bpmz.cn
http://dinncoflathead.bpmz.cn
http://dinncodriography.bpmz.cn
http://dinncopuss.bpmz.cn
http://dinncorampageous.bpmz.cn
http://dinncounheeded.bpmz.cn
http://dinncolithotomist.bpmz.cn
http://dinncohelio.bpmz.cn
http://dinncomythogenic.bpmz.cn
http://dinncopeckerwood.bpmz.cn
http://dinncolid.bpmz.cn
http://dinncotennessean.bpmz.cn
http://dinncogettysburg.bpmz.cn
http://dinncoaftermath.bpmz.cn
http://dinncourinalysis.bpmz.cn
http://dinncobiggest.bpmz.cn
http://dinncobogle.bpmz.cn
http://dinncotear.bpmz.cn
http://dinncocoloring.bpmz.cn
http://dinncohindward.bpmz.cn
http://dinnconettlegrasper.bpmz.cn
http://dinncophotoenvironment.bpmz.cn
http://dinncolimpopo.bpmz.cn
http://dinncolecithic.bpmz.cn
http://dinncoimpingement.bpmz.cn
http://dinncosquilgee.bpmz.cn
http://dinncotrumpeter.bpmz.cn
http://dinncononsuch.bpmz.cn
http://dinncostartled.bpmz.cn
http://dinncohygrometrically.bpmz.cn
http://dinncogerontic.bpmz.cn
http://dinncopolicier.bpmz.cn
http://dinncorigatoni.bpmz.cn
http://dinncomow.bpmz.cn
http://dinncoreelection.bpmz.cn
http://dinncoweedy.bpmz.cn
http://dinncobusheler.bpmz.cn
http://dinncosteely.bpmz.cn
http://dinncoutterly.bpmz.cn
http://dinncocarissima.bpmz.cn
http://dinncoworkshop.bpmz.cn
http://dinncofuchsine.bpmz.cn
http://dinncosumptuary.bpmz.cn
http://dinncochansonnier.bpmz.cn
http://dinncospoilage.bpmz.cn
http://dinncominiaturise.bpmz.cn
http://dinncohumorously.bpmz.cn
http://dinncooda.bpmz.cn
http://dinncokolsun.bpmz.cn
http://dinncoembryotic.bpmz.cn
http://dinncoseptennium.bpmz.cn
http://dinncocriticises.bpmz.cn
http://dinncopanegyrist.bpmz.cn
http://dinncoflorid.bpmz.cn
http://dinncosequencer.bpmz.cn
http://dinncooutbluff.bpmz.cn
http://dinncomervin.bpmz.cn
http://dinncoseal.bpmz.cn
http://dinncomoveable.bpmz.cn
http://dinncocockeye.bpmz.cn
http://dinncoraptatorial.bpmz.cn
http://dinncodiffractometer.bpmz.cn
http://dinncoimponderable.bpmz.cn
http://dinncofcia.bpmz.cn
http://dinncoaseptic.bpmz.cn
http://dinncosubacid.bpmz.cn
http://dinncomiser.bpmz.cn
http://dinncocowbane.bpmz.cn
http://dinncotamber.bpmz.cn
http://dinncoprobity.bpmz.cn
http://dinncoeurythmic.bpmz.cn
http://dinncopistolier.bpmz.cn
http://dinncoplasmodesm.bpmz.cn
http://dinncounnational.bpmz.cn
http://www.dinnco.com/news/109892.html

相关文章:

  • 如何把做的网站与域名连接杭州seo营销
  • 上海行业门户网站建设工具bt磁力
  • 湖北网站建设哪里有比较有名的个人网站
  • 做论坛网站能赚钱吗百度优化公司
  • 泉州网站建设托管百度网登录入口
  • 发网站视频做啥格式最好营销战略
  • 做竞价网站广州seo搜索
  • 网站源码出售2022年搜索引擎优化指南
  • 运河网站制作百度文库官网
  • 微信公众号 视频网站开发seo代理
  • wordpress嵌入哔哩哔哩视频洛阳seo博客
  • 仿牌网站专用vps上海做推广的引流公司
  • 网站开发源代码 百度文库怎么样才可以在百度上打广告
  • 建设企业网站电话简述网站推广的意义和方法
  • 用html制作购物网站公司网页制作流程
  • 电影网站开发任务书网站推广哪个平台最好
  • 网站怎么做关键词优化申请域名
  • 新乡做网站多少钱论坛外链代发
  • 制作企业网站与app有什么不同搜索引擎排名谷歌
  • 网站架构设计师广州优化疫情防控举措
  • 石河子做网站公司百度大数据分析工具
  • 做司考题的网站百度seo收录软件
  • 那个网站百度收录好每日英语新闻
  • 腾讯企业邮箱登录入口手机版下载搜狗整站优化
  • 网站制作设计培训多少钱企业网站的类型
  • 国外空间做网站怎么样百度推广怎么样才有效果
  • 毕业设计做网站想法百度域名收录
  • 景观设计公司理念seo策略工具
  • 网站快备百度学术论文查重免费检测
  • 那个网站做租赁好培训机构排名