plot_trisurf的参数错误:Error in qhull Delaunay triangulation calculation: singular input data (exitcode=2); use python verbose option (-v) to see original qhull error.
感觉参数没有重复,依然报错???
```python
import numpy as np
import matplotlib.pyplot as plt
x_data = [1.0, 2.0, 3.0]
y_data = [2.0, 4.0, 6.0]
# 模型函数
def forward(x):
return x * w + b
# 损失函数
def loss(x, y):
y_pred = forward(x)
return (y_pred - y) * (y_pred - y)
# 模型
w_list = []
b_list = []
cost_list = []
i = 0
for w in np.arange(0.0, 4.1, 1):
print("w=", w)
l_sum = 0
cost_list.append([])
for b in np.arange(-2.0, 2.1, 1):
for x_val, y_val in zip(x_data, y_data):
y_pred_val = forward(x_val) + b
loss_val = loss(x_val, y_val)
l_sum += loss_val
cost_list[i].append(l_sum / 3)
i = i+1
w_list.append(w)
b_list = list(np.linspace(-2, 2.1, 5, endpoint=True)) # 函数接受3个参数,前两个参数是开始和结束的数值,第三个参数是要生成的数字的数量。
for i, j in zip(w_list, b_list):
print(i, j)
print(cost_list)
fig = plt.figure(figsize=(12, 8), facecolor='white')
ax = fig.add_subplot(111, projection='3d')
ax.plot_trisurf(w_list, b_list, cost_list, cmap="rainbow") # 三角剖分,x,y,z的长度都是n的平方
plt.show()
```