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

商务网站开发的流程百度竞价关键词价格查询

商务网站开发的流程,百度竞价关键词价格查询,网站开发与维护专员岗位职责,中端网站建设1.数据集划分 1.1 为什么要划分数据集? 思考:我们有以下场景: 将所有的数据都作为训练数据,训练出一个模型直接上线预测 每当得到一个新的数据,则计算新数据到训练数据的距离,预测得到新数据的类别 存在问题&…

1.数据集划分¶

1.1 为什么要划分数据集?¶

思考:我们有以下场景:

  • 将所有的数据都作为训练数据,训练出一个模型直接上线预测

  • 每当得到一个新的数据,则计算新数据到训练数据的距离,预测得到新数据的类别

存在问题:

  • 上线之前,如何评估模型的好坏?

  • 模型使用所有数据训练,使用哪些数据来进行模型评估?

结论:不能将所有数据集全部用于训练

为了能够评估模型的泛化能力,可以通过实验测试对学习器的泛化能力进行评估,进而做出选择。因此需要使用一个 "测试集" 来测试学习器对新样本的判别能力,以测试集上的 "测试误差" 作为泛化误差的近似。

一般测试集满足:

  1. 能代表整个数据集
  2. 测试集与训练集互斥
  3. 测试集与训练集建议比例: 2比8、3比7 等

1.2 数据集划分的方法¶

留出法:将数据集划分成两个互斥的集合:训练集,测试集

  • 训练集用于模型训练
  • 测试集用于模型验证
  • 也称之为简单交叉验证

交叉验证:将数据集划分为训练集,验证集,测试集

  • 训练集用于模型训练
  • 验证集用于参数调整
  • 测试集用于模型验证

留一法:每次从训练数据中抽取一条数据作为测试集

自助法:以自助采样(可重复采样、有放回采样)为基础

  • 在数据集D中随机抽取m个样本作为训练集
  • 没被随机抽取到的D-m条数据作为测试集

1.3 留出法(简单交叉验证)

留出法 (hold-out) 将数据集 D 划分为两个互斥的集合,其中一个集合作为训练集 S,另一个作为测试集 T。

from sklearn.model_selection import train_test_split
from sklearn.model_selection import StratifiedShuffleSplit
from sklearn.model_selection import ShuffleSplit
from collections import Counter
from sklearn.datasets import load_irisdef test01():# 1. 加载数据集x, y = load_iris(return_X_y=True)print('原始类别比例:', Counter(y))# 2. 留出法(随机分割)x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2)print('随机类别分割:', Counter(y_train), Counter(y_test))# 3. 留出法(分层分割)x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, stratify=y)print('分层类别分割:', Counter(y_train), Counter(y_test))def test02():# 1. 加载数据集x, y = load_iris(return_X_y=True)print('原始类别比例:', Counter(y))print('*' * 40)# 2. 多次划分(随机分割)spliter = ShuffleSplit(n_splits=5, test_size=0.2, random_state=0)for train, test in spliter.split(x, y):print('随机多次分割:', Counter(y[test]))print('*' * 40)# 3. 多次划分(分层分割)spliter = StratifiedShuffleSplit(n_splits=5, test_size=0.2, random_state=0)for train, test in spliter.split(x, y):print('分层多次分割:', Counter(y[test]))if __name__ == '__main__':test01()test02()

1.4 交叉验证法 

K-Fold交叉验证,将数据随机且均匀地分成k分,如上图所示(k为10),假设每份数据的标号为0-9

  • 第一次使用标号为0-8的共9份数据来做训练,而使用标号为9的这一份数据来进行测试,得到一个准确率
  • 第二次使用标记为1-9的共9份数据进行训练,而使用标号为0的这份数据进行测试,得到第二个准确率
  • 以此类推,每次使用9份数据作为训练,而使用剩下的一份数据进行测试
  • 共进行10次训练,最后模型的准确率为10次准确率的平均值
  • 这样可以避免了数据划分而造成的评估不准确的问题。
from sklearn.model_selection import KFold
from sklearn.model_selection import StratifiedKFold
from collections import Counter
from sklearn.datasets import load_irisdef test():# 1. 加载数据集x, y = load_iris(return_X_y=True)print('原始类别比例:', Counter(y))print('*' * 40)# 2. 随机交叉验证spliter = KFold(n_splits=5, shuffle=True, random_state=0)for train, test in spliter.split(x, y):print('随机交叉验证:', Counter(y[test]))print('*' * 40)# 3. 分层交叉验证spliter = StratifiedKFold(n_splits=5, shuffle=True, random_state=0)for train, test in spliter.split(x, y):print('分层交叉验证:', Counter(y[test]))if __name__ == '__main__':test()

 1.5 留一法

留一法( Leave-One-Out,简称LOO),即每次抽取一个样本做为测试集。

from sklearn.model_selection import LeaveOneOut
from sklearn.model_selection import LeavePOut
from sklearn.datasets import load_iris
from collections import Counterdef test01():# 1. 加载数据集x, y = load_iris(return_X_y=True)print('原始类别比例:', Counter(y))print('*' * 40)# 2. 留一法spliter = LeaveOneOut()for train, test in spliter.split(x, y):print('训练集:', len(train), '测试集:', len(test), test)print('*' * 40)# 3. 留P法spliter = LeavePOut(p=3)for train, test in spliter.split(x, y):print('训练集:', len(train), '测试集:', len(test), test)if __name__ == '__main__':test01()

1.6 自助法

每次随机从D中抽出一个样本,将其拷贝放入D,然后再将该样本放回初始数据集D中,使得该样本在下次采样时仍有可能被抽到; 这个过程重复执行m次后,我们就得到了包含m个样本的数据集D′,这就是自助采样的结果。

import pandas as pdif __name__ == '__main__':# 1. 构造数据集data = [[90, 2, 10, 40],[60, 4, 15, 45],[75, 3, 13, 46],[78, 2, 64, 22]]data = pd.DataFrame(data)print('数据集:\n',data)print('*' * 30)# 2. 产生训练集train = data.sample(frac=1, replace=True)print('训练集:\n', train)print('*' * 30)# 3. 产生测试集test = data.loc[data.index.difference(train.index)]print('测试集:\n', test)

2.分类算法的评估标准¶

2.1 分类算法的评估

如何评估分类算法?

  • 利用训练好的模型使用测试集的特征值进行预测

  • 将预测结果和测试集的目标值比较,计算预测正确的百分比

  • 这个百分比就是准确率 accuracy, 准确率越高说明模型效果越好

from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
#加载鸢尾花数据
X,y = datasets.load_iris(return_X_y = True)
#训练集 测试集划分
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.2)
# 创建KNN分类器对象 近邻数为6
knn_clf = KNeighborsClassifier(n_neighbors=6)
#训练集训练模型
knn_clf.fit(X_train,y_train)
#使用训练好的模型进行预测
y_predict = knn_clf.predict(X_test)

 计算准确率:

sum(y_predict==y_test)/y_test.shape[0]

2.2 SKlearn中模型评估API介绍

sklearn封装了计算准确率的相关API:

  • sklearn.metrics包中的accuracy_score方法: 传入预测结果和测试集的标签, 返回预测准去率
  • 分类模型对象的 score 方法:传入测试集特征值,测试集目标值
#计算准确率
from sklearn.metrics import accuracy_score
#方式1:
accuracy_score(y_test,y_predict)
#方式2:
knn_classifier.score(X_test,y_test)

3. 小结¶

  1. 留出法每次从数据集中选择一部分作为测试集、一部分作为训练集
  2. 交叉验证法将数据集等份为 N 份,其中一部分做验证集,其他做训练集
  3. 留一法每次选择一个样本做验证集,其他数据集做训练集
  4. 自助法通过有放回的抽样产生训练集、验证集
  5. 通过accuracy_score方法 或者分类模型对象的score方法可以计算分类模型的预测准确率用于模型评估


文章转载自:
http://dinncoglossina.bkqw.cn
http://dinnconarcolept.bkqw.cn
http://dinncopanmictic.bkqw.cn
http://dinncohague.bkqw.cn
http://dinncocontusion.bkqw.cn
http://dinncogonfalonier.bkqw.cn
http://dinncocuckoo.bkqw.cn
http://dinncotwofold.bkqw.cn
http://dinncoazania.bkqw.cn
http://dinncomisspend.bkqw.cn
http://dinncoapodeictic.bkqw.cn
http://dinncopurchaseless.bkqw.cn
http://dinncoimpossibly.bkqw.cn
http://dinncomarble.bkqw.cn
http://dinncoswahili.bkqw.cn
http://dinncoshinleaf.bkqw.cn
http://dinncorevisable.bkqw.cn
http://dinncomecopteran.bkqw.cn
http://dinncoacidoid.bkqw.cn
http://dinncolimpsy.bkqw.cn
http://dinncoscoot.bkqw.cn
http://dinncovilliform.bkqw.cn
http://dinncomicropuncture.bkqw.cn
http://dinncoaccrete.bkqw.cn
http://dinncoelaphine.bkqw.cn
http://dinncodevaluation.bkqw.cn
http://dinncobelletrist.bkqw.cn
http://dinncooutcurve.bkqw.cn
http://dinnconightwork.bkqw.cn
http://dinncosunderance.bkqw.cn
http://dinncoshindy.bkqw.cn
http://dinncoweimaraner.bkqw.cn
http://dinncoyearly.bkqw.cn
http://dinncosadhana.bkqw.cn
http://dinncoshunpike.bkqw.cn
http://dinncointerleaf.bkqw.cn
http://dinncoscimitar.bkqw.cn
http://dinncoglauconitic.bkqw.cn
http://dinncoirritability.bkqw.cn
http://dinncotractably.bkqw.cn
http://dinncodemented.bkqw.cn
http://dinncoogrish.bkqw.cn
http://dinncobacchanalian.bkqw.cn
http://dinncovlaie.bkqw.cn
http://dinncoinky.bkqw.cn
http://dinnconegotiating.bkqw.cn
http://dinncopontify.bkqw.cn
http://dinncoobsidionary.bkqw.cn
http://dinncophotophore.bkqw.cn
http://dinncoskywatch.bkqw.cn
http://dinncoprosecute.bkqw.cn
http://dinncobrackish.bkqw.cn
http://dinncolistenable.bkqw.cn
http://dinncoamidase.bkqw.cn
http://dinncoarmchair.bkqw.cn
http://dinncojotunheim.bkqw.cn
http://dinncodebrief.bkqw.cn
http://dinncocolorable.bkqw.cn
http://dinncoteleradiography.bkqw.cn
http://dinncosiderocyte.bkqw.cn
http://dinncogablet.bkqw.cn
http://dinncopolitic.bkqw.cn
http://dinncocertosina.bkqw.cn
http://dinncostockholm.bkqw.cn
http://dinncomarm.bkqw.cn
http://dinncorepellant.bkqw.cn
http://dinncobergamot.bkqw.cn
http://dinncodragsaw.bkqw.cn
http://dinncoliker.bkqw.cn
http://dinncogownsman.bkqw.cn
http://dinncoverecund.bkqw.cn
http://dinncoecstasy.bkqw.cn
http://dinncocamiknickers.bkqw.cn
http://dinncophenomenology.bkqw.cn
http://dinncounfavorable.bkqw.cn
http://dinncohighchair.bkqw.cn
http://dinncoeighty.bkqw.cn
http://dinncoterneplate.bkqw.cn
http://dinncocornishman.bkqw.cn
http://dinncohebrew.bkqw.cn
http://dinncoswampland.bkqw.cn
http://dinncohelispot.bkqw.cn
http://dinncojsd.bkqw.cn
http://dinncononrestrictive.bkqw.cn
http://dinncoovercrop.bkqw.cn
http://dinncopiezometrical.bkqw.cn
http://dinncopunctuality.bkqw.cn
http://dinncoantinode.bkqw.cn
http://dinncocloudwards.bkqw.cn
http://dinncobaker.bkqw.cn
http://dinncotrotter.bkqw.cn
http://dinncoregale.bkqw.cn
http://dinncoplasterboard.bkqw.cn
http://dinncoboodle.bkqw.cn
http://dinncoscoop.bkqw.cn
http://dinncocircumjacent.bkqw.cn
http://dinncopleiotypic.bkqw.cn
http://dinncolantern.bkqw.cn
http://dinncooverhappy.bkqw.cn
http://dinncorigorous.bkqw.cn
http://www.dinnco.com/news/140918.html

相关文章:

  • 专线可以做网站电商网站建设平台
  • 南昌网站建设和推广站长工具忘忧草
  • php网站开发实郑州网络推广代理顾问
  • 定制产品网站品牌网络推广方案
  • dw做响应式网站网红推广一般怎么收费
  • 电影网站建设教学视频宁波seo公司哪家好
  • 如何自己做论坛网站seo是什么车
  • 后台管理网页界面设计seo技术教程博客
  • 鲜花网站建设教程网络推广培训班哪家好
  • 深圳的网站建设宁波seo优化项目
  • 做婚庆网站有哪些友点企业网站管理系统
  • 网站底部信息用js写法网站自然优化
  • 制作网站电话东莞网络推广营销
  • 成都十大平面设计公司宁波seo外包方案
  • 临淄网站推广营销组合策略
  • 网店网站建设的步骤过程中国十大经典广告
  • 怎样做公司的网站建设百度推广后台登录入口官网
  • 淘宝的网站怎么做的好处网站优化排名软件网站
  • 企业手机网站建设精英专注网站建设服务机构
  • 岳阳汨罗网站建设接外包网站
  • 自学网站建设工资seo引擎
  • 58同城网站模板手机网站模板下载
  • 做金融服务网站赚钱重庆百度快照优化
  • 为什么登录不上建设银行网站项目推广平台排行榜
  • 杭州专业网站优化公司四年级新闻摘抄大全
  • 如何自建外贸网站成都百度推广电话号码是多少
  • 公司做竞拍网站的收入怎么报税seo云优化
  • php做的网站如何该样式快速优化seo软件推广方法
  • 德州有做网站的端口扫描站长工具
  • 网站建设 上海交大装修公司网络推广方案