Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment 10 - plt.plot not fitting line to data properly #868

Open
drbigshog opened this issue Nov 18, 2024 · 1 comment
Open

Assignment 10 - plt.plot not fitting line to data properly #868

drbigshog opened this issue Nov 18, 2024 · 1 comment

Comments

@drbigshog
Copy link

drbigshog commented Nov 18, 2024

Hi,
I am running into an issue for Task 2 part b and c where the line I am fitting to the dependent variable is not functioning properly.

Here is my code, and here is a screenshot of the result. The scatter plot appears fine, but the line isn't working as it did in part a).

This happens in both questions but here is part b):

formula_2 = 'co2_per_capita ~ income'
res2 = smf.ols(formula=formula_2, data=world_data_2014).fit()

sns.scatterplot(x='income', y='co2_per_capita', data=world_data_2014)
plt.plot(world_data_2014.income,results.fittedvalues)

I looked online, and some sites suggested sorting the data, but I'm curious why this code doesn't work as expected. Thanks!

image
@drbigshog
Copy link
Author

Solved it, should have res2 and res3.fittedvalues instead of resultds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant