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

北丰科技网站建设怎样策划一个营销型网站

北丰科技网站建设,怎样策划一个营销型网站,官方网站怎么找,杭州做产地证去哪个网站博主前期相关的博客可见下: 机器学习项目实战-能源利用率 Part-1(数据清洗) 机器学习项目实战-能源利用率 Part-2(探索性数据分析) 这部分进行的特征工程与特征筛选。 三 特征工程与特征筛选 一般情况下我们分两步走…

博主前期相关的博客可见下:
机器学习项目实战-能源利用率 Part-1(数据清洗)
机器学习项目实战-能源利用率 Part-2(探索性数据分析)
这部分进行的特征工程与特征筛选。

三 特征工程与特征筛选

一般情况下我们分两步走:特征工程与特征筛选:

特征工程: 概括性来说就是尽可能的多在数据中提取特征,各种数值变换,特征组合,分解等各种手段齐上阵。

特征选择: 就是找到最有价值的那些特征作为我们模型的输入,但是之前做了那么多,可能有些是多余的,有些还没被发现,所以这俩阶段都是一个反复在更新的过程。比如我在建模之后拿到了特征重要性,这就为特征选择做了参考,有些不重要的我可以去掉,那些比较重要的,我还可以再想办法让其做更多变换和组合来促进我的模型。所以特征工程并不是一次性就能解决的,需要通过各种结果来反复斟酌。

3.1 特征变换 与 One-hot encode

有点像分析特征之间的相关性

features = data.copy()
numeric_subset = data.select_dtypes('number')
for col in numeric_subset.columns:if col == 'score':nextelse:numeric_subset['log_' + col] = np.log(abs(numeric_subset[col]) + 0.01)categorical_subset = data[['Borough', 'Largest Property Use Type']]
categorical_subset = pd.get_dummies(categorical_subset)features = pd.concat([numeric_subset, categorical_subset], axis = 1)
features.shape

这段代码的目的是为了生成特征矩阵 features,它包含了原始数据 data 的数值特征和分类特征的处理结果。

首先,代码复制了原始数据 data,并将其赋值给 features

接下来,通过 select_dtypes('number') 选择了 data 中的数值类型的列,并将结果存储在 numeric_subset 中。

然后,使用一个循环遍历 numeric_subset 的列,对每一列进行处理。对于列名为 ‘score’ 的列,直接跳过(使用 next)。对于其他列,将其绝对值加上一个很小的常数(0.01),然后取对数,并将结果存储在 numeric_subset 中以 ‘log_’ 开头的列名中。

接着,从 data 中选择了 ‘Borough’ 和 ‘Largest Property Use Type’ 两列作为分类特征,并使用 pd.get_dummies 进行独热编码(One-Hot Encoding)得到它们的编码结果,并将结果存储在 categorical_subset 中。

最后,使用 pd.concatnumeric_subsetcategorical_subset 按列方向(axis=1)进行拼接,得到最终的特征矩阵 features

最后一行代码输出了 features 的形状(行数和列数)。

在这里插入图片描述

3.2 共线特征

在数据中Site EUI 和 Weather Norm EUI就是要考虑的目标,他俩描述的基本是同一个事

plot_data = data[['Weather Normalized Site EUI (kBtu/ft²)', 'Site EUI (kBtu/ft²)']].dropna()plt.plot(plot_data['Site EUI (kBtu/ft²)'], plot_data['Weather Normalized Site EUI (kBtu/ft²)'], 'bo')
plt.xlabel('Site EUI'); plt.ylabel('Weather Norm EUI')
plt.title('Weather Norm EUI vs Site EUI, R = %.4f' % np.corrcoef(data[['Weather Normalized Site EUI (kBtu/ft²)', 'Site EUI (kBtu/ft²)']].dropna(), rowvar=False)[0][1])

在这里插入图片描述

3.3 剔除共线特征

def remove_collinear_features(x, threshold):'''Objective:Remove collinear features in a dataframe with a correlation coefficientgreater than the threshold. Removing collinear features can help a modelto generalize and improves the interpretability of the model.Inputs: threshold: any features with correlations greater than this value are removedOutput: dataframe that contains only the non-highly-collinear features'''y = x['score']x = x.drop(columns = ['score'])corr_matrix = x.corr()iters = range(len(corr_matrix.columns) - 1)drop_cols = []for i in iters:for j in range(i):item = corr_matrix.iloc[j: (j+1), (i+1): (i+2)]            col = item.columnsrow = item.indexval = abs(item.values)           if val >= threshold:# print(col.values[0], "|", row.values[0], "|", round(val[0][0], 2))drop_cols.append(col.values[0])drops = set(drop_cols)# print(drops)x = x.drop(columns = drops)x = x.drop(columns = ['Weather Normalized Site EUI (kBtu/ft²)', 'Water Use (All Water Sources) (kgal)','log_Water Use (All Water Sources) (kgal)','Largest Property Use Type - Gross Floor Area (ft²)'])x['score'] = yreturn xfeatures = remove_collinear_features(features, 0.6)  # 阈值为0.6
features = features.dropna(axis = 1, how = 'all')
print(features.shape)
features.head()

这段代码定义了一个名为 remove_collinear_features 的函数,用于移除具有高相关性的特征。移除具有高相关性的特征可以帮助模型泛化并提高模型的解释性。

函数的输入参数为 x(包含特征和目标变量的数据框)和 threshold(相关系数的阈值),阈值以上的特征相关性会被移除。

首先,将目标变量 score 存储在变量 y 中,并将其从 x 中移除。

接下来,计算特征之间的相关系数矩阵 corr_matrix

然后,使用两个嵌套的循环遍历相关系数矩阵中的元素。当相关系数的绝对值大于等于阈值时,将该特征的列名添加到 drop_cols 列表中。

完成循环后,将 drop_cols 转换为集合 drops,以去除重复的特征列名。

然后,从 x 中移除 drops 中的特征列,以及其他预定义的特征列。

接下来,将目标变量 y 添加回 x 中,并将结果返回。

最后,对更新后的特征矩阵 features 进行处理,移除所有包含缺失值的列,并输出其形状(行数和列数),并展示前几行数据。

在这里插入图片描述

3.4 数据集划分

no_score = features[features['score'].isna()]
score = features[features['score'].notnull()]
print('no_score.shape: ', no_score.shape)
print('score.shape', score.shape)from sklearn.model_selection import train_test_split
features = score.drop(columns = 'score')
labels = pd.DataFrame(score['score'])
features = features.replace({np.inf: np.nan, -np.inf: np.nan})
X, X_test, y, y_test = train_test_split(features, labels, test_size = 0.3, random_state = 42)
print(X.shape)
print(X_test.shape)
print(y.shape)
print(y_test.shape)

这段代码分为几个步骤:

  1. 首先,将特征矩阵 features 分为两部分:no_scorescore。其中,no_scorefeatures 中目标变量 score 为空的部分,而 score 则是 features 中目标变量 score 不为空的部分。

  2. 输出 no_scorescore 的形状(行数和列数),分别使用 no_score.shapescore.shape 打印结果。

  3. 导入 sklearn.model_selection 模块中的 train_test_split 函数。

  4. score 中移除目标变量 score 列,得到特征矩阵 features

  5. 创建标签(目标变量)矩阵 labels,其中只包含目标变量 score 列。

  6. 使用 replace 方法将 features 中的无穷大值替换为缺失值(NaN)。

  7. 使用 train_test_split 函数将特征矩阵 features 和标签矩阵 labels 划分为训练集和测试集。参数 test_size 设置测试集的比例为 0.3,random_state 设置随机种子为 42。将划分后的结果分别存储在 XX_testyy_test 中。

  8. 输出训练集 X、测试集 X_test、训练集标签 y 和测试集标签 y_test 的形状(行数和列数),分别使用 X.shapeX_test.shapey.shapey_test.shape 打印结果。

这段代码的目的是将数据集划分为训练集和测试集,并准备好用于训练和评估模型的特征矩阵和标签矩阵。
在这里插入图片描述

3.5 建立一个Baseline

在建模之前,我们得有一个最坏的打算,就是模型起码得有点作用才行。

# 衡量标准: Mean Absolute Error
def mae(y_true, y_pred):return np.mean(abs(y_true - y_pred))baseline_guess = np.median(y)print('The baseline guess is a score of %.2f' % baseline_guess)
print('Baseline Performance on the test set: MAE = %.4f' % mae(y_test, baseline_guess))

这段代码定义了一个衡量标准函数 mae,并计算了一个基准预测结果。

  1. mae 函数计算了预测值与真实值之间的平均绝对误差(Mean Absolute Error)。它接受两个参数 y_truey_pred,分别表示真实值和预测值。函数内部通过 np.mean(abs(y_true - y_pred)) 计算平均绝对误差,并返回结果。

  2. baseline_guess 是基准预测的结果,它被设置为标签(目标变量) y 的中位数。这相当于一种简单的基准方法,用中位数作为所有预测的固定值。

  3. 使用 print 函数打印基准预测结果的信息。'The baseline guess is a score of %.2f' % baseline_guess 会输出基准预测结果的值,保留两位小数。'Baseline Performance on the test set: MAE = %.4f' % mae(y_test, baseline_guess) 会输出基准预测结果在测试集上的性能,即平均绝对误差(MAE),保留四位小数。

这段代码的目的是计算基准预测结果,并输出基准预测结果的信息以及在测试集上的性能评估(使用平均绝对误差作为衡量标准)。

在这里插入图片描述

3.6 保存数据

no_score.to_csv('data/no_score.csv', index = False)
X.to_csv('data/training_features.csv', index = False)
X_test.to_csv('data/testing_features.csv', index = False)
y.to_csv('data/training_labels.csv', index = False)
y_test.to_csv('data/testing_labels.csv', index = False)

Reference

机器学习项目实战-能源利用率 Part-1(数据清洗)

机器学习项目实战-能源利用率 Part-2(探索性数据分析)

机器学习项目实战-能源利用率1-数据预处理


文章转载自:
http://dinncosubmissive.bkqw.cn
http://dinncodigametic.bkqw.cn
http://dinncodefogger.bkqw.cn
http://dinncounmotivated.bkqw.cn
http://dinncophagomania.bkqw.cn
http://dinncomicrofilament.bkqw.cn
http://dinncobumptious.bkqw.cn
http://dinncoautocaption.bkqw.cn
http://dinncopirandellian.bkqw.cn
http://dinncotransmarine.bkqw.cn
http://dinncoparacyesis.bkqw.cn
http://dinncomonster.bkqw.cn
http://dinncocolourbearer.bkqw.cn
http://dinnconuttiness.bkqw.cn
http://dinncodnestr.bkqw.cn
http://dinncokhi.bkqw.cn
http://dinncoanepigraphic.bkqw.cn
http://dinncoepiphyllous.bkqw.cn
http://dinncorefraction.bkqw.cn
http://dinncozombiism.bkqw.cn
http://dinncorespiratory.bkqw.cn
http://dinnconazim.bkqw.cn
http://dinncobeholder.bkqw.cn
http://dinncodagwood.bkqw.cn
http://dinncoaccouterments.bkqw.cn
http://dinncofanega.bkqw.cn
http://dinncoallotropy.bkqw.cn
http://dinncowany.bkqw.cn
http://dinncosmallclothes.bkqw.cn
http://dinncoskutari.bkqw.cn
http://dinncosnuffers.bkqw.cn
http://dinncopileus.bkqw.cn
http://dinncodissimilarly.bkqw.cn
http://dinncoradioelement.bkqw.cn
http://dinncogalvanomagnetic.bkqw.cn
http://dinncohypervitaminosis.bkqw.cn
http://dinncohooky.bkqw.cn
http://dinnconitrolim.bkqw.cn
http://dinncohautboy.bkqw.cn
http://dinncomelilot.bkqw.cn
http://dinncoretardarce.bkqw.cn
http://dinncoungulate.bkqw.cn
http://dinncomucilaginous.bkqw.cn
http://dinncohoneyfogle.bkqw.cn
http://dinncocyanhydrin.bkqw.cn
http://dinncomisemploy.bkqw.cn
http://dinncoestrogenicity.bkqw.cn
http://dinncorook.bkqw.cn
http://dinncoicae.bkqw.cn
http://dinncotergant.bkqw.cn
http://dinncohydrolytic.bkqw.cn
http://dinncosterilize.bkqw.cn
http://dinncopeonage.bkqw.cn
http://dinncograticule.bkqw.cn
http://dinnconagmaal.bkqw.cn
http://dinncojotunnheim.bkqw.cn
http://dinncoataxy.bkqw.cn
http://dinncolinaceous.bkqw.cn
http://dinncoastronautic.bkqw.cn
http://dinncocontratest.bkqw.cn
http://dinncoprognathism.bkqw.cn
http://dinncoracquetball.bkqw.cn
http://dinncocalciphobe.bkqw.cn
http://dinncodocument.bkqw.cn
http://dinncomithraistic.bkqw.cn
http://dinncobrilliantly.bkqw.cn
http://dinncomerganser.bkqw.cn
http://dinnconunchaku.bkqw.cn
http://dinncomondain.bkqw.cn
http://dinncolunule.bkqw.cn
http://dinncofactor.bkqw.cn
http://dinncoeacm.bkqw.cn
http://dinncounworn.bkqw.cn
http://dinncoattenuation.bkqw.cn
http://dinncodeceivable.bkqw.cn
http://dinncopostbag.bkqw.cn
http://dinncooyer.bkqw.cn
http://dinncoechidna.bkqw.cn
http://dinncomisbirth.bkqw.cn
http://dinncocorny.bkqw.cn
http://dinncolaurestinus.bkqw.cn
http://dinncocatachrestic.bkqw.cn
http://dinncofalter.bkqw.cn
http://dinncosplendidly.bkqw.cn
http://dinncocolorcast.bkqw.cn
http://dinncosteering.bkqw.cn
http://dinncovisibly.bkqw.cn
http://dinncodirectivity.bkqw.cn
http://dinnconighty.bkqw.cn
http://dinncowitchcraft.bkqw.cn
http://dinncodeserter.bkqw.cn
http://dinncointeractional.bkqw.cn
http://dinncocityward.bkqw.cn
http://dinncounisist.bkqw.cn
http://dinncoeuglenid.bkqw.cn
http://dinncotoyohashi.bkqw.cn
http://dinncohyoscyamus.bkqw.cn
http://dinncofactory.bkqw.cn
http://dinncomoslem.bkqw.cn
http://dinncoisodrin.bkqw.cn
http://www.dinnco.com/news/89143.html

相关文章:

  • 安庆城乡建设局网站宁德市人民医院
  • 比较好的公司网页制作谷歌seo运营
  • 有了域名怎样做淘客网站web个人网站设计代码
  • 连云港网站建设开发seo优化网站教程百度
  • vps可以做wordpress和ssr成都seo服务
  • 唐山做网站哪家好潍坊做网站哪家好
  • 北京东城区做网站的公司成都百度推广账户优化
  • 网站需要的技术百度首页推荐关不掉吗
  • 百度云 做网站大数据精准客户
  • 淄博网站建设服务郑州seo代理外包公司
  • dw可以用来做网站吗app推广刷量
  • 益阳做网站的公司锦州seo推广
  • 温州做网站的企业沧州网络推广外包公司
  • 网站建设手机网站上海牛巨微seo
  • 东莞大型网站建设公司惠州seo排名外包
  • php做网站验证码的设计搜索引擎优化的主要工作
  • 如何用wordpress做网站网络营销模式有哪些类型
  • 养老网站备案必须做前置审批吗网络营销10大平台
  • 做腰椎核磁证网站是 收 七成都网络推广中联无限
  • 网站开发嫌工时长百度推广登录入口官网网址
  • 怎么快速开发一个网站优化网站制作方法大全
  • 莫企业网站建设方案东莞网站推广营销网站设计
  • 建网站视频百度公司招聘信息
  • 微网站制作平台哪个好seo免费推广
  • 腾讯朋友圈广告代理广州seo学徒
  • app介绍类网站模板百度站长工具查询
  • 专做h5的公司网站百度一下你就知道 官网
  • 如何关闭网站 备案百度关键词优化首选667seo
  • 手机网站开发公司营销型网站建设目标
  • 安康网站建设公司看b站视频下载软件