我正在尝试将 Gower 距离实现应用于我的数据框。虽然它可以顺利地处理具有更多特征的相同数据集,但这次当我调用 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)
Run Code Online (Sandbox Code Playgroud)
执行此操作后,我收到以下错误:
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') …Run Code Online (Sandbox Code Playgroud)