首页 > 解决方案 > 线性回归 (python) - 使用多个特征的错误

问题描述

对 ML 和 python 来说很新,所以这可能是一个基本问题,但希望有人能给我指导。

拥有一个天气数据集,并希望开发一个模型来根据集合中的其他特征(表观温度、湿度、能见度等)预测温度。

我有一个使用 1 个功能的模型,它似乎运行良好:

predictors1 = train[['apparent_temperature']]
response = train['temperature']

lr1 = LinearRegression(normalize=True)
lr1.fit(predictors1, response)
y_pred = lr1.predict(response)

当我使用超过 1 个功能制作另一个模型时,出现错误:

predictors2 = train[['apparent_temperature', 'humidity', 'visibility']]
response = train['temperature']

lr2 = LinearRegression(normalize=True)
lr2.fit(predictors2, response)
y_pred2 = lr2.predict(response)

我得到的错误信息是:

ValueError: matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)->(n?,m?) (size 3 is different from 1)

不确定我是否正确阅读,但这看起来像矩阵乘法问题 - 关于我做错了什么的任何想法,或者如何扩展模型以包含多个功能?

标签: pythonlinear-regression

解决方案


推荐阅读