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

如何使用matplotlib绘制非线性模型?,matplotlib,machine-learning,scikit-learn,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 f

对于如何实现这一目标,我有点不知所措。通常,对于线性模型,当我执行线性回归时,我只需获取训练数据(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变量包含my 3功能,my train_y包含输出数据。我使用SFrame来包含数据。SFrame能够将自身转换为数据帧(在熊猫中使用)。使用转换,我能够获取值

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

这本质上是否意味着你的函数有3个自变量而不是1个?如果是这样,那真的很难想象。我现在明白你的意思了。我想我的目标是将我的特征转化为3次多项式,然后绘制它。我找到了一些关于SKI的文档,了解多项式特性。我还在研究如何使用它@Andras文档的问题在于,尽管看起来示例是使用matplotlib绘制的,但从未显示文档作者是如何做到这一点的。我的问题其实很幼稚;我没有机器学习和非线性规划的经验。@AndrasDeak,我想我很困惑。当你提到3个自变量时,我立即开始四处搜索,找到了一个,我立即开始认为我在画一个类似于我所发现的东西。谢谢你的澄清。