在python中使用DBSCAN是否有一种维度大于2的简单方法?

2024-05-23 14:49:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在使用集群算法进行一个机器学习项目,我正在研究基于我正在使用的数据使用scikit learn的DBSCAN实现。但是,每当我尝试使用功能阵列运行它时,它都会抛出以下错误:

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

这给我的印象是scikit的DBS只能支持二维功能。我这样想是不是错了?如果没有,是否有支持高维特征阵列的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);

Tags: to功能defwithscikitarraypickledbscan