Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
float和int的python未移植操作数数据类型_Python_Linear Regression - Fatal编程技术网

float和int的python未移植操作数数据类型

float和int的python未移植操作数数据类型,python,linear-regression,Python,Linear Regression,嘿,我试图用梯度下降法做线性回归,我一直面临这个错误 TypeError: unsupported operand type(s) for &: 'float' and 'int' 代码如下 b = 0 a = 0 L = 0.0001 epochs = 10000 n = len(X) n = 1 epsilon = 0.0001 # Stop algorithm when absolute difference between 2 consecutive x-values is

嘿,我试图用梯度下降法做线性回归,我一直面临这个错误

TypeError: unsupported operand type(s) for &: 'float' and 'int'
代码如下

b = 0
a = 0
L = 0.0001
epochs = 10000
n = len(X)
n = 1
epsilon = 0.0001  # Stop algorithm when absolute difference between 2 consecutive x-values is less than epsilon
diff = 1
while diff > epsilon & n < epochs:  # 2 stopping criteria is set
    Y_pred = b*X + a
    cost = (1/n)*sum([val**2 for val in (Y-Y_pred)])
    D_b = (-2/n) * sum(X*(Y - Y_pred))
    D_a = (-2/n) * sum(Y - Y_pred)
    b = b - L*D_b
    a = a - L*D_a
    diff = abs(Y_pred -Y)
    j = j + 1
    y = Y_pred
    print('x')

print('The value of b is {},cost is {} and the value of a is {} when itstheminimum'.format(b,cost,a))
b=0
a=0
L=0.0001
纪元=10000
n=len(X)
n=1
ε=0.0001#当两个连续x值之间的绝对差小于ε时停止算法
差异=1
而diff>epsilon&n
错误在这行

while diff > epsilon & n < epochs:  # 2 stopping criteria is set
而diff>epsilon&n

任何建议或备选方案都将不胜感激

它返回错误,因为您使用
&
表示
逻辑运算符。在Python中,应使用
,如下所示:

while diff > epsilon and n < epochs:
而diff>ε和n
&
是按位和。使用
&&
进行逻辑AND。或者,如果你在
while(diff>epsilon)和(n
@Barmar你的意思是