sam*_*and 7 python numpy matplotlib linear-regression
在Python中绘制单个变量函数非常简单matplotlib.但我正在尝试在散点图中添加第三个轴,以便我可以看到我的多变量模型.
这是一个示例代码段,有30个输出:
import numpy as np
np.random.seed(2)
## generate a random data set
x = np.random.randn(30, 2)
x[:, 1] = x[:, 1] * 100
y = 11*x[:,0] + 3.4*x[:,1] - 4 + np.random.randn(30) ##the model
Run Code Online (Sandbox Code Playgroud)
如果这只是一个单一的变量模型,我可能会使用这样的东西来生成最佳拟合的图和线:
%pylab inline
import matplotlib.pyplot as pl
pl.scatter(x_train, y_train)
pl.plot(x_train, ols.predict(x_train))
pl.xlabel('x')
pl.ylabel('y')
Run Code Online (Sandbox Code Playgroud)
多变量可视化的等价物是什么?
最常见的方法是改变散射符号的颜色和/或大小.例如:
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(2)
## generate a random data set
x, y = np.random.randn(2, 30)
y *= 100
z = 11*x + 3.4*y - 4 + np.random.randn(30) ##the model
fig, ax = plt.subplots()
scat = ax.scatter(x, y, c=z, s=200, marker='o')
fig.colorbar(scat)
plt.show()
Run Code Online (Sandbox Code Playgroud)

| 归档时间: |
|
| 查看次数: |
13507 次 |
| 最近记录: |