为什么sklearn的LinearRegression中的fit方法只接受X值的2D数组,而接受Y值的1D数组?

2024-09-27 07:26:39 发布

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

基本上只是标题。当我把脚趾伸进sklearn库时,我觉得很奇怪。对此有何解释


Tags: 标题sklearn脚趾
1条回答
网友
1楼 · 发布于 2024-09-27 07:26:39

这就是scikit learn afaik中ML模型的fit方法的设计选择。这主要是为了与输入形状的规范保持一致:(n_samples, n_features)

X : {array-like, sparse matrix} of shape (n_samples, n_features)
     Training vector, where n_samples is the number of samples and
     n_features is the number of features.

^{}的顶部,也清楚地表明了这一点,即引发错误的验证步骤:

Input validation on an array, list, sparse matrix or similar.
By default, the input is checked to be a non-empty 2D array containing
only finite values. If the dtype of the array is object, attempt
converting to float, raising on failure.

LinearRegression确实接受2D目标数组,在这种情况下,它将执行多元线性回归

相关问题 更多 >

    热门问题