【发布时间】:2022-01-21 17:13:58
【问题描述】:
数据集:https://docs.google.com/spreadsheets/d/1jlKp7JR9Ewujv445QgT1kZpH5868fhXFFrA3ovWxS_0/edit?usp=sharing
我一直在尝试将集成方法从 sklearn 部署到我上面链接的一个小数据集。出于某种原因,我不断收到此错误。
ValueError: y should be a 1d array, got an array of shape (9, 56) instead.
这是代码:
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
from numpy import array
from sklearn import datasets, metrics
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.preprocessing import OneHotEncoder
from sklearn.preprocessing import LabelEncoder
cbdata = pd.read_excel("C:/Users/Andrew/cbupdated2.xlsx")
print(cbdata)
print(cbdata.describe())
df = cbdata.columns
print(df)
x = cbdata
y = cbdata.fundingstatus
xshape = x.shape
yshape = y.shape
shapes = xshape, yshape
print(shapes)
size = x.size, y.size
print(size)
###Problem ENCODING DATA
##Label encoder
label_encoder = LabelEncoder()
integer_encoded = label_encoder.fit_transform(x)
print(integer_encoded)
scaler = StandardScaler()
X_scaled = scaler.fit_transform(x)
print(X_scaled)
###Problm block
ec = OneHotEncoder()
X_encoded = cbdata.apply(lambda col: ec.fit_transform(col.astype(str)), axis=0, result_type='expand')
X_encoded2 = X_encoded.shape
print(X_encoded2)
关于让编码器工作的任何帮助和/或建议,以便我可以使用 ensemble 方法?
【问题讨论】:
标签: python arrays machine-learning scikit-learn encoding