收藏   订阅   蔚来影讯
你现在的位置:首页 » 业余爱好 » 正文

sklearn数据拆分训练集、测试集、验证集常用分割数据函数

时间:2019年08月16日 18:13:11 | 作者 :老马 | 分类 : 业余爱好 | 浏览:1375 | 评论:0

sklearn工具包下载地址

pypi中下载sklearn库,该库在国内也有中文文档,地址是:https://sklearn.apachecn.org/

sklearn工具包简介

这是个基于python的机器学习工具,英文全名为:scikit-learn

scikit :科学工具包

learn :学习

这样就好记住这个工具包名称啦~

在机器学习变成时候,最常用到的就是数据分割为训练集(train_dataset)、测试集(test_dataset)、val_dataset(验证集),在这个工具包中有一个函数就是专门做这个的,它会将拿过来的数据帧(dataframe)分割为tensorflow方便处理的数据格式。

sklearn工具包函数导入方式:

from sklearn.model_selection import train_test_split


sklearn使用方法示例代码:

import tensorflow as tf
from tensorflow import keras
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split

# 下载心脏病例数据集
Url = "https://storage.googleapis.com/applied-dl/heart.csv"
heart_sill_form = pd.read_csv(Url)
# print(dict(heart_sill_form))
heart_sill_form_copy = heart_sill_form.copy()
heart_sill_form_copy_labels = heart_sill_form_copy.pop('target')
# print(heart_sill_form_copy_labels)
ds = tf.data.Dataset.from_tensor_slices((dict(heart_sill_form), heart_sill_form_copy_labels))
print(ds)


打印结果:

<TensorSliceDataset shapes: ({age: (), sex: (), cp: (), trestbps: (), chol: (), fbs: (), restecg: (), thalach: (), exang: (), oldpeak: (), slope: (), ca: (), thal: (), target: ()}, ()), types: ({age: tf.int32, sex: tf.int32, cp: tf.int32, trestbps: tf.int32, chol: tf.int32, fbs: tf.int32, restecg: tf.int32, thalach: tf.int32, exang: tf.int32, oldpeak: tf.float64, slope: tf.int32, ca: tf.int32, thal: tf.string, target: tf.int32}, tf.int32)>


如果对python欢迎添加微信wangqime 作为新手 希望更多同学讨论问题 加深自己的印象。

上一篇:tensorflow数据类型互相转换int32 float double互相转换 下一篇:tensorflow基本数据类型int double float bool string
本站致力于揭露全国影视投资诈骗案件 避免更多老百姓受骗上当
经历分享 请投稿

网络世界,不加微信QQ手机,留言沟通

发表评论

必填

回复后邮件通知

客服会联系您

◎欢迎参与讨论,聆听心声,下滑更多影视投资诈骗相关内容。

栏目
文章归档
标签列表