【问题标题】:Is there an easy way to use DBSCAN in python with dimensions higher than 2?有没有一种简单的方法可以在尺寸大于 2 的 python 中使用 DBSCAN?
【发布时间】:2023-03-21 16:27:02
【问题描述】:

我一直在使用聚类算法进行机器学习项目,并且正在研究基于我正在使用的数据使用 scikit-learn 的 DBSCAN 实现。但是,每当我尝试使用我的特征数组运行它时,它都会引发以下错误:

ValueError: Found array with dim 3. Estimator expected <= 2.

这给我的印象是scikit的DBSCAN只支持二维特征。我这样想错了吗?如果没有,是否有支持高维特征数组的 DBSCAN 实现?感谢您提供的任何帮助。

编辑

这是我用于 DBSCAN 脚本的代码。这个想法是从许多不同的 CSV 中读取数据,将它们保存到一个数组中,然后将它们转储到一个 pickle 文件中,以便模型可以在将来加载它们并运行 DBSCAN。

def get_clusters(fileList, arraySavePath):
    # Create empty array
    fitting = [];

    # Get values from all files, save to singular array
    for filePath in fileList:
        df = pd.read_csv(filePath, usecols=use_cols);
        fitting.append(df.values.tolist());

    # Save array to it's own csv file    
    with open(arraySavePath, "wb") as fp:
        pickle.dump(fitting, fp);


def predict_cluster(modelPath, predictInput):
    # Load the cluster data
    with open(modelPath, "rb") as fp:
        fitting = pickle.load(fp);

    # DBSCAN fit
    clustering = DBSCAN(eps=3, min_samples=2);
    clustering.fit(fitting);

    # Predict the label
    return clustering.predict_fit(predictInput);

【问题讨论】:

  • 请发布您的(最小相关)代码和您的数据样本; DBSCAN 可以与iris data 的 4 个功能配合使用。

标签: python scikit-learn cluster-analysis dbscan


【解决方案1】:

我认为问题出在“min_samples”参数上。您正在拟合的数据包含 3 个特征/维度,但您已设置“min_samples=2”。 Min_samples 必须等于或大于数据集中的特征数。

【讨论】:

    猜你喜欢
    • 2011-01-27
    • 1970-01-01
    • 2012-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-02
    • 1970-01-01
    相关资源
    最近更新 更多