决策树模型如何解决标签数量与样本数量不匹配的问题?

问题描述 投票:0回答:1

   x=weekly_exposure.drop(columns =['Classifcation']) #inputs
   y= weekly_exposure['Classifcation'] #outputs
   y = np.array(y)
   y = y.reshape(-1, 1)
   x.ndim,x.shape
   y.ndim,y.shape
   x_train, x_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
   model = DecisionTreeClassifier()
   model.fit(X_train, y_train)type here

大家好, 我正在尝试构建一个决策树,根据 8 个变量和 42 行将运动员分类为“受伤”或“未受伤”。 我改变了 x 和 y 的形状,因此它们都是二维的。 但是,当我尝试运行模型时,出现错误“发现样本数量不一致的输入变量:[336, 42]” 我不确定如何使我当前的标签 42 等于我的每个数据点 332。 欢迎所有想法谢谢。

python machine-learning multidimensional-array jupyter-notebook decision-tree
1个回答
0
投票

model.fit(X_train, y_train)

您输入了大写 x 而不是小写,正如您在上面进行拆分时所定义的那样。

© www.soinside.com 2019 - 2024. All rights reserved.