赞
踩
目录
1.4.2数据展示 ,含有多个特征,划分为三类0,1,2编辑
n_samples为数据数目
import mglearn X,y=mglearn.datasets.make_wave(n_samples=10) print(X,y)
from sklearn.datasets import load_iris iris=load_iris() x=iris.data y=iris.target feature=iris.feature_names print(x,'\n',y,'\n',feature)
import numpy as np import pandas as pd data_url = "http://lib.stat.cmu.edu/datasets/boston" raw_df = pd.read_csv(data_url, sep=r"\s+", skiprows=22, header=None) data = np.hstack([raw_df.values[::2, :], raw_df.values[1::2, :2]]) target = raw_df.values[1::2, 2] print(data,'\n',target)
from sklearn.datasets import load_wine wine=load_wine() wine_data=wine.data wine_target=wine.target wine_feature=wine.feature_names print(wine_data,wine_target,wine_feature)
from sklearn.datasets import make_blobs #n_samples为数据数目,n_features=数据特征数目,centers数据类别,random_state随机种子控制随机过程 x,y = make_blobs(n_samples= 10,n_features= 2, centers= 4, random_state= 1) print(x,'\n',y)
from sklearn.model_selection import train_test_split x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.2,random_state=20)
在train_test_split函数内
其中x,y,分别为我们导入的数据的特征和数值(类别)
test_size=0.2,表示x_test,和y_test,测试数据占比0.2
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。