将列表划分为命名子阵列
测试列车的拆分阵列
本质上,我试图将PANDAS DataFrame转换为Numpy阵列,以便我可以通过测试/火车运行它。
我的目的是将列分为用于运行测试训练的因变量和独立变量的组。
我能够将数据框架转换为有效的列表阵列,从而
x = df.values
为我提供了每个行中每个值的列表的列表。
如果我要在此数组上使用np.split()尝试分组,则只会将某些行分组在一起,而不是按列值分组。
我打算做的最简单的例子(使用已经具有的IRIS数据集而不是我的插图)看起来像这样:
X_train, X_test, y_train, y_test = train_test_split(iris.data, iris.target, test_size=0.2, random_state=0)
数据和目标是数据集IRIS的子阵列。我如何将我的一个列表数列为列表的多个列出的子阵列?
Splitting Arrays for Test Train
Essentially I am attempting to convert a pandas dataframe into numpy arrays so that I can run it through a Test/Train.
My goal here is to split the columns into groups of dependent and independent variables on which to run the test-train.
I am able to convert the dataframe into an array of lists with
x = df.values
This effectively gives me a list of a list of every value in every row.
If I were to use np.split() on this array to try to divide into groups, it would only group certain rows together, and not split by the column values.
The simplest example of what I aim to do (Using the already sectored iris dataset as opposed to mine) looks like this:
X_train, X_test, y_train, y_test = train_test_split(iris.data, iris.target, test_size=0.2, random_state=0)
with data and target being sub-arrays of the dataset iris. How can I turn my one array of lists, into multiple named sub-arrays of lists?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终将其保留为大熊猫的数据框架,JSUT将列分解为两个独立的新数据框架,
我过度复杂化了。谢谢大家的帮助
I ended up keeping it as a pandas data frame and jsut broke up the columns into two separate new data frames
I was overcomplicating things. Thank you everyone for your help