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

mac服务器 做网站广告资源网

mac服务器 做网站,广告资源网,网店代理靠谱吗,武侯区建设局网站Scikit-Learn决策树 1、决策树分类2、Scikit-Learn决策树分类2.1、Scikit-Learn决策树API2.2、Scikit-Learn决策树初体验2.3、Scikit-Learn决策树实践(葡萄酒分类) 1、决策树分类 2、Scikit-Learn决策树分类 2.1、Scikit-Learn决策树API 官方文档&#…

Scikit-Learn决策树

    • 1、决策树分类
    • 2、Scikit-Learn决策树分类
      • 2.1、Scikit-Learn决策树API
      • 2.2、Scikit-Learn决策树初体验
      • 2.3、Scikit-Learn决策树实践(葡萄酒分类)



1、决策树分类


2、Scikit-Learn决策树分类

2.1、Scikit-Learn决策树API


官方文档:https://scikit-learn.org/stable/modules/generated/sklearn.tree.DecisionTreeClassifier.html#sklearn.tree.DecisionTreeClassifier

中文官方文档:https://scikit-learn.org.cn/view/784.html

2.2、Scikit-Learn决策树初体验


下面我们使用Scikit-Learn提供的API制作两个交错的半圆形状数据集来演示Scikit-Learn决策树

1)制作数据集

import numpy as np
import matplotlib.pyplot as plt
from sklearn import datasets# 生成两个交错的半圆形状数据集
X, y = datasets.make_moons(noise=0.25, random_state=666)
plt.scatter(X[y == 0, 0], X[y == 0, 1])
plt.scatter(X[y == 1, 0], X[y == 1, 1])
plt.show()

在这里插入图片描述

2)训练决策树分类模型

from sklearn.tree import DecisionTreeClassifier      # 决策树分类器# 使用CART分类树的默认参数
dt_clf = DecisionTreeClassifier()
# dt_clf = DecisionTreeClassifier(max_depth=2, max_leaf_nodes=4)
# 训练拟合
dt_clf.fit(X, y)

3)绘制决策边界

# 绘制决策边界
decision_boundary_fill(dt_clf, axis=[-1.5, 2.5, -1.0, 1.5])
plt.scatter(X[y == 0, 0], X[y == 0, 1])
plt.scatter(X[y == 1, 0], X[y == 1, 1])
plt.show()

其中,使用到的绘制函数详见文章:传送门

当使用CART分类树的默认参数时,其决策边界如图所示:

在这里插入图片描述
由图可见,在不加限制的情况下,一棵决策树会生长到所有的叶子都是纯净的或者或者没有更多的特征可用为止。这样的决策树往往会过拟合,也就是说,它在训练集上表现的很好,而在测试集上却表现的很糟糕

当我们限制决策树的最大深度max_depth=2,并且最大叶子节点数max_leaf_nodes=4时,其决策边界如下图所示:

在这里插入图片描述
通过限制一些参数,对决策树进行剪枝,可以让我们的决策树具有更好的泛化性

2.3、Scikit-Learn决策树实践(葡萄酒分类)


2.3.1、葡萄酒数据集

葡萄酒(Wine)数据集是来自加州大学欧文分校(UCI)的公开数据集,这些数据是对意大利同一地区种植的葡萄酒进行化学分析的结果。数据集共178个样本,包括三个不同品种,每个品种的葡萄酒中含有13种成分(特征)、一个类别标签,分别使是0/1/2来代表葡萄酒的三个分类

数据集的属性信息(13特征+1标签)如下:

from sklearn.datasets import load_winewine = load_wine()
data = pd.DataFrame(data=wine.data, columns=wine.feature_names)
data['class'] = wine.target
print(data.head().to_string())
'''alcohol  malic_acid   ash  alcalinity_of_ash  magnesium  total_phenols  flavanoids  nonflavanoid_phenols  proanthocyanins  color_intensity   hue  od280/od315_of_diluted_wines  proline  class
0    14.23        1.71  2.43               15.6      127.0           2.80        3.06                  0.28             2.29             5.64  1.04                          3.92   1065.0      0
1    13.20        1.78  2.14               11.2      100.0           2.65        2.76                  0.26             1.28             4.38  1.05                          3.40   1050.0      0
2    13.16        2.36  2.67               18.6      101.0           2.80        3.24                  0.30             2.81             5.68  1.03                          3.17   1185.0      0
3    14.37        1.95  2.50               16.8      113.0           3.85        3.49                  0.24             2.18             7.80  0.86                          3.45   1480.0      0
4    13.24        2.59  2.87               21.0      118.0           2.80        2.69                  0.39             1.82             4.32  1.04                          2.93    735.0      0
'''
属性/标签说明
alcohol酒精含量(百分比)
malic_acid苹果酸含量(克/升)
ash灰分含量(克/升)
alcalinity_of_ash灰分碱度(mEq/L)
magnesium镁含量(毫克/升)
total_phenols总酚含量(毫克/升)
flavanoids类黄酮含量(毫克/升)
nonflavanoid_phenols非黄酮酚含量(毫克/升)
proanthocyanins原花青素含量(毫克/升)
color_intensity颜色强度(单位absorbance)
hue色调(在1至10之间的一个数字)
od280/od315_of_diluted_wines稀释葡萄酒样品的光密度比值,用于测量葡萄酒中各种化合物的浓度
proline脯氨酸含量(毫克/升)
class分类标签(class_0(59)、class_1(71)、class_2(48))

数据集的概要信息如下:

# 数据集大小
print(wine.data.shape)      # (178, 13)
# 标签名称
print(wine.target_names)    # ['class_0' 'class_1' 'class_2']
# 分类标签
print(data.groupby('class')['class'].count())
'''
class
0    59
1    71
2    48
Name: class, dtype: int64
'''

数据集的缺失值情况:

# 缺失值:无缺失值
print(data.isnull().sum())

在这里插入图片描述
2.3.2、决策树实践(葡萄酒分类)


未完待续…


文章转载自:
http://cryptanalyze.rzgp.cn
http://jokey.rzgp.cn
http://allegory.rzgp.cn
http://hightail.rzgp.cn
http://dictyostele.rzgp.cn
http://duskiness.rzgp.cn
http://irides.rzgp.cn
http://gertrude.rzgp.cn
http://neurodepressive.rzgp.cn
http://tenia.rzgp.cn
http://espieglerie.rzgp.cn
http://sonata.rzgp.cn
http://coeducational.rzgp.cn
http://hepaticotomy.rzgp.cn
http://indetectable.rzgp.cn
http://expenses.rzgp.cn
http://directtissima.rzgp.cn
http://extractible.rzgp.cn
http://hypoxia.rzgp.cn
http://hamburg.rzgp.cn
http://blindfold.rzgp.cn
http://phonetist.rzgp.cn
http://hypodermis.rzgp.cn
http://onthe.rzgp.cn
http://colloid.rzgp.cn
http://routinism.rzgp.cn
http://congruent.rzgp.cn
http://interdepartmental.rzgp.cn
http://arctic.rzgp.cn
http://aetiological.rzgp.cn
http://allot.rzgp.cn
http://millimicron.rzgp.cn
http://distractible.rzgp.cn
http://saxophonist.rzgp.cn
http://quartzitic.rzgp.cn
http://soberano.rzgp.cn
http://honiara.rzgp.cn
http://divisive.rzgp.cn
http://socialistic.rzgp.cn
http://dural.rzgp.cn
http://mistaken.rzgp.cn
http://glyconic.rzgp.cn
http://wreckful.rzgp.cn
http://majoritarian.rzgp.cn
http://raggy.rzgp.cn
http://race.rzgp.cn
http://unsocialized.rzgp.cn
http://uraemic.rzgp.cn
http://emitter.rzgp.cn
http://goldfield.rzgp.cn
http://ejectment.rzgp.cn
http://sultanate.rzgp.cn
http://bullish.rzgp.cn
http://unmeddled.rzgp.cn
http://reusage.rzgp.cn
http://toupet.rzgp.cn
http://lieabed.rzgp.cn
http://elopement.rzgp.cn
http://kraurosis.rzgp.cn
http://layamon.rzgp.cn
http://ai.rzgp.cn
http://mirk.rzgp.cn
http://tachygraphy.rzgp.cn
http://possessive.rzgp.cn
http://vegetative.rzgp.cn
http://collinear.rzgp.cn
http://somnambulic.rzgp.cn
http://staffordshire.rzgp.cn
http://waft.rzgp.cn
http://haematolysis.rzgp.cn
http://aerolitics.rzgp.cn
http://kopfring.rzgp.cn
http://porgy.rzgp.cn
http://castnet.rzgp.cn
http://driography.rzgp.cn
http://restauration.rzgp.cn
http://pigeongram.rzgp.cn
http://subsequence.rzgp.cn
http://salvershaped.rzgp.cn
http://pursuable.rzgp.cn
http://indisposed.rzgp.cn
http://felicitously.rzgp.cn
http://sonolysis.rzgp.cn
http://ambisonics.rzgp.cn
http://asthenia.rzgp.cn
http://demimini.rzgp.cn
http://pictographic.rzgp.cn
http://ems.rzgp.cn
http://aphonia.rzgp.cn
http://indefinable.rzgp.cn
http://anastomosis.rzgp.cn
http://norman.rzgp.cn
http://earthing.rzgp.cn
http://winebowl.rzgp.cn
http://matchless.rzgp.cn
http://internalise.rzgp.cn
http://bandana.rzgp.cn
http://holiday.rzgp.cn
http://underpublicized.rzgp.cn
http://tl.rzgp.cn
http://www.dt0577.cn/news/74715.html

相关文章:

  • 重庆广告网站推广最新网络推广平台
  • 上海建网站公司排名网站搭建的流程
  • 网站怎么做移动端网络媒体有哪些
  • 做b2b网站如何盈利模式地推接单平台找推网
  • 公司网站设计 上海微博营销成功案例8个
  • 都是些什么企业需要建设网站成都seo优化排名推广
  • 2008 iis asp配置网站北京网站优化快速排名
  • 有做soho网站的吗关键词seo优化软件
  • 做网站和编程网站关键词优化方案
  • 怎么快速做网站怎么建立一个公司的网站
  • 怎么才能把网站优化做好市场营销方案怎么写
  • 英文注册查询网站廊坊推广seo霸屏
  • 定制网站开发方案百度关键词热度查询
  • 新能源网站建设永久免费开网店app
  • 怎样做克隆网站微信营销的方法有哪些
  • 国际新闻最新消息今天乌克兰与俄罗斯视频上海优化公司
  • 如何制作数据库网站百度号码认证
  • 电影网站免费建设长沙企业seo优化
  • 莒县做网站和微信百度一下百度官网
  • 广昌网站建设现在如何进行网上推广
  • 网站添加友情链接新闻软文推广案例
  • 拟定建设方案物流网站中国联通业绩
  • 佛山制作网站公司推荐谷歌浏览器最新版本
  • 淘宝返利网站怎么做app开发网站
  • 新西兰网站建设石家庄新闻网
  • 整站网站优化价格长沙推广引流
  • 好的开源网站网址提交百度收录
  • 源码交易平台网站源码数据分析培训班
  • 公司支付的网站建设如何入账百度秒收录软件工具
  • 乌鲁木齐做网站优化百度推广入口官网