[Python] HDBSCAN unable to generate prediction data

Discussão em 'Python' iniciado por Stack, Julho 18, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to use a HDBSCAN model that I previously pkl'ed from google co-lab over to a local python project I am doing. The problem I am having is that no matter what this model will not generate any prediction data. I believe that I have trained the model correctly and the example array is what the input data looks like.

    Any help is greatly appreciated.

    TESTING THE PREDICTIONS

    import joblib
    import numpy as np
    import hdbscan

    model = joblib.load("hdbscan_model.pkl")
    print("Model loaded")

    test_sample = [ 1, 516, 1, 237, 1, -667, 0, 945, 1, -2882, 1, 1519, 1, -2878]
    try:
    labels, strengths = hdbscan.approximate_predict(model, test_sample)
    print("Predicted labels:", labels)
    except Exception as e:
    print("Prediction error:", e)


    HOW MODEL WAS TRAINED IN COLAB

    X = df_cleaned.drop(columns=['Failure_area'])

    #Scale features
    X_scaled = StandardScaler().fit_transform(X)

    #UMAP for 2D projection
    reducer = umap.UMAP(random_state=42)
    X_umap = reducer.fit_transform(X_scaled)

    # HDBSCAN clustering
    clusterer = hdbscan.HDBSCAN(min_cluster_size=40, min_samples= 55, prediction_data=True, gen_min_span_tree=True)
    import pickle


    # Save the model to a file
    with open('hdbscan_model.pkl', 'wb') as f:
    pickle.dump(clusterer, f)

    Continue reading...

Compartilhe esta Página