概述
将多维数组转换为一维数组
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
最后
以上就是细腻店员为你收集整理的numpy中的ravel()的全部内容,希望文章能够帮你解决numpy中的ravel()所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复