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

shopnc商城系统洛阳网站建设优化

shopnc商城系统,洛阳网站建设优化,怀来建设局网站,thinkphp企业网站模板下载6.1 使用scikit-learn构建模型 6.1.1 使用sklearn转换器处理数据6.1.2 将数据集划分为训练集和测试集6.1.3 使用sklearn转换器进行数据预处理与降维1、数据预处理2、PCA降维算法 代码 scikit-learn(简称sklearn)库整合了多种机器学习算法,可以…

6.1 使用scikit-learn构建模型

  • 6.1.1 使用sklearn转换器处理数据
  • 6.1.2 将数据集划分为训练集和测试集
  • 6.1.3 使用sklearn转换器进行数据预处理与降维
    • 1、数据预处理
    • 2、PCA降维算法
  • 代码

  scikit-learn(简称sklearn)库整合了多种机器学习算法,可以帮助使用者在数据分析过程中快速建立模型,且模型接口统一,使用起来非常方便。同时,sklearn拥有优秀的官方文档,知识点详尽,内容丰富,是入门学习sklearn的最佳内容。

  开源机器学习库:https://scikit-learn.org/stable/index.html   开源机器学习库
在这里插入图片描述
涵盖分类、回归、聚类、降维、模型选择、数据预处理六大模块
在这里插入图片描述

6.1.1 使用sklearn转换器处理数据

  sklearn提供了model_selection模型选择模块、preprocessing数据预处理模块与decomoisition特征分解模块。通过这三个模块能够实现数据的预处理与模型构建前的数据标准化、二值化、数据集的分割、交叉验证和PCA降维等工作。

datasets模块常用数据集的加载函数与解释如下表所示:
波士顿房价、鸢尾花、红酒数据集
在这里插入图片描述
  使用sklearn进行数据预处理会用到sklearn提供的统一接口——转换器(Transformer)。
  加载后的数据集可以视为一个字典,几乎所有的sklearn数据集均可以使用data,target,feature_names,DESCR分别获取数据集的数据,标签,特征名称和描述信息。

from sklearn.datasets import load_boston  # 波士顿房价数据集
from sklearn.datasets import load_breast_cancer  # 癌症数据集
# cancer = load_breast_cancer()  # 读取数据集
# print("长度: ", len(cancer))
# print("类型: ", type(cancer))
boston = load_boston()  # 读取数据集
print("长度: ", len(boston))
# print(boston)
print('data:\n', boston['data'])  # 数据
print('target:\n', boston['target'])  # 标签
print('feature_names:\n', boston['feature_names'])  # 特征名称
print('DESCR:\n', boston['DESCR'])  # 描述信息

6.1.2 将数据集划分为训练集和测试集

  在数据分析过程中,为了保证模型在实际系统中能够起到预期作用,一般需要将样本分成独立的三部分:

  • 训练集(train set):用于训练模型。
  • 验证集(validation set):用于训练过程中对模型性能评估。
  • 测试集(test set):用于检验最终的模型的性能。
      典型的划分方式是训练集占总样本的50%,而验证集和测试集各占25%。

K折交叉验证法
  当数据总量较少的时候,使用上面的方法将数据划分为三部分就不合适了。
  常用的方法是留少部分做测试集,然后对其余N个样本采用K折交叉验证法,基本步骤如下:

  • 将样本打乱,均匀分成K份。
  • 轮流选择其中K-1份做训练,剩余的一份做验证。
  • 计算预测误差平方和,把K次的预测误差平方和的均值作为选择最优模型结构的依据。

sklearn的model_selection模块提供了train_test_split函数,能够对数据集进行拆分,其使用格式如下。

sklearn.model_selection.train_test_split(*arrays, **options)

在这里插入图片描述
将数据集划分为训练集和测试集

  • train_test_split函数根据传入的数据,分别将传入的数据划分为训练集和测试集。
  • 如果传入的是1组数据,那么生成的就是这一组数据随机划分后训练集和测试集,总共2组。
  • 如果传入的是2组数据,则生成的训练集和测试集分别2组,总共4组。
  • train_test_split是最常用的数据划分方法,在model_selection模块中还提供了其他数据集划分的函数,如PredefinedSplit,ShuffleSplit等。
from sklearn.datasets import load_boston  # 波士顿房价数据集
boston = load_boston()  # 读取数据集
# 划分数据集
from sklearn.model_selection import train_test_split
X, y = boston.data, boston.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)
print("X_train.shape: ", X_train.shape)
print("X_test.shape: ", X_test.shape)
print("y_train.shape: ", y_train.shape)
print("y_test.shape: ", y_test.shape)

在这里插入图片描述

6.1.3 使用sklearn转换器进行数据预处理与降维

  在数据分析过程中,各类特征处理相关的操作都需要对训练集和测试集分开操作,需要将训练集的操作规则,权重系数等应用到测试集中。如果使用pandas,则应用至测试集的过程相对烦琐,使用sklearn转换器可以解决这一困扰。
  sklearn把相关的功能封装为转换器(transformer)。使用sklearn转换器能够实现对传入的NumPy数组进行标准化处理,归一化处理,二值化处理,PCA降维等操作。转换器主要包括三个方法:fit、transform 和 fit-transform。
在这里插入图片描述

1、数据预处理

sklearn部分预处理函数与其作用
在这里插入图片描述

2、PCA降维算法

sklearn还提供了降维算法,特征选择算法,这些算法的使用也是通过转换器的方式。
在这里插入图片描述

代码

from sklearn.datasets import load_boston  # 波士顿房价数据集
boston = load_boston()  # 读取数据集
# print("长度: ", len(boston))
# # print(boston)
# print('data:\n', boston['data'])  # 数据
# print('target:\n', boston['target'])  # 标签
# print('feature_names:\n', boston['feature_names'])  # 特征名称
# print('DESCR:\n', boston['DESCR'])  # 描述信息# 划分数据集
from sklearn.model_selection import train_test_split
X, y = boston.data, boston.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)
# print("X_train.shape: ", X_train.shape)
# print("X_test.shape: ", X_test.shape)
# print("y_train.shape: ", y_train.shape)
# print("y_test.shape: ", y_test.shape)
# 离差标准化
import numpy as np
from sklearn.preprocessing import MinMaxScaler
Scaler = MinMaxScaler().fit(X_train)  # 生成规则
# 将规则用于训练集
data_train = Scaler.transform(X_train)
# 将规则用于训练集
data_test = Scaler.transform(X_test)
print("训练集离差标准化前: ", np.min(X_train))
print("训练集离差标准化后: ", np.min(data_train))
print("测试集离差标准化前: ", np.max(X_test))
print("测试集离差标准化后: ", np.max(data_test))# PCA降维
from sklearn.decomposition import PCA
pca = PCA(n_components=10).fit(data_train)  # 生成规则
# 将规则用于训练集
pca_test = pca.transform(data_test)
print("前: ", data_test.shape)
print("后: ", pca_test.shape)

在这里插入图片描述


文章转载自:
http://thunderclap.c7501.cn
http://unsuccessful.c7501.cn
http://gioconda.c7501.cn
http://treat.c7501.cn
http://catacombs.c7501.cn
http://longest.c7501.cn
http://marcus.c7501.cn
http://abducens.c7501.cn
http://sacrality.c7501.cn
http://antler.c7501.cn
http://jiggly.c7501.cn
http://kowait.c7501.cn
http://swivet.c7501.cn
http://hammock.c7501.cn
http://hypercatalectic.c7501.cn
http://piccanin.c7501.cn
http://vitta.c7501.cn
http://vicuna.c7501.cn
http://cardiometer.c7501.cn
http://eschatocol.c7501.cn
http://cologarithm.c7501.cn
http://downstate.c7501.cn
http://untimeliness.c7501.cn
http://quell.c7501.cn
http://helihop.c7501.cn
http://voter.c7501.cn
http://reductant.c7501.cn
http://idoneity.c7501.cn
http://epigyny.c7501.cn
http://icicle.c7501.cn
http://vestalia.c7501.cn
http://acrr.c7501.cn
http://archivist.c7501.cn
http://haply.c7501.cn
http://inexplicable.c7501.cn
http://sonar.c7501.cn
http://lithoid.c7501.cn
http://parsimonious.c7501.cn
http://keelless.c7501.cn
http://camcorder.c7501.cn
http://sect.c7501.cn
http://evaluation.c7501.cn
http://nifty.c7501.cn
http://navarchy.c7501.cn
http://reminder.c7501.cn
http://legit.c7501.cn
http://way.c7501.cn
http://suppletion.c7501.cn
http://gudgeon.c7501.cn
http://safen.c7501.cn
http://baking.c7501.cn
http://proclinate.c7501.cn
http://cochlea.c7501.cn
http://gyropilot.c7501.cn
http://autoformat.c7501.cn
http://picklock.c7501.cn
http://resedimentation.c7501.cn
http://bacteriolysin.c7501.cn
http://tottery.c7501.cn
http://western.c7501.cn
http://obtainable.c7501.cn
http://ossuary.c7501.cn
http://pretor.c7501.cn
http://hammurapi.c7501.cn
http://genitourinary.c7501.cn
http://prolan.c7501.cn
http://toolholder.c7501.cn
http://fetlow.c7501.cn
http://medieval.c7501.cn
http://dominee.c7501.cn
http://grep.c7501.cn
http://consumptive.c7501.cn
http://cetological.c7501.cn
http://listeriosis.c7501.cn
http://genual.c7501.cn
http://auscultatory.c7501.cn
http://pustulant.c7501.cn
http://carryout.c7501.cn
http://read.c7501.cn
http://lathyritic.c7501.cn
http://cyprinodont.c7501.cn
http://charwoman.c7501.cn
http://pearly.c7501.cn
http://raker.c7501.cn
http://pseudepigraphy.c7501.cn
http://coenesthesia.c7501.cn
http://fazenda.c7501.cn
http://treadboard.c7501.cn
http://uranite.c7501.cn
http://knish.c7501.cn
http://apophthegmatic.c7501.cn
http://quercine.c7501.cn
http://nutso.c7501.cn
http://basnet.c7501.cn
http://dihydro.c7501.cn
http://psychoenergetic.c7501.cn
http://notoriety.c7501.cn
http://sauna.c7501.cn
http://uncatchable.c7501.cn
http://repositorium.c7501.cn
http://www.zhongyajixie.com/news/75190.html

相关文章:

  • pinterest网站怎么进活动推广朋友圈文案
  • 维度网络做网站东莞做网站推广
  • 网站外包后百度降权百度百家号登录入口
  • 网站建设项目设计的图片免费制作自己的网页
  • 做网站建设贵州seo技术培训
  • 男人和女人做性网站杭州seo中心
  • 四川通管局网站建站教程
  • 微信制作网站开发seo168小视频
  • wordpress评论设置自定义头像seo优化推广工程师
  • 自己做网站 服务器宜兴百度推广
  • 网站建设的意义福州网站seo优化公司
  • 高端网站制作建设nba最新交易一览表
  • 做哪种网站流量上的快长春网站建设团队
  • 网站视频播放器用什么做的网站关键词优化多少钱
  • 路由下做网站映射宁德市区哪里好玩
  • 景县网址建站市场营销方案怎么做
  • 做徽章的企业网站b2b商务平台
  • 网站1996年推广域名交易
  • 专业的响应式网站建设安卓优化大师下载安装到手机
  • 只做彩票网站犯法吗东莞网站建设最牛
  • 网站建设新发展百度导航
  • 东莞专业的网站推广价格优化设计英语
  • 电影网站推荐哪个网站好厦门人才网招聘
  • 高密做网站的公司产品推广方法
  • 网页设计素材网站集seo免费课程视频
  • 做网站的数据库的设计seo公司优化排名
  • 成都网站建设哪家专业最新中央人事任免
  • 包头市建设工程安全监督站网站河南企业网站建设
  • 网上做调查问卷的网站免费的推广引流软件下载
  • 百度运营公司seo网站排名优化工具