我尝试使用两个类对分类问题进行维数降低。
我有6个csv文件。我的代码在这里:
def linear_discrimination_analysis(files):
with open(os.path.join("/Users", "byname", "PycharmProjects", "sensorLogProject", "Data", files[0]),
'rU') as my_file_0:
df1 = sd.sample_difference(my_file_0)
for f in files[1:len(files) - 2]:
with open(os.path.join("/Users", "myname", "PycharmProjects", "sensorLogProject", "Data", f),
'rU') as my_file_1:
df1.append(sd.sample_difference(my_file_1))
with open(os.path.join("/Users", "myname", "PycharmProjects", "sensorLogProject", "Data", files[len(files) - 2]),
'rU') as my_file_2:
df2 = sd.sample_difference(my_file_2)
with open(os.path.join("/Users", "myname", "PycharmProjects", "sensorLogProject", "Data", files[len(files) - 1]),
'rU') as my_file_3:
df2.append(sd.sample_difference(my_file_3))
X = df1[['x', 'y', 'z']].values
y = df2['label'].values
lda = LDA(n_components=1)
lda.fit_transform(X, y.ravel())
plt.show()
linear_discrimination_analysis(files)
我想这可能是个问题。
这是我得到的错误:
RuntimeWarning: invalid value encountered in divide S**2 [:self._max_components]
每个文件有100行和5列。我想使用第3,第4和第5列进行特征提取,这些列被称为' x'' y'和' z'。
答案 0 :(得分:1)
错误基本上是指y
bad input shape (464, 3)
。对于您发布的线性判别分析,您可以提供一个输出,即"类" (虽然你可以有多个类),你的y
应该是一维数组。虽然我不确定你想做什么,为什么你需要3列y ...