# AUTOGENERATED! DO NOT EDIT! File to edit: ../../nbs/linalg/10_linalg_fitsvd.ipynb.

# %% auto 0
__all__ = ['fitline']

# %% ../../nbs/linalg/10_linalg_fitsvd.ipynb 11
import numpy as np

# %% ../../nbs/linalg/10_linalg_fitsvd.ipynb 12
def fitline(points): 
    
    # center the data points by subtracting the mean to 
    # remove the bias (intercept)
    avg = np.mean(points, axis=0)
    subtracted = points - avg
    
    _, _, V = np.linalg.svd(subtracted)

    # the direction vector is the right singular vector 
    # corresponding to the largest singular value
    direction = V[0, :]
    
    # A line is defined by a support vector, the average,
    # and its direction
    p0 = avg
    d = direction

    return p0, d


