
[英]MinMaxScaler for dataframe: ValueError: setting an array element with a sequence
[英]Working and solving valueerror setting an array element with a sequence on dataframe
这个问题已经在几个地方讨论过,包括这里、这里和这里。 然而,作为经典,我正在努力实现对我的代码提出的想法。
我收到错误消息:
这意味着如果我们尝试将某些内容写入数组的单个位置(数组单元格,矩阵条目)并且该内容不是标量值,则会发生使用序列设置数组元素的错误。
我试图发送给我的预测 model 的数据类型是:
(14, 34)
<class 'pandas.core.frame.DataFrame'>
在我“切片”我的数据之后,这就是我得到的:
这是我的代码:
print("-----------------")
result = result.reset_index(drop=True) # Reindex a dataframe with duplicate index values
print(result)
print("-----------------")
print(result.shape)
print(type(result))
##############################################
####### Block for the prediction model #######
##############################################
# Which fiels do I have the features and which I have the prediciton field?
#Slicing the data
array = result.values
numcols = len(array[0]) # total number of column
lastcolumn=numcols-1
X = array[:,0:lastcolumn] # recieves the data of the channels (all columns besides last)
Y = array[:,lastcolumn] # recives the data of the class (last column)
#print(X)
print(Y)
# prepare configuration for cross validation test harness
seed = 7
# prepare models
models = []
models.append(('Linear Discriminant Analysis', LinearDiscriminantAnalysis()))
# evaluate each model in turn
results = []
names = []
scoring = 'accuracy'
for name, model in models:
# k=10: The value for k is fixed to 10, a value that has been found through experimentation to generally result in a model skill estimate with low bias a modest variance.
kfold = model_selection.KFold(n_splits=10, random_state=seed)
cv_results = model_selection.cross_val_score(model, X, Y, cv=kfold, scoring=scoring)
results.append(cv_results)
names.append(name)
msg = "%s: %f (%f)" % (name, cv_results.mean(), cv_results.std())
print(msg)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.