分类器中的 scikit-learn 改装/部分拟合选项

Muh*_*waz 8 parameters machine-learning scikit-learn logistic-regression

我想知道 sklearn 分类器中是否有任何选项可以使用一些超参数进行拟合,并在更改一些超参数后,通过节省计算(拟合)成本来重新拟合模型。

让我们说,逻辑回归适合使用C=1e5( logreg=linear_model.LogisticRegression(C=1e5)),我们只更改CC=1e3。我想节省一些计算,因为只更改了一个参数。

Moh*_*OUI 10

是的,有一种技术叫做warm_start,从文档中引用,这意味着:

warm_start : bool, 默认值: False
设置为True 时,重用之前调用fit 的解作为初始化,否则,只擦除之前的解。对 liblinear 求解器没用。

如文档中描述的在这里,它提供LogisticRegression

sklearn.linear_model.LogisticRegression(..., warm_start=False, n_jobs=1)
Run Code Online (Sandbox Code Playgroud)

因此,具体而言,对于您的情况,您将执行以下操作:

from sklearn.linear_model import LogisticRegression 

# create an instance of LogisticRegression with warm_start=True
logreg = LogisticRegression(C=1e5, warm_start=True)
# you can access the C parameter's value as follows
logreg.C 
# it's set to 100000.0

# .... 
# train your model here by calling logreg.fit(..)
# ....

# reset the value of the C parameter as follows 
logreg.C = 1e3 

logreg.C 
# now it's set to 1000.0

# .... 
# re-train your model here by calling logreg.fit(..)
# ....
Run Code Online (Sandbox Code Playgroud)

就我能够快速检查而言,它也可以在以下位置使用: