2

I'm a bit lost as to how to proceed to achieve this. Normally with a linear model, when I perform linear regressions, I simply take my training data (x) and and my output data (y) and plot them using matplotlib. Now I have 3 features with and my output/observation (y). Can anyone guide me as to how to graph this kind of model using matplotlib? My goal is to fit a polynomial model and graph a polynomial using 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

Note:

The train_x variable contains my 3 features, and my train_y contains the output data. I use SFrame to contain the data. SFrame has the ability to convert itself into a dataframe (used in Pandas). Using the conversion I am able to grab the values.

7
  • Does this essentially mean that your function has 3 independent variables instead of one? If so, that's indeed hard to visualize. Commented Jun 28, 2016 at 21:41
  • I see what you mean now. I think I was aiming towards turning my features into a polynomial of degree 3 and then plotting that. I found some documentation on sklearn about Polynomial features. I'm still investigating how to use it. stats.stackexchange.com/questions/58739/… Commented Jun 28, 2016 at 22:05
  • @Andras The problem with the documentation is that, although it looks like the examples are plotted using matplotlib, an example is never shown of how the author of the documentation did that. scikit-learn.org/stable/modules/… Commented Jun 28, 2016 at 22:08
  • My question was actually a pretty naive one; I have no experience with machine learning and nonlinear programming. Commented Jun 28, 2016 at 22:20
  • @AndrasDeak I guess I was pretty confused. When you mentioned 3 independent variables I immediately began search around and found a Matlab graph plotting thread about that and I immediately began to think I was plotting a something like what I had found. Thanks for the clarification. Commented Jun 28, 2016 at 22:24

1 Answer 1

1

Rather than plotting a non-linear model with multiple discrete features at once, I have found that simply observing each and every feature against my observation/output was better and easier for my research.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.