在scikit中使用PassiveAggressiveClassifier的正确方法在线学习



我希望在scikit在线学习环境中训练PassiveAggressiveClassifier。

我想知道实例化这个分类器的正确方法是否是

PA_I_online = PassiveAggressiveClassifier(warm_start=True)

根据文件

warm_start : bool, optional
When set to True, reuse the solution of the previous call to fit as initialization, otherwise, just erase the previous solution. 

这就是我在在线/增量设置中所需要的-在下一个数据点上继续训练模型

但在这个例子中,它被称为

'Passive-Aggressive': PassiveAggressiveClassifier()

同样,在这个代码太

注意,根据文档,warm_start=False的默认值

我是不是错过了什么

我完整的在线培训代码狙击手是:

# Given X_train, y_train, X_test and y_test, labels
PA_I_online = PassiveAggressiveClassifier(loss='hinge', warm_start=True)
no_of_samples = len(X_train)
no_of_classes= np.unique(labels)
for i in range(no_of_samples):
    #get the ith datapoint
    X_i = X_train[i]
    y_i = y_train[i]
    #reshape it
    X_i = X_i.reshape(1,300)
    y_i = y_i.reshape(1,)
    #consume data point 
    PA_I_online.partial_fit(X_i, y_i, no_of_classes)

关键:要使用PassiveAggressiveClassifier()进行在线培训,必须设置参数warm_start=True

使用partial_fit()时,在任何情况下都不会重新初始化模型。文档介绍了fit()方法,该方法默认情况下重置模型参数并从头开始训练。CCD_ 3是为CCD_ 4方法设计的。

您可能会发现此讨论对进一步的详细信息很有用。

最新更新