nplist = data.T.to_numpy() data = nplist[0:-1].T self.data = np.float64(data) self.target = nplist[-1]
时间: 2024-05-19 13:13:10 浏览: 139
利用torch.utils.data.Dataset自定义数据加载类
3星 · 编辑精心推荐
This code snippet is converting a pandas dataframe to a numpy array and then separating the data and target values.
The first line converts the dataframe to a numpy array and transposes it (i.e., switches the rows and columns).
The second line selects all rows except the last one and transposes the resulting array back to its original shape. This corresponds to selecting all the features and leaving out the target variable.
The third line converts the resulting array to float64 data type.
The last line selects the last row of the original numpy array, which corresponds to the target variable. This is stored separately from the data as `self.target`.
阅读全文