微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我无法在 python 中拟合树的模型

如何解决我无法在 python 中拟合树的模型

晚上好!!!

我必须在回归森林和树分类器方面工作,但我在尝试适应我的系统时遇到了麻烦。

我使用的数据是具有多列的 .csv,我无法拟合具有一个或多个特征的模型。

我认为问题在于我没有正确的形状,因为我之前一直在“玩”这些功能。 这是 .csv (https://www.kaggle.com/gpandi007/usa-housing-dataset)

代码如下:

#Separar la data en entrenamiento y test
#X = USA_Housing.drop(['SalePrice','Street','LotShape','LandContour','Utilities',#'LotConfig','LandSlope','Neighborhood','Condition1','Condition2',#'BldgType','HouseStyle','RoofStyle','RoofMatl','Exterior1st',#'Exterior2nd','MasVnrType','ExterQual','ExterCond','Foundation',#'BsmtQual','BsmtCond','BsmtExposure','BsmtFinType1','BsmtFinType2',#'Heating','HeatingQC','CentralAir','Electrical','KitchenQual',#'Functional','GarageType','GarageFinish','GarageQual',#'GarageCond','PavedDrive','SaleType','SaleCondition'],axis= 1)
X = USA_Housing['OverallQual']
y = USA_Housing['SalePrice']
print(X,y)
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.2,random_state=101)
#Crear el árbol
modelo = DecisionTreeRegressor(max_depth = 5)

还有我说的错误

ValueError: Expected 2D array,got 1D array instead:
array=[6. 7. 6. ... 6. 7. 5.].
Reshape your data either using array.reshape(-1,1) if your data has a single feature or array.reshape(1,-1) if it contains a single sample.

你需要更多关于我以前做过的事情的信息吗? 谢谢

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。