逻辑回归绘制具有相同颜色的连续曲线

问题描述 投票:0回答:1
x = np.array([0,1,2,3,4,5])
y = np.array([[0,10],[5,10],[8,10],[10,10],[10,11],[10,11]])

color = [[1,0,0],
         [0,1,0],
         [1,0,0],
         [0,1,0],
         [1,0,0],
         [0,1,0],
         [1,0,0],
         [0,1,0],
         [0,1,0],
         [1,0,0],
         [0,1,0],
         [1,0,0]]
plt.figure(figsize=(2,4))
plt.plot(x, y, lw=0.4, marker = '.', markersize=0)
plt.scatter(np.repeat(x, y.shape[1]), y, s=8, c=np.abs(color))

如何使用逻辑回归将绿点与绿点、红点与红点连接起来,得到连续的曲线?

python matplotlib logic logistic-regression
1个回答
0
投票

我对你的代码做了一些修改,它起作用了 图表截图

import numpy as np
import matplotlib.pyplot as plt

x = np.array([0, 1, 2, 3, 4, 5])
y = np.array([[0, 10], [5, 10], [8, 10], [10, 10], [10, 11], [10, 11]])

color = [[1, 0, 0],
         [0, 1, 0],
         [1, 0, 0],
         [0, 1, 0],
         [1, 0, 0],
         [0, 1, 0]]
red_indices = np.where(np.array(color) == [1, 0, 0])
green_indices = np.where(np.array(color) == [0, 1, 0])

red_x = x[red_indices[0]]
red_y = y[red_indices[0]][:, 1]
green_x = x[green_indices[0]]
green_y = y[green_indices[0]][:, 1]
plt.figure(figsize=(8, 4))
plt.plot(red_x, red_y, color='red', lw=2, label='Red Curve')
plt.plot(green_x, green_y, color='green', lw=2, label='Green Curve')
plt.scatter(x, y[:, 1], s=50, c=color)

plt.legend()
plt.grid(True)
plt.show()
© www.soinside.com 2019 - 2024. All rights reserved.