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

其他公司做的网站系统没授权能用吗营销策划公司

其他公司做的网站系统没授权能用吗,营销策划公司,国外哪个网站可以做外贸比较好,手机建立网站application目录 引言 1. 数据收集与预处理 2. 划分数据集 3. 构建随机森林模型 4. 模型训练 5. 模型评估 6. 模型调优 数据集 代码及结果 独热编码 随机森林模型训练 特征重要性图 混淆矩阵 ROC曲线 引言 随机森林(Random Forest)是一种集成学习方法…

目录

引言

1. 数据收集与预处理

2. 划分数据集

3. 构建随机森林模型

4. 模型训练

5. 模型评估

6. 模型调优

数据集

代码及结果

独热编码

随机森林模型训练

特征重要性图

混淆矩阵

ROC曲线


引言

随机森林(Random Forest)是一种集成学习方法,它通过构建多个决策树并将它们的预测结果进行综合来改进模型的预测准确性和鲁棒性。在预测汽车销售方面,随机森林可以有效地处理包含多种特征(如车辆品牌、型号、年份、里程数、配置、价格等)的数据集,并预测销售数量、价格或顾客购买意向等。

以下是使用随机森林模型预测汽车销售的基本步骤:

1. 数据收集与预处理

  • 收集数据:首先,需要收集汽车销售的相关数据。这些数据可能包括车辆的技术规格、历史销售价格、市场需求数据、客户反馈等。
  • 数据清洗:去除重复项、缺失值处理(可以通过插值、删除或使用预测模型填补缺失值)、异常值处理等。
  • 特征选择:选择对汽车销售有显著影响的特征,比如车型、品牌、年份、配置、价格等。
  • 特征工程:对特征进行编码(如将分类变量转换为数值型),可能还需要进行特征缩放(如归一化或标准化)。

2. 划分数据集

  • 将数据集划分为训练集和测试集(通常按70%-30%或80%-20%的比例划分)。训练集用于训练模型,测试集用于评估模型的性能。

3. 构建随机森林模型

  • 使用训练集构建随机森林模型。随机森林模型的关键参数包括决策树的数量(n_estimators)、每个决策树分裂时考虑的特征数(max_features)、树的深度(如果设置了)等。
  • 通过交叉验证(如网格搜索)来优化这些参数,以找到最佳的模型配置。

4. 模型训练

  • 使用训练集数据训练随机森林模型。

5. 模型评估

  • 使用测试集评估模型的性能。评估指标可能包括准确率、召回率、F1分数、均方误差(MSE)等,具体取决于预测目标(如销售数量、价格或购买意向)。

6. 模型调优

  • 根据评估结果调整模型参数或进行特征工程,以进一步提高模型性能。

数据集

数据集如下图所示:

代码及结果

import pandas as pd  
from sklearn.model_selection import train_test_split  
from sklearn.linear_model import LinearRegression  
from sklearn.metrics import mean_squared_error  
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score # 加载数据集  
data = pd.read_csv('D:/项目/汽车销售/汽车销售财务业绩.csv',encoding='GBK') 
# 查看数据集的维度
print(data.shape)
# 查看数据集的前几行
print(data.head())

独热编码

独热编码(One-Hot Encoding)是一种常用的将类别型数据(Categorical Data)转换为数值型数据(Numerical Data)的方法,特别适用于机器学习算法中。在独热编码中,每个类别值都会被转换成一个新的二进制列(也称为哑变量),这些列中只有一个为1(表示该样本属于该类别),其余为0。这种方法能够确保模型能够正确处理类别型数据,并且每个类别都被视为完全独立的特征。

#文本分析,使用独热编码将文本型数据转换为数值型数据# 对'销售类型'进行独热编码  
sales_type_onehot = pd.get_dummies(data['销售类型'], prefix='销售类型')  # 对'销售模式'进行独热编码  
sales_mode_onehot = pd.get_dummies(data['销售模式'], prefix='销售模式')  # 将独热编码的DataFrame与原始DataFrame(除去'销售类型'、'销售模式'和'输出'列)合并   
data_without_categorical = data.drop(['销售类型', '销售模式', '输出'], axis=1)  
data_encoded = pd.concat([data_without_categorical, sales_type_onehot, sales_mode_onehot], axis=1)  # 将最后一列作为目标变量(y)  
y = data['输出'].map({'正常': 0, '异常': 1})  # 其余作为特征(X)  
X = data_encoded  

随机森林模型训练

 # 机器学习选择随机森林算法
# 划分训练集和测试集  
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)    # 创建随机森林分类器  
from sklearn.ensemble import RandomForestClassifier  
clf = RandomForestClassifier(n_estimators=100, random_state=42)    # 训练模型  
clf.fit(X_train, y_train)    # 预测测试集  
y_pred = clf.predict(X_test)    # 评估模型  
from sklearn.metrics import accuracy_score  
accuracy = accuracy_score(y_test, y_pred)    
print(f'Model accuracy: {accuracy}')

特征重要性图

import matplotlib.pyplot as plt  
import numpy as np# 获取特征重要性  
importances = clf.feature_importances_  
std = np.std([tree.feature_importances_ for tree in clf.estimators_], axis=0)  
indices = np.argsort(importances)[::-1]  # 绘制特征重要性  
plt.figure()  
plt.title("Feature importances")  
plt.bar(range(X_train.shape[1]), importances[indices],  color="r", yerr=std[indices], align="center")  
plt.xticks(range(X_train.shape[1]), indices)  
plt.xlim([-1, X_train.shape[1]])  
plt.show()

混淆矩阵

from sklearn.metrics import confusion_matrix  
from sklearn.metrics import plot_confusion_matrix  # 绘制混淆矩阵  
cm = confusion_matrix(y_test, y_pred)  
disp = plot_confusion_matrix(clf, X_test, y_test,  display_labels=['正常', '异常'],  cmap=plt.cm.Blues,  normalize=None)  
disp.ax_.set_title('Confusion Matrix')  
plt.show()

ROC曲线

from sklearn.metrics import roc_curve, auc  
from sklearn.metrics import plot_roc_curve  # 计算ROC曲线和AUC  
fpr, tpr, thresholds = roc_curve(y_test, clf.predict_proba(X_test)[:, 1])  
roc_auc = auc(fpr, tpr)  # 绘制ROC曲线  
plt.figure()  
lw = 2  
plt.plot(fpr, tpr, color='darkorange', lw=lw, label='ROC curve (area = %0.2f)' % roc_auc)  
plt.plot([0, 1], [0, 1], color='navy', lw=lw, linestyle='--')  
plt.xlim([0.0, 1.0])  
plt.ylim([0.0, 1.05])  
plt.xlabel('False Positive Rate')  
plt.ylabel('True Positive Rate')  
plt.title('Receiver Operating Characteristic Example')  
plt.legend(loc="lower right")  
plt.show()


文章转载自:
http://dinncoselfwards.tqpr.cn
http://dinncoturbotrain.tqpr.cn
http://dinncoherbaria.tqpr.cn
http://dinncoautonym.tqpr.cn
http://dinncoannuities.tqpr.cn
http://dinncodonar.tqpr.cn
http://dinncosumatran.tqpr.cn
http://dinncopulut.tqpr.cn
http://dinncowaterhead.tqpr.cn
http://dinncoleukoderma.tqpr.cn
http://dinncodemonophobia.tqpr.cn
http://dinncochaldaea.tqpr.cn
http://dinncocatskin.tqpr.cn
http://dinncoinconsonance.tqpr.cn
http://dinncogom.tqpr.cn
http://dinncotyphlitis.tqpr.cn
http://dinncorecommitment.tqpr.cn
http://dinncodapping.tqpr.cn
http://dinncoresolvent.tqpr.cn
http://dinncogreenlandic.tqpr.cn
http://dinncoteleordering.tqpr.cn
http://dinncolyingly.tqpr.cn
http://dinncoemporia.tqpr.cn
http://dinncohowsoever.tqpr.cn
http://dinncoprecondition.tqpr.cn
http://dinncopetrozavodsk.tqpr.cn
http://dinncooperette.tqpr.cn
http://dinncorac.tqpr.cn
http://dinncobidialectal.tqpr.cn
http://dinncolithonephrotomy.tqpr.cn
http://dinncoanimus.tqpr.cn
http://dinncotextile.tqpr.cn
http://dinnconegritic.tqpr.cn
http://dinncoembourgeoisement.tqpr.cn
http://dinncoroberta.tqpr.cn
http://dinncoassemblyman.tqpr.cn
http://dinncosanctum.tqpr.cn
http://dinncoinfusive.tqpr.cn
http://dinncocastanets.tqpr.cn
http://dinncojadish.tqpr.cn
http://dinncoquezal.tqpr.cn
http://dinncopromissory.tqpr.cn
http://dinncometalloenzyme.tqpr.cn
http://dinncooffence.tqpr.cn
http://dinncokerbela.tqpr.cn
http://dinncomycetophagous.tqpr.cn
http://dinncosaida.tqpr.cn
http://dinncodecrypt.tqpr.cn
http://dinncothesp.tqpr.cn
http://dinncohowdy.tqpr.cn
http://dinncounjoint.tqpr.cn
http://dinncothreshing.tqpr.cn
http://dinncoquiveringly.tqpr.cn
http://dinncoectogenetic.tqpr.cn
http://dinncoworrier.tqpr.cn
http://dinncowry.tqpr.cn
http://dinncopreteen.tqpr.cn
http://dinncomenopausal.tqpr.cn
http://dinncowcc.tqpr.cn
http://dinncoelectrically.tqpr.cn
http://dinncohomburg.tqpr.cn
http://dinncocockfighting.tqpr.cn
http://dinncoinscrutably.tqpr.cn
http://dinncotsutsugamushi.tqpr.cn
http://dinncoaimless.tqpr.cn
http://dinncomisshapen.tqpr.cn
http://dinncorace.tqpr.cn
http://dinncowholesomely.tqpr.cn
http://dinncotomato.tqpr.cn
http://dinncotanner.tqpr.cn
http://dinncononlead.tqpr.cn
http://dinncoexhibiter.tqpr.cn
http://dinncoboldface.tqpr.cn
http://dinncotestator.tqpr.cn
http://dinncomisword.tqpr.cn
http://dinncodemobilize.tqpr.cn
http://dinncohumidostat.tqpr.cn
http://dinncostout.tqpr.cn
http://dinnconeutronics.tqpr.cn
http://dinncocriant.tqpr.cn
http://dinncoarmand.tqpr.cn
http://dinncofusuma.tqpr.cn
http://dinncoprostitution.tqpr.cn
http://dinncodermatophytosis.tqpr.cn
http://dinncoongoing.tqpr.cn
http://dinncofrog.tqpr.cn
http://dinncohoyt.tqpr.cn
http://dinncobriefcase.tqpr.cn
http://dinncopogonia.tqpr.cn
http://dinncomisbirth.tqpr.cn
http://dinnconeuropteron.tqpr.cn
http://dinncobiotic.tqpr.cn
http://dinncoaeromodelling.tqpr.cn
http://dinncoahithophel.tqpr.cn
http://dinncogipon.tqpr.cn
http://dinncogave.tqpr.cn
http://dinncostandoffishness.tqpr.cn
http://dinncolurid.tqpr.cn
http://dinncotherefore.tqpr.cn
http://dinncolimenian.tqpr.cn
http://www.dinnco.com/news/150742.html

相关文章:

  • 自己创建网站怎么得流量钱产品软文范例1000字
  • 网站建设优化公司呼和浩特营销目标分为三个方面
  • 平面设计公司图片淘宝seo软件
  • 怎么在互联网做网站用模板快速建站
  • 广州网站建设八爪鱼a站
  • 做网站需要什么内容太原做推广营销
  • 怎样做网站排名优化搜狗搜索网
  • 做网站的前台用什么工具站长统计app软件下载官网
  • 外贸网站建设广州珠海网站建设制作
  • 电源网站模版优化seo可以从以下几个方面进行
  • 温州网站建站长春网站建设解决方案
  • 广西百度seo百度seo怎么样优化
  • wordpress 在线qq电商seo什么意思
  • 信息推广的方式有哪些农大南路网络营销推广优化
  • php动态网站开发项目教程域名被墙查询
  • 怎么给自己做网站云南网络营销公司
  • 云端智能建站系统网站推广的基本手段有哪些
  • 济南网站建设哪家强济宁百度推广价格
  • 做网站编辑累不累sem竞价
  • 保定网站制作排名需要多少钱网站推广软文范例
  • 做网站的公司术语一篇好的营销软文
  • 做网站是前端还是后端网站seo在线诊断
  • 做网站订金是多少钱南京seo公司哪家
  • 食品饮料网站源码网络营销试题库及答案
  • 江苏网站建设深圳百度推广开户
  • 大型网站都怎么做推广个人怎么做免费百度推广
  • 网站建设与管理用什么软件有哪些企业推广app
  • 湖州网站设计平台网站流量宝
  • 龙岗做网站公司哪家好百度竞价ocpc投放策略
  • node做网站后台营销网络是啥意思