matplotlib - 如何使用 matplotlib 绘制非线性模型?

标签 matplotlib machine-learning scikit-learn

我对如何继续实现这一目标有点迷失。通常,对于线性模型,当我执行线性回归时,我只需获取训练数据 (x) 和输出数据 (y) 并使用 matplotlib 绘制它们。现在我有 3 个特征和我的输出/观察结果 (y)。谁能指导我如何使用 matplotlib 绘制此类模型的图形?我的目标是拟合多项式模型并使用 matplotlib 绘制多项式图表。

%matplotlib inline
import sframe as frame
import matplotlib.pyplot as plt
import numpy as np
from sklearn import datasets, linear_model

# Initalize SFrame
sales = frame.SFrame('kc_house_data.gl/')

# Separate data into test and training data 
train_data,test_data = sales.random_split(.8,seed=0)

# Organize data into training and testing data 

train_x = train_data[['sqft_living', 'bedrooms', 'bathrooms']].to_dataframe().values
train_y = train_data[['price']].to_dataframe().values
test_x = test_data[['sqft_living', 'bedrooms', 'bathrooms']].to_dataframe().values
test_y = test_data[['price']].to_dataframe().values


# Create a model using sklearn with multiple features
regr = linear_model.LinearRegression(fit_intercept=True, n_jobs=2)

# test predictions
regr.predict(train_x)

# Prepare to plot the data

注意:

train_x 变量包含我的 3 个特征,train_y 包含输出数据。我使用 SFrame 来包含数据。 SFrame 能够将自身转换为数据帧(在 Pandas 中使用)。使用转换我能够获取这些值。

最佳答案

我发现,相对于我的观察/输出简单地观察每个特征,而不是一次性绘制具有多个离散特征的非线性模型,对我的研究来说更好、更容易。

关于matplotlib - 如何使用 matplotlib 绘制非线性模型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38086751/

相关文章:

python - Tensorflow DNNClassifier 返回错误的预测

python - 橙色在Python脚本中保存模型

python - 导入整个 python 模块不允许使用子模块

python - 分类器超参数之间的相关性

matplotlib - 如何在没有@PLT的情况下在汇编中正常调用 printf ,而只需在带有标准库的 gcc 中使用 -l 选项调用 printf ,

python - 灵活地向图形添加子图以及向图形添加一个颜色条

tensorflow - tf.Dataset.from_tensor_slices性能问题

python - Matplotlib 创建实时动画图

python - Matplotlib:取消matplotlib 2.0引入的坐标轴偏移

machine-learning - 如何最好地处理与哪种类型的专家标记了在分类时不可用的数据相关的特征?