5

I try to Fit Multiple Linear Regression Model

Y= c + a1.X1 + a2.X2 + a3.X3 + a4.X4 +a5X5 +a6X6

Had my model had only 3 variable I would have used 3D plot to plot. How can I plot this . I basically want to see how the best fit line looks like or should I plot multiple scatter plot and see the effect of individual variable Y = a1X1 when all others are zero and see the best fit line. What is the best approach for these models. I know it is not possible to visualize higher dimensions want to know what should be the best approach. I am desperate to see the best fit line

9
  • Try using tsne, a technique for dimensionality reduction that is particularly well suited for the visualization of high-dimensional datasets Commented Sep 19, 2018 at 11:35
  • 1
    I did that and also used PCA thank you Commented Sep 19, 2018 at 12:35
  • 1
    @nithin that blog post recommends using "univariate and bivariate inspections of your data" to determine if you should use polynomial terms -- did you try that? Commented Sep 19, 2018 at 14:34
  • 1
    @duhaime brings up a good point. I personally have observed that - sometimes - visual inspections of the scatterplots of "Y" vs. each "X" has given some insight into the problem. Because they are so easy and quick to both make and inspect, this is worth trying. Commented Sep 20, 2018 at 15:07
  • 1
    Agreed I did some visualisation will put that Commented Sep 20, 2018 at 15:09

3 Answers 3

4

I found this post which is more helpful and followed
https://stats.stackexchange.com/questions/73320/how-to-visualize-a-fitted-multiple-regression-model. Based on suggestions I am currently just plotting scatter plots like dependent variable vs. 1st independent variable, then vs. 2nd independent variable etc I am doing same thing . I may not be able to see best fit line for complete model but I know how it is dependent on individual variable

from sklearn.linear_model import LinearRegression
train_copy = train[['OverallQual', 'AllSF','GrLivArea','GarageCars']]
train_copy =pd.get_dummies(train_copy)
train_copy=train_copy.fillna(0)
linear_regr_test = LinearRegression()

fig, axes = plt.subplots(1,len(train_copy.columns.values),sharey=True,constrained_layout=True,figsize=(30,15))

for i,e in enumerate(train_copy.columns):
  linear_regr_test.fit(train_copy[e].values[:,np.newaxis], y.values)
  axes[i].set_title("Best fit line")
  axes[i].set_xlabel(str(e))
  axes[i].set_ylabel('SalePrice')
  axes[i].scatter(train_copy[e].values[:,np.newaxis], y,color='g')
  axes[i].plot(train_copy[e].values[:,np.newaxis], 
  linear_regr_test.predict(train_copy[e].values[:,np.newaxis]),color='k')
Sign up to request clarification or add additional context in comments.

Comments

2

You can use Seaborn's regplot function, and use the predicted and actual data for comparison. It is not the same as plotting a best fit line, but it shows you how well the model works.

sns.regplot(x=y_test, y=y_predict, ci=None, color="b")

Comments

-1

You could try to visualize how well your model is performing by comparing actual and predicted values. Assuming that our actual values are stored in Y, and the predicted ones in Y_, we could plot and compare both.

import seaborn as sns

ax1 = sns.distplot(Y, hist=False, color="r", label="Actual Value")
sns.distplot(Y_, hist=False, color="b", label="Fitted Values" , ax=ax1)

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.