資源簡(jiǎn)介
利用隨機(jī)坐標(biāo)下降法和循環(huán)坐標(biāo)下降法求解lasso回歸,并作比較。
代碼片段和文件信息
import?numpy?as?np
import?pandas?as?pd
import?matplotlib.pyplot?as?plt
from?sklearn?import?linear_model
from?sklearn?import?preprocessing
from?sklearn.model_selection?import?train_test_split
import?copy
class?Algorithm:
“““
This?is?a?demo?of?using?coordinate?descent?algorithm?(including?both?cyclic?coordinate?descent?
and?randomized?coordinate?descent)?to?solve?the?LASSO?problem?that?is?the?‘l1-regularized?
least-squares?regression?problem.
“““
def?__init__(self?lambduh=6.46?max_iter=1000):
“““
Coordinate?descent?algorithm?to?solve?the?LASSO?problem.
Parameters
----------
lambduh?:?float
Regularization?parameter.
The?default?lambduh?is?set?as?6.46?(the?optimal?lambduh?from?cross?validation?result).?
However?users?are?allowed?set?lambduh?in?the?__main__?function
評(píng)論
共有 條評(píng)論