LMyers
LMyers

Reputation: 13

Linear Regression from a .csv file in matplotlib

Can someone explain how to make a scatter plot and linear regression from an excel file?

I know how to import the the file with pandas, I know how to do a scatter plot by plugging in my own data in matplotlib, but I don't know how to make python do all three from the file.

Ideally it would also give r value, p value, std error, slope and intercept.

I'm very new to all of this and any help would be great.

I've searched around stack overflow, reddit, and else where, but I haven't found anything recent.

Upvotes: 1

Views: 1348

Answers (1)

RGMyr
RGMyr

Reputation: 301

SciPy has a basic linear regression function that fits your criteria: scipy.stats.linregress Just use the appropriate columns from your DataFrame as x and y.

Pyplot's basic plt.plot(x, y) function will give you a line: matplotlib.pyplot.plot. You can compute a set of y values using the slope and intercept.

Upvotes: 1

Related Questions