Implement a function local_outlier_factor(X, k) that computes the Local Outlier Factor (LOF) anomaly score for every point in a dataset.
Given:
X: array-like of shape (n, d) containing n data points in d dimensions.k: positive integer giving the neighborhood size.For each point p, define:
N_k(p): the set of indices of the k nearest neighbors of p (excluding p itself), determined by Euclidean distance and ranked by np.argsort (stable, ascending).k-distance(p): the Euclidean distance from p to its k-th nearest neighbor.reach_dist_k(p, o) = max(k-distance(o), d(p, o)).lrd_k(p) = 1 / mean( reach_dist_k(p, o) for o in N_k(p) ).LOF_k(p) = mean( lrd_k(o) / lrd_k(p) for o in N_k(p) ).Return a Python list of length n containing the LOF score of each point in input order. Do not round inside the function. Assume 1 <= k < n and that no two points coincide.