在同一模型上多次调用fit()有什么作用? [英] What does calling fit() multiple times on the same model do?
问题描述
实例化一个scikit模型(例如 LinearRegression
)之后,如果我多次调用它的 fit()
方法(使用不同的 X
和 y
数据),会发生什么?是否像我刚刚重新实例化模型一样(例如,从头开始)将模型拟合到数据上,还是将先前调用 fit()
时已经拟合的数据考虑在内?>
尝试使用 LinearRegression
(还要查看其源代码),在我看来,每次调用 fit()
时,它都会从头开始拟合,而忽略了以前对同一方法的任何调用.我不知道这通常是否正确,并且我可以在scikit learning的所有模型/管道中使用此行为.
如果您第二次执行 model.fit(X_train,y_train)
-它会覆盖所有先前拟合的系数,重量,截距(偏差)等.
如果您只想拟合一部分数据集,然后通过拟合新数据来改善模型,则可以使用 partial_fit()方法的对象)
After I instantiate a scikit model (e.g. LinearRegression
), if I call its fit()
method multiple times (with different X
and y
data), what happens? Does it fit the model on the data like if I just re-instantiated the model (i.e. from scratch), or does it keep into accounts data already fitted from the previous call to fit()
?
Trying with LinearRegression
(also looking at its source code) it seems to me that every time I call fit()
, it fits from scratch, ignoring the result of any previous call to the same method. I wonder if this true in general, and I can rely on this behavior for all models/pipelines of scikit learn.
If you will execute model.fit(X_train, y_train)
for a second time - it'll overwrite all previously fitted coefficients, weights, intercept (bias), etc.
If you want to fit just a portion of your data set and then to improve your model by fitting a new data, then you can use estimators, supporting "Incremental learning" (those, that implement partial_fit()
method)
这篇关于在同一模型上多次调用fit()有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!