scikitlearn中的“fit”函数如何进行验证?

2024-05-19 08:58:32 发布

您现在位置:Python中文网/ 问答频道 /正文

当应用于MLPClassifier时,fit函数有问题。我仔细阅读了Scikit-Learn's documentation about that,但无法确定验证是如何工作的。在

是交叉验证还是在培训和验证数据之间存在分割?在

提前谢谢。在


Tags: 数据函数thatdocumentationscikitlearn交叉fit
1条回答
网友
1楼 · 发布于 2024-05-19 08:58:32

fit函数本身不包括交叉验证,也不应用列车测试分割。 幸运的是你自己能做到。

列车试验拆分:

from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33) // test set size is 0.33 
clf = MLPClassifier()
clf.fit(X_train, y_train) 
clf.predict(X_test, y_test) // predict on test set 

K-折叠交叉验证

^{pr2}$

对于交叉验证有多个函数可用,您可以阅读更多关于它的here。这里所说的k-折叠只是一个例子。

编辑:

Thanks for this answer, but basically how does fit function works concretely ? It just trains the network on the given data (i.e. training set) until max_iter is reached and that's it ?

我假设您使用的是MLPClassifier的默认配置。在这种情况下,fit函数尝试在adam优化器的基础上进行优化。实际上,在这种情况下,网络会一直训练到到达最大值。

Moreover, in the K-Fold cross validation, is the model improving as long as the loop goes through or just restarts from scratch ?

实际上,交叉验证并不是用来提高网络性能的,它实际上是一种方法,用来测试你的algrotihm在不同数据上的泛化能力。对于k-fold,训练并测试了k个独立分类器。

相关问题 更多 >

    热门问题