Python代价函数机器学习

Python代价函数机器学习,python,numpy,machine-learning,Python,Numpy,Machine Learning,我在做波士顿价格预测项目。问题是,当我试图计算成本函数时,我收到一个错误: Data must be 1-dimensional 代码: 错误 ile "C:\Users\Alberto\Desktop\Oscar\UNIVERSIDAD\TFG\PROYECTOS\PRECIO CASAS BOSTON\prediction.py", line 129, in <module> predictor.linear_regression_model(X_t

我在做波士顿价格预测项目。问题是,当我试图计算
成本函数时,我收到一个错误:

Data must be 1-dimensional
代码:

错误

ile "C:\Users\Alberto\Desktop\Oscar\UNIVERSIDAD\TFG\PROYECTOS\PRECIO CASAS BOSTON\prediction.py", line 129, in <module>
    predictor.linear_regression_model(X_train, Y_train, 10000)

  File "C:\Users\Alberto\Desktop\Oscar\UNIVERSIDAD\TFG\PROYECTOS\PRECIO CASAS BOSTON\prediction.py", line 110, in linear_regression_model
    cost_train = self.cost_function(Z_train, Y_train)

  File "C:\Users\Alberto\Desktop\Oscar\UNIVERSIDAD\TFG\PROYECTOS\PRECIO CASAS BOSTON\prediction.py", line 87, in cost_function
    J = (1/455)*np.sum(np.square(Z_train - Y_train))

  File "C:\Users\Alberto\anaconda3\lib\site-packages\pandas\core\series.py", line 635, in __array_ufunc__
    result = ops.maybe_dispatch_ufunc_to_dunder_op(

  File "pandas\_libs\ops_dispatch.pyx", line 91, in pandas._libs.ops_dispatch.maybe_dispatch_ufunc_to_dunder_op

  File "C:\Users\Alberto\anaconda3\lib\site-packages\pandas\core\ops\common.py", line 64, in new_method
    return method(self, other)

  File "C:\Users\Alberto\anaconda3\lib\site-packages\pandas\core\ops\__init__.py", line 505, in wrapper
    return _construct_result(left, result, index=left.index, name=res_name)

  File "C:\Users\Alberto\anaconda3\lib\site-packages\pandas\core\ops\__init__.py", line 478, in _construct_result
    out = left._constructor(result, index=index)

  File "C:\Users\Alberto\anaconda3\lib\site-packages\pandas\core\series.py", line 305, in __init__
    data = sanitize_array(data, index, dtype, copy, raise_cast_failure=True)

  File "C:\Users\Alberto\anaconda3\lib\site-packages\pandas\core\construction.py", line 482, in sanitize_array
    raise Exception("Data must be 1-dimensional")

**Exception: Data must be 1-dimensional)**
ile“C:\Users\Alberto\Desktop\Oscar\UNIVERSIDAD\TFG\PROYECTOS\PRECIO CASAS BOSTON\prediction.py”,第129行,在
预测因子。线性回归模型(X序列,Y序列,10000)
文件“C:\Users\Alberto\Desktop\Oscar\UNIVERSIDAD\TFG\PROYECTOS\PRECIO CASAS BOSTON\prediction.py”,第110行,在线性回归模型中
成本列车=自身成本列车功能(Z列车、Y列车)
文件“C:\Users\Alberto\Desktop\Oscar\UNIVERSIDAD\TFG\PROYECTOS\PRECIO CASAS BOSTON\prediction.py”,第87行,成本函数
J=(1/455)*np.和(np.平方(Z_列-Y_列))
文件“C:\Users\Alberto\anaconda3\lib\site packages\pandas\core\series.py”,第635行,在数组中__
结果=运行。可能将运行调度到运行(
文件“pandas\\ libs\ops\u dispatch.pyx”,第91行,在pandas.libs.ops\u dispatch.maybe\u dispatch\u ufunc\u to\u dunder\u op
文件“C:\Users\Alberto\anaconda3\lib\site packages\pandas\core\ops\common.py”,第64行,采用新方法
返回方法(自身、其他)
文件“C:\Users\Alberto\anaconda3\lib\site packages\pandas\core\ops\\uuuuu init\uuuuu.py”,第505行,在包装器中
return _construct_result(左,result,index=left.index,name=res_name)
文件“C:\Users\Alberto\anaconda3\lib\site packages\pandas\core\ops\\uuuu init\uuuuu.py”,第478行,位于“构造”结果中
out=左。\构造函数(结果,索引=索引)
文件“C:\Users\Alberto\anaconda3\lib\site packages\pandas\core\series.py”,第305行,在\uuu init中__
数据=清理数组(数据、索引、数据类型、复制、引发\u转换\u失败=真)
文件“C:\Users\Alberto\anaconda3\lib\site packages\pandas\core\construction.py”,第482行,在sanitize\u数组中
引发异常(“数据必须是一维的”)
**例外情况:数据必须是一维的)**

请将错误格式化为code@MadPhysicist请不要将错误格式化为code@MadPhysicist多恩
ile "C:\Users\Alberto\Desktop\Oscar\UNIVERSIDAD\TFG\PROYECTOS\PRECIO CASAS BOSTON\prediction.py", line 129, in <module>
    predictor.linear_regression_model(X_train, Y_train, 10000)

  File "C:\Users\Alberto\Desktop\Oscar\UNIVERSIDAD\TFG\PROYECTOS\PRECIO CASAS BOSTON\prediction.py", line 110, in linear_regression_model
    cost_train = self.cost_function(Z_train, Y_train)

  File "C:\Users\Alberto\Desktop\Oscar\UNIVERSIDAD\TFG\PROYECTOS\PRECIO CASAS BOSTON\prediction.py", line 87, in cost_function
    J = (1/455)*np.sum(np.square(Z_train - Y_train))

  File "C:\Users\Alberto\anaconda3\lib\site-packages\pandas\core\series.py", line 635, in __array_ufunc__
    result = ops.maybe_dispatch_ufunc_to_dunder_op(

  File "pandas\_libs\ops_dispatch.pyx", line 91, in pandas._libs.ops_dispatch.maybe_dispatch_ufunc_to_dunder_op

  File "C:\Users\Alberto\anaconda3\lib\site-packages\pandas\core\ops\common.py", line 64, in new_method
    return method(self, other)

  File "C:\Users\Alberto\anaconda3\lib\site-packages\pandas\core\ops\__init__.py", line 505, in wrapper
    return _construct_result(left, result, index=left.index, name=res_name)

  File "C:\Users\Alberto\anaconda3\lib\site-packages\pandas\core\ops\__init__.py", line 478, in _construct_result
    out = left._constructor(result, index=index)

  File "C:\Users\Alberto\anaconda3\lib\site-packages\pandas\core\series.py", line 305, in __init__
    data = sanitize_array(data, index, dtype, copy, raise_cast_failure=True)

  File "C:\Users\Alberto\anaconda3\lib\site-packages\pandas\core\construction.py", line 482, in sanitize_array
    raise Exception("Data must be 1-dimensional")

**Exception: Data must be 1-dimensional)**