numpy中的ravel()

将多维数组转换为一维数组

print(Y_underSampling_trian)

输出带有index的DataFrame格式

        Class
6870        1
82147       0
...
[688 rows x 1 columns]

对这个series的values进行ravel()

print(Y_underSampling_trian.values.ravel())

输出1-D数组(ndarray):

[1 0 0 1 1 1 1 0 0 0 1 1 1 1 0 1 0 0....0 0 0 1 0 0 0]

之所以会关注这个,是因为,在sklearn.linear_model.LogisticRegression()应该过程中fit(X,Y)时,Y没有用ravel()出先如下warrning:
‘DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel(). y = column_or_1d(y, warn=True)’

查阅sklearn官网https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html#sklearn.linear_model.LogisticRegression发现fit()的Y是数组:
fit(X, y, sample_weight=None)

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

y : array-like, shape (n_samples,)
Target vector relative to X.

sample_weight : array-like, shape (n_samples,) optional
Array of weights that are assigned to individual samples.
If not provided, then each sample is given unit weight.

New in version 0.17: sample_weight support to LogisticRegression.

Returns:
self : object

  • 17
    点赞
  • 46
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值