小宽带怎样做视频网站/泰安做网站公司哪家比较好

小宽带怎样做视频网站,泰安做网站公司哪家比较好,全网型网站建设方案,网站维护托管要多少钱🧑 博主简介:曾任某智慧城市类企业算法总监,目前在美国市场的物流公司从事高级算法工程师一职,深耕人工智能领域,精通python数据挖掘、可视化、机器学习等,发表过AI相关的专利并多次在AI类比赛中获奖。CSDN…

🧑 博主简介:曾任某智慧城市类企业算法总监,目前在美国市场的物流公司从事高级算法工程师一职,深耕人工智能领域,精通python数据挖掘、可视化、机器学习等,发表过AI相关的专利并多次在AI类比赛中获奖。CSDN人工智能领域的优质创作者,提供AI相关的技术咨询、项目开发和个性化解决方案等服务,如有需要请站内私信或者联系任意文章底部的的VX名片(ID:xf982831907

💬 博主粉丝群介绍:① 群内初中生、高中生、本科生、研究生、博士生遍布,可互相学习,交流困惑。② 热榜top10的常客也在群里,也有数不清的万粉大佬,可以交流写作技巧,上榜经验,涨粉秘籍。③ 群内也有职场精英,大厂大佬,可交流技术、面试、找工作的经验。④ 进群免费赠送写作秘籍一份,助你由写作小白晋升为创作大佬。⑤ 进群赠送CSDN评论防封脚本,送真活跃粉丝,助你提升文章热度。有兴趣的加文末联系方式,备注自己的CSDN昵称,拉你进群,互相学习共同进步。

在这里插入图片描述

【机器学习案列】使用随机森林(RF)进行白葡萄酒质量预测

    • 引言
    • 数据集介绍
    • 环境准备
    • 数据预处理
      • 1. 导入相应的分析库和数据加载
      • 2. 数据探索
      • 3. 异常值处理
        • 3.1 缺失值处理
        • 3.2 异常值处理
    • 模型训练
      • 1. 数据标签的0/1化
      • 2. 数据的归一化
      • 3. 划分数据集
      • 4. 训练模型
      • 5. 模型评估
      • 6. 特征重要性
    • 结论

引言

  在葡萄酒产业中,质量评估是一个复杂的过程,涉及到多个化学和感官因素。随着机器学习技术的发展,我们可以使用这些技术来预测葡萄酒的质量。在这篇文章中,我们将使用Python中的RandomForestClassifier来预测白葡萄酒的质量。我们将通过分析数据集中的多个化学成分来训练一个模型,该模型能够预测葡萄酒的质量评分。

数据集介绍

  我们的数据集包含了多个与葡萄酒质量相关的化学成分,这些成分包括:

  • 非挥发性酸(fixed acidity)
  • 挥发性酸(volatile acidity)
  • 柠檬酸(citric acid)
  • 残糖(residual sugar)
  • 氯化物(chlorides)
  • 游离二氧化硫(free sulfur dioxide)
  • 总二氧化硫(total sulfur dioxide)
  • 密度(density)
  • 酸碱度(pH)
  • 硫酸盐(sulphates)
  • 酒精(alcohol)
  • 葡萄酒质量(quality,0-10)

环境准备

  在开始之前,确保你的Python环境中安装了以下库:

  • pandas
  • numpy
  • scikit-learn
  • matplotlib
  • seaborn

  你可以通过以下命令安装这些库:

pip install pandas numpy scikit-learn matplotlib seaborn

数据预处理

1. 导入相应的分析库和数据加载

  首先,我们需要加载数据集。

import warnings # For warning handling# Third-party imports
import pandas as pd # For data processing, CSV file I/O
import numpy as np # For numerical operations and mathematical functions
import matplotlib.pyplot as plt # For data visualization
import seaborn as sns # For statistical graphics
import plotly.express as px # For interactive plotting
from sklearn.model_selection import train_test_split # For data splitting for machine learning
from sklearn.preprocessing import MinMaxScaler, StandardScaler # For feature standardization
from sklearn.metrics import accuracy_score # For model evaluation
from termcolor import colored # For colored text printing
from sklearn.ensemble import RandomForestClassifier # For random forest classifier model# For warning handling
warnings.filterwarnings('ignore') # For ignoring warnings

  加载相应的数据集。

# load data
try:# Relative file pathfilePath = "winequality-white.csv"# Read the CSV file and save it in "data" variabledata= pd.read_csv(filePath,sep=';')# Check loading dataprint(colored("THE DATASET LOADED SUCCESSFULLY...", "green", attrs=['reverse']))except FileNotFoundError:print(colored("ERROR: File not found!", "red", attrs=['reverse']))except Exception as e:print(colored(f"ERROR: {e}", "red", attrs=['reverse']))

在这里插入图片描述

2. 数据探索

  在进行任何预处理之前,我们应该对数据有一个基本的了解,首先查看数据前几行。

# 查看数据集的前几行
dataset_rows = data.head(7) #.head() the default value = 5print(colored('As you can see, the first 7 rows in the dataset:\n', 'green', attrs=['reverse']))# Iterate over each row in the dataset_rows DataFrame
for index, row in dataset_rows.iterrows():# Print the index label of the current rowprint(colored(f"Row {index + 1}:","white",attrs=['reverse']))# Print the content of the current rowprint(row)# Print a separator lineprint("--------------------------------------")

在这里插入图片描述
  查看数据的基本情况,包括shape、特征、总数等等。

print("The shape =",data.shape)# Show information about the dataset
num_rows, num_cols = data.shape
num_features = num_cols - 1
num_data = num_rows * num_cols# Print the information
print(f"Number of Rows: {num_rows}")
print(f"Number of Columns: {num_cols}")
print(f"Number of Features: {num_features}")
print(f"Number of All Data: {num_data}")# Check and ensure running
print(colored("The task has been completed without any errors....","green", attrs=['reverse']))

在这里插入图片描述

# 查看数据集的信息
print(data.info())

在这里插入图片描述
  查看数据统计特征。

data.describe().T.round(2)

在这里插入图片描述
  查看数据标签的分布情况。

# Create a count plot using seaborn
sns.catplot(data=data, x='quality', kind='count')# Add labels and title to the plot
plt.title('Distribution of Wine Quality')
plt.xlabel('Quality')
plt.ylabel('Count')# Display the plot
plt.show()

在这里插入图片描述
  这里的数据EDA部分不在做详细的介绍,具体参考【数据可视化案列】白葡萄酒质量数据的EDA可视化分析一文即可。

3. 异常值处理

3.1 缺失值处理
# Check for missing values
null_counts = data.isnull().sum() # Display the number of null values
print(null_counts)print("_________________________________________________________________")
print(colored(f"Totally, there are {null_counts.sum()} null values in the dataset.","green", attrs=['reverse']))

在这里插入图片描述
  发现数据集中无缺失值的存在(万恶的资本主义数据集中都没有空值)。

3.2 异常值处理
# Set the figure size
plt.figure(figsize=(22, 11))# Add outliers to the plot
sns.stripplot(data=data, color="red", jitter=0.2, size=5)# Set the axis labels and title
plt.title("Outliers")
plt.xlabel("X-axis label")
plt.ylabel("Y-axis label")# Show the plot
plt.show()

在这里插入图片描述

# Delete the outliers
# The data before deleting outliers 
print("Before Removing the outliers", data.shape)# Deleting outliers (Removing the number of observation where the total sulfur dioxide is more than 160)
data = data[data['total sulfur dioxide']<160]#The data after deleting outliers
print("After Removing the outliers", data.shape)

在这里插入图片描述

# Set the figure size
plt.figure(figsize=(22, 11))# Add outliers to the plot
sns.stripplot(data=data, color="red", jitter=0.2, size=5)# Set the axis labels and title
plt.title("Outliers")
plt.xlabel("X-axis label")
plt.ylabel("Y-axis label")# Show the plot
plt.show()

在这里插入图片描述

模型训练

1. 数据标签的0/1化

# Split the data into features (X) and target variable (Y)
X = data.drop('quality',axis=1)# Create a new series 'Y' by applying a lambda function to the 'quality' column of the 'data' DataFrame
# The lambda function assigns a value of 1 if the 'quality' value is greater than or equal to 5, otherwise assigns 0
Y = data['quality'].apply(lambda y_value: 1 if y_value >= 5 else 0)# Print the shapes of X and Y to verify the splitting
print("Shape of X:", X.shape)
print("Shape of Y:", Y.shape)

在这里插入图片描述

2. 数据的归一化

# Rescale and normalize the features
'''
# Standardization (Normalization)
standard_scaler = StandardScaler()
X = standard_scaler.fit_transform(X)
'''# Min-Max Scaling (Rescaling)
min_max_scaler = MinMaxScaler()
X = min_max_scaler.fit_transform(X)#I will choose one of them in the future part "model selection" based on the highest accuracy

3. 划分数据集

  我们将数据集划分为训练集和测试集。

X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2, random_state=44)# Print the shapes of the training and testing sets to verify the splitting
print("Shape of X_train:", X_train.shape)
print("Shape of X_test:", X_test.shape)
print("Shape of Y_train:", Y_train.shape)
print("Shape of Y_test:", Y_test.shape)

在这里插入图片描述

4. 训练模型

  使用RandomForestClassifier训练模型。

# Initialize lists to store training and testing accuracies
scoreListRF_Train = []
scoreListRF_Test = []'''
max_dep      ----------> (1, 5),(1, 10) 
rand_state   ----------> (1, 35),(1, 50)
n_est        ----------> (1, 30),(1, 30)
'''# Iterate over different values of max_depth
for max_dep in range(1, 5):# Iterate over different values of random_statefor rand_state in range(1, 20):# Iterate over different values of n_estimatorsfor n_est in range(1, 15):# Create a Random Forest model with the different values of max_depth, random_state, and n_estimatorsModel = RandomForestClassifier(n_estimators=n_est, random_state=rand_state, max_depth=max_dep)            # Fit the model on the training dataModel.fit(X_train, Y_train)# Calculate and store the training accuracyscoreListRF_Train.append(Model.score(X_train, Y_train))# Calculate and store the testing accuracyscoreListRF_Test.append(Model.score(X_test, Y_test))# Find the maximum accuracy for both training and testing
RF_Accuracy_Train = max(scoreListRF_Train) 
RF_Accuracy_Test = max(scoreListRF_Test)# Print the best accuracies achieved
print(f"Random Forest best accuracy (Training): {RF_Accuracy_Train*100:.2f}%")
print(f"Random Forest best accuracy (Testing): {RF_Accuracy_Test*100:.2f}%")# Print a success message indicating that the model has been trained successfully
print(colored("The Random Forest model has been trained successfully","green", attrs=['reverse']))

在这里插入图片描述

5. 模型评估

  评估模型的性能。

from sklearn.metrics import accuracy_score, classification_report, confusion_matrix# 预测测试集
y_pred = Model.predict(X_test)# 计算准确率
accuracy = accuracy_score(Y_test, y_pred)
print(f'Accuracy: {accuracy:.2f}')# 打印分类报告
print(classification_report(Y_test, y_pred))# 打印混淆矩阵
print(confusion_matrix(Y_test, y_pred))

在这里插入图片描述

6. 特征重要性

  RandomForestClassifier提供了一个方便的特性,即可以查看每个特征的重要性。

import matplotlib.pyplot as plt
import seaborn as sns# 获取特征重要性
feature_importances = Model.feature_importances_# 创建一个DataFrame来存储特征和它们的重要性
feature_importance_df = pd.DataFrame({'Feature': data.columns.tolist()[:-1],'Importance': feature_importances
})# 对特征重要性进行排序
feature_importance_df = feature_importance_df.sort_values(by='Importance', ascending=False)# 绘制特征重要性图
plt.figure(figsize=(10, 8))
sns.barplot(x='Importance', y='Feature', data=feature_importance_df)
plt.title('Feature Importance')
plt.show()

在这里插入图片描述

结论

  通过使用RandomForestClassifier,我们能够预测白葡萄酒的质量。在这个过程中,我们进行了数据预处理、特征选择、模型训练和评估,并分析了特征的重要性。这只是一个简单的示例,实际应用中可能需要更复杂的数据预处理和模型调优。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/64596.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Reactor

文章目录 正确的理解发送double free问题 1.把我们的reactor进行拆分2.链接管理3.Reactor的理论 listensock只需要设置_recv_cb&#xff0c;而其他sock&#xff0c;读&#xff0c;写&#xff0c;异常 所以今天写nullptr其实就不太对&#xff0c;添加为空就没办法去响应事件 获…

React,Antd实现文本输入框话题添加及删除的完整功能解决方案

最终效果就是实现该输入框&#xff1a; 添加话题时&#xff0c;话题自动插入到输入框前面多文本输入框左侧间距为话题的宽度多行文本时&#xff0c;第二行紧接开头渲染删除文本时&#xff0c;如果删除到话题&#xff0c;再次删除&#xff0c;话题被删除 首先构造div结构 cons…

【机器人】ATM 用于策略学习的任意点轨迹建模 RSS 2024 | 论文精读

文章提出了一种新的框架&#xff0c;名为Any-point Trajectory Modeling (ATM) &#xff0c;称为任意点轨迹建模。 用于从视频中预测任意点的未来轨迹&#xff0c;从而在最少动作标签数据的情况下&#xff0c;学习稳健的视觉运动策略。 图中展示了三个案例&#xff0c;打开柜子…

Android 搭建AIDL Client和Server端,双向通信

一、背景 使用AIDL,搭建Client和Server端,实现跨进程通讯,即两个应用之间可以相互通讯。这里列举AIDL实现的方式和需注意的细节&#xff0c;并附上源码。 二、实现方式 2.1 定义AIDL需要的接口,名字为xxx.aidl,Client和Server端 AIDL接口的包名和aidl文件必须一致&#xff0c…

【VUE】14、VUE项目如何自动识别服务端是否发布了新版本

今天介绍的是通过轮询的方式去检测服务端是否发布了新版本&#xff0c;从而提醒客户刷新页面&#xff0c;提升用户体验。 1、实现思路 使用轮询的方式获取项目中 index.html 文件。查询文件引入的 JS 文件是否有更新&#xff08; Vue 每次打包后会生成新的引入文件&#xff0…

空天地遥感数据识别与计算--数据分析如何助力农林牧渔、城市发展、地质灾害监测等行业革新

在科技飞速发展的时代&#xff0c;遥感数据的精准分析已经成为推动各行业智能决策的关键工具。从无人机监测农田到卫星数据支持气候研究&#xff0c;空天地遥感数据正以前所未有的方式为科研和商业带来深刻变革。然而&#xff0c;对于许多专业人士而言&#xff0c;如何高效地处…

多智能体/多机器人网络中的图论法

一、引言 1、网络科学至今受到广泛关注的原因&#xff1a; &#xff08;1&#xff09;大量的学科&#xff08;尤其生物及材料科学&#xff09;需要对元素间相互作用在多层级系统中所扮演的角色有更深层次的理解&#xff1b; &#xff08;2&#xff09;科技的发展促进了综合网…

python数据分析:介绍pandas库的数据类型Series和DataFrame

安装pandas pip install pandas -i https://mirrors.aliyun.com/pypi/simple/ 使用pandas 直接导入即可 import pandas as pd pandas的数据结构 pandas提供了两种主要的数据结构&#xff1a;Series 和 DataFrame,类似于python提供list列表&#xff0c;dict字典&#xff0c;…

Python:枚举(包含例题字符计数,反倍数,洁净数,扫雷)

一.枚举是什么 枚举&#xff1a;通过逐个尝试所有可能的值或组合来解决问题的方法。 将问题空间划分为一系列离散的状态&#xff0c;并通过遍历这些状态来寻找解决方案。 二.枚举流程 1.确定解空间&#xff08;一维&#xff0c;二维等&#xff09; 2.确定空间边界&#xff…

设计模式之 abstract factory

适用场景 一个系统要独立于它的产品的创建、组合和表示时。一个系统要由多个产品系列中的一个来配置时。当你要强调一系列相关的产品对象的设计以便进行联合使用时。当你提供一个产品类库&#xff0c;而只想显示它们的接口而不是实现时 架构演示 首先client这个东西可以接触到…

linux-----数据库

Linux下数据库概述 数据库类型&#xff1a; 关系型数据库&#xff08;RDBMS&#xff09;&#xff1a;如MySQL、PostgreSQL、Oracle等。这些数据库以表格的形式存储数据&#xff0c;表格之间通过关系&#xff08;如主键 - 外键关系&#xff09;相互关联。关系型数据库支持复杂的…

鸿蒙学习笔记:用户登录界面

文章目录 1. 提出任务2. 完成任务2.1 创建鸿蒙项目2.2 准备图片资源2.3 编写首页代码2.4 启动应用 3. 实战小结 1. 提出任务 本次任务聚焦于运用 ArkUI 打造用户登录界面。需呈现特定元素&#xff1a;一张图片增添视觉感&#xff0c;两个分别用于账号与密码的文本输入框&#…

RunCam WiFiLink连接手机图传测试

RunCam WiFiLink中文手册从这里下载 一、摄像头端 1.连接天线&#xff08;易忘&#xff09; 2.打开摄像头前面的盖子&#xff08;易忘&#xff09; 3.接上直流电源&#xff0c;红线为正&#xff0c;黑线为负 4.直流电源设置电压为14v&#xff0c;电流为3.15A&#xff0c; 通…

通过阿里云 Milvus 和 LangChain 快速构建 LLM 问答系统

背景介绍 阿里云向量检索 Milvus 版是一款云上全托管服务&#xff0c;确保了与开源Milvus的100%兼容性&#xff0c;并支持无缝迁移。在开源版本的基础上增强了可扩展性&#xff0c;能提供大规模 AI 向量数据的相似性检索服务。相比于自建&#xff0c;目前阿里云Milvus具备易用…

LeetCode刷题day29——动态规划(完全背包)

LeetCode刷题day29——动态规划&#xff08;完全背包&#xff09; 377. 组合总和 Ⅳ分析&#xff1a; 57. 爬楼梯&#xff08;第八期模拟笔试&#xff09;题目描述输入描述输出描述输入示例输出示例提示信息 分析&#xff1a; 322. 零钱兑换分析&#xff1a; 279. 完全平方数分…

多个Echart遍历生成 / 词图云

echart官网 安装 如果版本报错推荐安装以下版本 npm install echarts4.8.0 --savenpm uninstall echarts//这个是卸载命令以下安装成功后是局部引入:多个Echart遍历生成 vue3echart单个页面多个图表循环渲染展示:<template><div class"main"><div …

LabVIEW伸缩臂参数监控系统

LabVIEW开发伸缩臂越野叉车参数监控系统主要应用于工程机械中的越野叉车&#xff0c;以提高车辆的作业效率和故障诊断能力。系统通过PEAK CAN硬件接口和LabVIEW软件平台实现对叉车作业参数的实时监控和故障分析&#xff0c;具有良好的实用性和推广价值。 系统组成 系统主要由P…

【FFmpeg】解封装 ① ( 封装与解封装流程 | 解封装函数简介 | 查找码流标号和码流参数信息 | 使用 MediaInfo 分析视频文件 )

文章目录 一、解封装1、封装与解封装流程2、解封装 常用函数 二、解封装函数简介1、avformat_alloc_context 函数2、avformat_free_context 函数3、avformat_open_input 函数4、avformat_close_input 函数5、avformat_find_stream_info 函数6、av_read_frame 函数7、avformat_s…

YOLOv8目标检测——详细记录使用ONNX Runtime进行推理部署C++/Python实现

概述 在之前博客中有介绍YOLOv8从环境安装到训练的完整过程&#xff0c;本节主要介绍ONNX Runtime的原理以及使用其进行推理加速&#xff0c;使用Python、C两种编程语言来实现。 https://blog.csdn.net/MariLN/article/details/143924548?spm1001.2014.3001.5501 1. ONNX Ru…

python学opencv|读取图像(十六)修改HSV图像HSV值

【1】引言 前序学习进程中&#xff0c;我们已经掌握了对HSV通道和BGR通道的拆分和合并&#xff0c;并通过自由组合的形式&#xff0c;获得了和初始图像完全不一样的新图像&#xff0c;相关文章可以参考下述链接&#xff1a; python学opencv|读取图像&#xff08;十四&#xf…