June 2018
Intermediate to advanced
276 pages
6h 26m
English
In statistics, Lasso is a regression analysis method. Lasso linear regression L1 simply adds a penalty equivalent to the absolute value of the magnitude of coefficients. The following is an implementation of the method in Python and sckit-learn:
>>> from sklearn.svm import LinearSVC>>> from sklearn.datasets import load_iris>>> from sklearn.feature_selection import SelectFromModel>>> iris = load_iris()>>> X, y = iris.data, iris.target>>> X.shape>>> lsvc = LinearSVC(C=0.01, penalty="l1", dual=False).fit(X, y)>>> model = SelectFromModel(lsvc, prefit=True)>>> X_new = model.transform(X)>>> X_new.shape

Read now
Unlock full access