gpt4 book ai didi

python - 索引错误和值错误如何处理?

转载 作者:行者123 更新时间:2023-11-30 08:57:05 27 4
gpt4 key购买 nike

我有一个问题。该数据集有两个分类列。每当我执行labelencoder_y时,它都会给我IndexError:数组索引太多,每当我运行最后一个onehotencoder时,它都会给我ValueError:可以不将字符串转换为 float :“否”。虽然我没有遇到 x 值的任何问题。怎么处理呢?数据集如下

Site Name,Per Article,Per Song,Per Hour,Per Test,Per Survey,Per Minute,Pakistan
Listverse,100,0,0,0,0,0,Yes
Playlist Push,0,12,0,0,0,0,No
TranscribeMe,0,0,18,0,0,0,Yes
IntelliZoomPanel,0,0,0,10,0,0,No
Italki,0,0,12,0,0,0,Yes
Vindalle Research,0,0,0,0,3,0,No
Rev,0,0,0,0,0,2,Yes
QuickRewards,0,0,0,0,5,0,No

这是我的代码:

#Importing the libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

#Importing the dataset
dataset = pd.read_csv('sheet.csv')
X = dataset.iloc[:, :-7].values
y = dataset.iloc[:, 7].values

from sklearn.preprocessing import LabelEncoder, OneHotEncoder
labelencoder_X= LabelEncoder()
X[:,0] = labelencoder_X.fit_transform(X[:,0])
onehotencoder = OneHotEncoder(categorical_features = [0])
X = onehotencoder.fit_transform(X).toarray()

labelencoder_y = LabelEncoder()
y[:,0] = labelencoder_y.fit_transform(y[:,0])
onehotencoder = OneHotEncoder(categorical_features = [0])
y = onehotencoder.fit_transform(y).toarray()

最佳答案

我认为索引太多了。全部剥离,编码工作没有错误

labelencoder_y = LabelEncoder()
y = labelencoder_y.fit_transform(y)
y = y.reshape(-1, 1)
onehotencoder = OneHotEncoder()
y = onehotencoder.fit_transform(y).toarray()

关于python - 索引错误和值错误如何处理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56239857/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com