本文共 2138 字,大约阅读时间需要 7 分钟。
from sklearn.datasets import load_iris,load_boston,fetch_20newsgroups# 1,分类数据集# lr = load_iris()# print("特征值",lr.data)# print("目标值",lr.target)# print(lr.feature_names)# print(lr.target_names)# print(lr.DESCR)# 2,回归数据集# lb = load_boston()# print("特征值",lb.data)# print("目标值",lb.target)# print(lb.feature_names)# 3,数据量比较大的数据集# subset: 'train'或者'test','all',可选,选择要加载的数据集.训练集的“训练”,# 测试集的“测试”,两者的“全部”news = fetch_20newsgroups(subset='all')print("特征值",news.data)print("目标值",news.target)---------------------------------------------------------------Downloading 20news dataset. This may take a few minutes.Downloading dataset from https://ndownloader.figshare.com/files/5975967 (14 MB)
机器学习一般的数据集会划分为两个部分:
划分比例:
from sklearn.datasets import load_iris,load_boston,fetch_20newsgroupsfrom sklearn.model_selection import train_test_split# 1,分类数据集lr = load_iris()# print("特征值",lr.data)# print("目标值",lr.target)# print(lr.feature_names)# print(lr.target_names)# print(lr.DESCR)# 2,回归数据集# lb = load_boston()# print("特征值",lb.data)# print("目标值",lb.target)# print(lb.feature_names)# 3,数据量比较大的数据集# news = fetch_20newsgroups(subset='all')# print("特征值",news.data)# print("目标值",news.target)# 4,进行数据集的训练集和测试集划分# 返回值有4个部分接受# x,y特征值、目标值,train、test训练集和测试集# x_train,x_test,y_train,y_testx_train,x_test,y_train,y_test = train_test_split(lr.data,lr.target,test_size=0.3)print("训练集的特征值和目标值:",x_train,y_train)print("测试机的特征值和目标值:",x_test,y_test)
转载地址:http://osili.baihongyu.com/