1. 程式人生 > 其它 >深度學習之資料劃分

深度學習之資料劃分

技術標籤:Python

使用步驟

1.匯入相關包:
from sklearn.datasets import load_iris
from sklearn.datasets import fetch_20newsgroups
from sklearn.model_selection import train_test_split
2.例項化物件:li = load_iris() 返回一個字典格式的資料
3.#獲取特徵值 , 也就是資料: print(li.data) #因為是字典也可以li[‘data’]
4. #獲取目標值:print(li.target)
5. 獲取描述資訊: print(li.DESCR)

結果

1.資料輸出
在這裡插入圖片描述
2.目標輸出
在這裡插入圖片描述
其中0 1 2 分別代表花的類別
3.獲取描述資訊

在這裡插入圖片描述
這裡選擇幾個比較常用的加以說明:
Attribute Information:表示資料的列索引
class:表示類別,這裡有三類,分別對應於目標輸出中的0 1 2 三類

進行資料劃分


```python
  #必須這樣排列
    x_train,x_test,y_train,y_test = train_test_split(li.data,li.target,test_size=0.25)
    #li.data,表示總資料,也及要劃分的資料集
    #li.target,表示資料集的目標值
    #test_size = 0.25,表示測試集的大小,範圍0-1
#注意這裡進行劃分是隨機抽取 print("訓練集特徵值和目標值:",x_train,y_train) print("測試集特徵值和目標值:",x_test,y_test)
![在這裡插入圖片描述](https://img-blog.csdnimg.cn/20210123093453348.png)
![在這裡插入圖片描述](https://img-blog.csdnimg.cn/20210123093515876.png)