python 验证模型_python中的模型验证

python 验证模型

Scikit-learn is an open source machine learning library that provides tools for building, training and testing models. The model selection module has many functions that are useful for model testing and validation. In this post, we will discuss some of the important model selection functions in scikit-learn.

Scikit-learn是一个开放源代码的机器学习库,提供用于构建,训练和测试模型的工具。 模型选择模块具有许多对模型测试和验证有用的功能。 在本文中,我们将讨论scikit-learn中的一些重要模型选择功能。

Let’s get started!

让我们开始吧!

For our purposes, we will be working with The Wines Reviews data set, which can be found here.

为了我们的目的,我们将使用“葡萄酒评论”数据集,可在此处找到。

To start, let’s read our data into a Pandas data frame:

首先,让我们将数据读取到Pandas数据框中:

import pandas as pd
df = pd.read_csv("winemag-data-130k-v2.csv")

Next, let’s print the first five rows of data:

接下来,让我们打印数据的前五行:

print(df.head())
Image for post

Let’s consider the task of predicting whether wine price is more expensive than $50 based on the variety, winery, country and review points. We can build a random forest classifier to perform this task. First, let’sconvert the categorical features into categorical codes that can be handled by random forests:

让我们考虑根据品种,酒庄,国家和审查要点来预测葡萄酒价格是否高于50美元的任务。 我们可以构建一个随机森林分类器来执行此任务。 首先,让我们将分类特征转换为可以由随机森林处理的分类代码:

df['country_cat'.format(i)] = df['country'].astype('category').copy()
df['country_cat'.format(i)] = df['country_cat'.format(i)].cat.codesdf['winery_cat'.format(i)] = df['winery'].astype('category').copy()
df['winery_cat'.format(i)] = df['winery_cat'.format(i)].cat.codesdf['variety_cat'.format(i)] = df['variety'].astype('category').copy()
df['variety_cat'.format(i)] = df['variety_cat'.format(i)].cat.codes

Let’s also impute missing values. We won’t do any fancy imputing here but check out Predicting Missing Values with Python for a more reliable method of imputation. Here, let’s replace missing values with 0:

让我们还估算缺失的值。 我们不会在此处进行任何花哨的插补,但请查看

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值