我正在尝试对两个类的分类问题进行降维。
我有 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"。
该错误基本上是指您的y
具有bad input shape (464, 3)
。对于您发布的线性判别分析,您应该提供一个输出,即"类"(尽管您可以有多个类(,并且您的y
应该是一维数组。虽然我不确定你想做什么以及为什么你需要 3 列......