:::| 目前位置圖示目前位置:首頁圖示回首頁 | 主功能頁圖示相關問答
常用指令參數筆記-更改資料的內容

[日期]:2018/04/12  [瀏覽人數]:250

將對應的數字改為另一個索引值,如將1改為0,2-->1,3-->2,5-->3,6-->4,7-->5

type_map = {1:0,2:1,3:2,5:3,6:4,7:5}
df["Type"] = df["Type"].map(type_map)

取第一欄至第9欄當特徵值

features = df.columns[:9]

分割資料

from sklearn.model_selection import train_test_split

x=df[feature] #將轉入的資料表分出所有特徵值欄位資料

y=df['Type'] #將label欄位的資料轉為y

x_train,x_test,y_train_label,y_test_label=train_test_split(x,y,test_size=0.2,random_state=10)