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

企业网站开发 外文文献seo快速优化

企业网站开发 外文文献,seo快速优化,一家专门做建材的网站,云南文山在哪里文章目录 Iris数据的准备1.直接从sklearn.datasets 加载或转化成文件已备本地使用2.可以在https://archive.ics.uci.edu/dataset/53/iris下载 过程示例代码如下生成的决策树如下:生成的分析报告如下: 决策树模型分析报告1. 模型性能2. 特征重要性3. 决策…

文章目录

    • Iris数据的准备
      • 1.直接从sklearn.datasets 加载或转化成文件已备本地使用
      • 2.可以在https://archive.ics.uci.edu/dataset/53/iris下载
    • 过程
    • 示例
      • 代码如下
      • 生成的决策树如下:
      • 生成的分析报告如下:
  • 决策树模型分析报告
    • 1. 模型性能
    • 2. 特征重要性
    • 3. 决策规则

Iris数据的准备

1.直接从sklearn.datasets 加载或转化成文件已备本地使用

代码如下:

from sklearn.datasets import load_iris
import pandas as pd# 加载数据集
iris = load_iris()
df = pd.DataFrame(data=iris.data, columns=iris.feature_names)# 将数字标签替换为植物名
df['species'] = [iris.target_names[i] for i in iris.target]  # 新增一列植物名
df['target'] = iris.target
# # 保存为Excel文件(不包含行索引)
df.to_excel("iris_dataset.xlsx", index=False)

execl表格如下所示

sepal length (cm)sepal width (cm)petal length (cm)petal width (cm)speciestarget
5.13.51.40.2setosa0
4.931.40.2setosa0
4.73.21.30.2setosa0

2.可以在https://archive.ics.uci.edu/dataset/53/iris下载

过程

  • 读取数据
  • 确定特征
  • 训练决策树模型(按重要性分裂)
  • 模型评估
  • 可视化决策树
  • 生成决策树分析报告

示例

代码如下

import pandas as pd
import numpy as np# 读取数据
df_train = pd.read_excel('iris_dataset.xlsx')# print(df_train.keys())
# print(df_train.head())# 特征工程
def create_features(df):#初始化featuresfeatures = pd.DataFrame()#简化df中原来的列名(feature)features['SepalLength'] = df['sepal length (cm)']features['SepalWidth'] = df['sepal width (cm)']features['PetalLength'] = df['petal length (cm)']features['PetalWidth'] = df['petal width (cm)']return features
# 创建特征
features_train = create_features(df_train)
# print("features_train")
# define the X and y
X_train = df_train.drop(['species', 'target'], axis=1)
y_train = df_train.loc[:, 'target']
# print(X.head())
# print(y.head())
# print(X_train.shape, y_train.shape)
#
# 训练决策树模型(按重要性分裂)
from sklearn.tree import DecisionTreeClassifier,export_textdt = DecisionTreeClassifier(criterion='entropy',min_samples_leaf=5,splitter='best'  # 确保优先选重要性高的特征# ,max_features=1  # 每次分裂只考虑1个特征(需配合特征选择使用)
)
dt.fit(X_train, y_train)
feature_importance = pd.DataFrame({'feature': features_train.columns,'importance': dt.feature_importances_})
# print("特征重要性:\n", feature_importance)# 模型评估
from sklearn.metrics import accuracy_scorey_predict = dt.predict(X_train)
train_score = accuracy_score(y_train, y_predict)
print(train_score)# 可视化决策树
import matplotlib.pyplot as plt
from sklearn.tree import plot_tree# 设置中文显示
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = Falsefig = plt.figure(figsize=(10, 10))
#print(features_train.columns)
plot_tree(dt, feature_names=features_train.columns,class_names=['setosa', 'versicolor','virginica'],filled=True, rounded=True, fontsize=12)
#plt.show()
plt.savefig('decision_tree.png', dpi=300, bbox_inches='tight', pad_inches=0.5)# 生成决策树规则文本
tree_rules = export_text(dt, feature_names=list(features_train.columns))# 生成分析报告
with open('决策树分析.md', 'w', encoding='utf-8') as f:f.write('# 决策树模型分析报告\n\n')# 模型性能f.write('## 1. 模型性能\n')f.write(f'- 训练集准确率: {train_score:.4f}\n')# 特征重要性f.write('## 2. 特征重要性\n')feature_importance = pd.DataFrame({'feature': features_train.columns,'importance': dt.feature_importances_}).sort_values('importance', ascending=False)for _, row in feature_importance.iterrows():f.write(f'- {row["feature"]}: {row["importance"]:.4f}\n')# 决策规则f.write('\n## 3. 决策规则\n')f.write('```\n')f.write(tree_rules)f.write('\n```\n\n')

生成的决策树如下:

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

生成的分析报告如下:

决策树模型分析报告

1. 模型性能

  • 训练集准确率: 0.9733

2. 特征重要性

  • PetalLength: 0.6777
  • PetalWidth: 0.3071
  • SepalLength: 0.0151
  • SepalWidth: 0.0000

3. 决策规则

|--- PetalLength <= 2.45
|   |--- class: 0
|--- PetalLength >  2.45
|   |--- PetalWidth <= 1.75
|   |   |--- PetalLength <= 4.95
|   |   |   |--- SepalLength <= 5.15
|   |   |   |   |--- class: 1
|   |   |   |--- SepalLength >  5.15
|   |   |   |   |--- class: 1
|   |   |--- PetalLength >  4.95
|   |   |   |--- class: 2
|   |--- PetalWidth >  1.75
|   |   |--- PetalLength <= 4.95
|   |   |   |--- class: 2
|   |   |--- PetalLength >  4.95
|   |   |   |--- class: 2
http://www.dtcms.com/wzjs/87592.html

相关文章:

  • 邢台 建网站app推广30元一单
  • phpwind做的网站seo代码优化有哪些方法
  • 域名不转出可以做网站吗重庆网站
  • 做网站推广话术bing搜索引擎国内版
  • 目前做定制产品的网站国内最新十大新闻
  • 网站二维码怎么做的百度推广官方
  • 做导航网站用什么cms万网域名注册信息查询
  • 自己做的网站与ie不兼容企业怎么做好网站优化
  • 凡科做数据查询网站北京seo排名公司
  • 网上哪里给公司做网站网址大全浏览器
  • 天天网站建设如何推广自己的网站
  • 做学校教务处网站病毒营销案例
  • 搜题公众号怎么制作seo工作前景如何
  • wordpress怎么没有导航栏app排名优化
  • 怎样创建个人购物网站google推广妙招
  • 自学网站建设要多久最新军事动态
  • 香港做批发的网站郑州粒米seo顾问
  • 嘉兴网站建设wmcn百度一下app
  • 在线ps网页版网站搜索排名优化怎么做
  • 网站域名查询工具爱链工具
  • 苏州乡村旅游网站建设策划书如何让百度收录自己的网站信息
  • 查询网站所有关键词排名网站优化软件费用
  • 沂seo网站推广做网站哪家好
  • 最好的建设网站优化关键词的方法
  • 直通车关键词优化口诀电商网站seo怎么做
  • 朔州网站建设优化自助网站建设平台
  • 如何跟客户销售做网站seo免费课程视频
  • 移动开发网站开发区别seo软文代写
  • phpwind 做的网站抖音搜索引擎推广
  • 兰溪做网站短视频推广引流