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 作为新手 希望更多同学讨论问题 加深自己的印象。
网络世界,不加微信QQ手机,留言沟通
发表评论