Traceback (most recent call last):
File "D:\35433\Documents\机器学习\任务1\任务1.py", line 17, in <module>
(theta,cost_history) = linear_regression.train(learning_rate,num_iterations)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\35433\Documents\机器学习\任务1\梯度下降类.py", line 11, in train
cost_history = self.gradient_descent(alpha,num_iterations)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\35433\Documents\机器学习\任务1\梯度下降类.py", line 18, in gradient_descent
self.gradient_step(alpha)#每次都走一步,更新一次theta(w,参数列)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\35433\Documents\机器学习\任务1\梯度下降类.py", line 26, in gradient_step
t = prediction - self.labels#设置了一个临时变量,预测值-真实值
~~~~~~~~~~~^~~~~~~~~~~~~
File "D:\python\Lib\site-packages\pandas\core\generic.py", line 2171, in __array_ufunc__
return arraylike.array_ufunc(self, ufunc, method, *inputs, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\python\Lib\site-packages\pandas\core\arraylike.py", line 276, in array_ufunc
result = maybe_dispatch_ufunc_to_dunder_op(self, ufunc, method, *inputs, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "ops_dispatch.pyx", line 113, in pandas._libs.ops_dispatch.maybe_dispatch_ufunc_to_dunder_op
File "D:\python\Lib\site-packages\pandas\core\ops\common.py", line 76, in new_method
return method(self, other)
^^^^^^^^^^^^^^^^^^^
File "D:\python\Lib\site-packages\pandas\core\arraylike.py", line 198, in __rsub__
return self._arith_method(other, roperator.rsub)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\python\Lib\site-packages\pandas\core\series.py", line 6135, in _arith_method
return base.IndexOpsMixin._arith_method(self, other, op)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\python\Lib\site-packages\pandas\core\base.py", line 1384, in _arith_method
return self._construct_result(result, name=res_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\python\Lib\site-packages\pandas\core\series.py", line 6231, in _construct_result
out = self._constructor(result, index=self.index, dtype=dtype, copy=False)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\python\Lib\site-packages\pandas\core\series.py", line 584, in __init__
data = sanitize_array(data, index, dtype, copy)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\python\Lib\site-packages\pandas\core\construction.py", line 659, in sanitize_array
subarr = _sanitize_ndim(subarr, data, dtype, index, allow_2d=allow_2d)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\python\Lib\site-packages\pandas\core\construction.py", line 718, in _sanitize_ndim
raise ValueError(
ValueError: Data must be 1-dimensional, got ndarray of shape (150, 150) instead
最新发布