我正试图将高尔距离的实现应用于我的数据框架。虽然它在处理具有更多特征的同一数据集时很顺利,但这次当我调用Gower距离函数时却出现了错误。我从同一目录下的另一个.py代码中导入了Gower的函数。下面是我的代码。
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import gower_function as gf
# Importing the dataset with pandas
dataset = pd.read_excel('input_partial.xlsx')
X = dataset.iloc[:, 1:].values
df = pd.DataFrame(X)
#obtaining gower distances of instances
Gower = gf.gower_distances(X)
并在执行后,我得到以下错误。
File "<ipython-input-10-6a4c39600b0e>", line 1, in <module>
Gower = gf.gower_distances(X)
File "C:\Users\...\Clustering\Section 24 - K-Means
Clustering\gower_function.py", line 184, in gower_distances
X_num = np.divide(X_num ,max_of_numeric,out=np.zeros_like(X_num),
where=max_of_numeric!=0)
TypeError: ufunc 'true_divide' output (typecode 'd') could not be coerced to
provided output parameter (typecode 'q') according to the casting rule
''same_kind''
我不明白为什么在同样的数据集上,只有较少的特征(列)会出现这种错误。有谁能说出其中的原因吗?