plot_linear_regression
plot_linear_regression(X, y, model=LinearRegression(copy_X=True, fit_intercept=True, n_jobs=None, normalize=False), corr_func='pearsonr', scattercolor='blue', fit_style='k--', legend=True, xlim='auto')
Plot a linear regression line fit.
Parameters
-
X
: numpy array, shape = [n_samples,]Samples.
-
y
: numpy array, shape (n_samples,)Target values model: object (default: sklearn.linear_model.LinearRegression) Estimator object for regression. Must implement a .fit() and .predict() method. corr_func: str or function (default: 'pearsonr') Uses
pearsonr
from scipy.stats if corr_func='pearsonr'. to compute the regression slope. If not 'pearsonr', thecorr_func
, thecorr_func
parameter expects a function of the form func(, ) as inputs, which is expected to return a tuple (<correlation_coefficient>, <some_unused_value>)
. scattercolor: string (default: blue) Color of scatter plot points. fit_style: string (default: k--) Style for the line fit. legend: bool (default: True) Plots legend with corr_coeff coef., fit coef., and intercept values. xlim: array-like (x_min, x_max) or 'auto' (default: 'auto') X-axis limits for the linear line fit.
Returns
-
regression_fit
: tupleintercept, slope, corr_coeff (float, float, float)
Examples
For usage examples, please see http://rasbt.github.io/mlxtend/user_guide/plotting/plot_linear_regression/