此代码正在运行 a 已恢复到它正在运行但现在无法运行的状态。有人可以帮助解决错误吗
import pandas as pd
import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt
sns.set_theme(style="whitegrid")
iris = sns.load_dataset("iris")
dataset1 = iris
from scipy.stats import linregress
x = np.linspace(0,7,8)
y = a*x + b
plt.plot(x, y, 'r', label='Y = aX + b')
x = dataset1['petal_length'].to_numpy(dtype = float)
y = dataset1['sepal_length'].to_numpy(dtype = float)
a, b, r ,p, stderr = linregress(x,y)
print("\na: {:.4f}".format(a))
print("\nb: {:.4f}".format(b))
print("\nR Sqaured: {:.4f}".format(r**2))
sns.scatterplot(data=dataset1, x = 'petal_length', y = 'sepal_length')
plt.show()
收到错误
ValueError Traceback (most recent call last)
<ipython-input-185-aa2ea9694f18> in <module>
2
3 x = np.linspace(0,7,8)
----> 4 y = a*x + b
5 plt.plot(x, y, 'r', label='Y = aX + b')
6
ValueError: operands could not be broadcast together with shapes (3,4) (8,)
新错误一个 seaborn 被卸载并重新安装
NameError Traceback (most recent call last)
<ipython-input-27-0c657297db5a> in <module>
2
3 x = np.linspace(8,7,8)
----> 4 y = a*x + b (1)
5 plt.plot(x, y, 'r', label='Y = aX + b')
6
NameError: name 'a' is not defined