Код Django не может установить маринованную переменную sklearn

Я создаю Django сайт, который содержит приложение сегментации. Трудность, с которой я сталкиваюсь, заключается в импорте переменных сегментации kmeans / hclusters, которые были сохранены через joblib.

Чтобы попытаться минимизировать влияние факторов, я создаю кластеры на той же машине (новый Macbook M1), что и машина, в которую я загружаю переменные. Я также использовал ту же структуру окружения (оба окружения Python 3.10) и синхронизировал окружения numpy, pandas и scikit-learn

Я не могу понять, что мешает загрузке joblib в среде Django. Ошибка возникает и при использовании pickle / pickle5.

Сообщение об ошибке при попытке импорта:

Код проекта Django при попытке импорта

from website.settings import STAT_FILES
import pickle
from joblib import dump, load
import pandas as pd
from sklearn.preprocessing import normalize


def get_segment(deck_in):
    df_out = deck_in
    deck_df = get_elixr(deck_in)

    kmeans_name = STAT_FILES / 'pickles/kmeans.pickle'
    hclust_name = STAT_FILES / 'pickles/clust.pickle'
    segcols_name = STAT_FILES / 'pickles/segment_cols'

    clustering = load(kmeans_name)
    Hclustering = load(hclust_name)

requirements.txt для среды импорта Django

django==4.0
boto3==1.20.26
psycopg2==2.9.3
botocore==1.23.26
gunicorn==20.1.0
django-crispy-forms==1.13.0
pandas==1.3.5
numpy==1.22.0
scikit_learn==1.0.2

requirements.txt для среды сборки сегмента:

pandas==1.3.5
numpy==1.22.0
sklearn==0.0
scikit-learn==1.0.2
openpyxl==3.0.9
joblib==1.1.0
scipy==1.7.3
ujson==5.1.0
requests==2.27.1

тест загрузки joblib в среде segment_build:

    print(f'Analysis complete with {km_seg} kmeans clusters and {n_clusts} agglomerative clusters')
    print('Saving model to pickle for later scoring...')

    dump(clustering, (Config.CLASH_PATH + '/src_code/pickles/kmeans.pickle'))
    dump(Hclustering, (Config.CLASH_PATH + '/src_code/pickles/hclust.pickle'))

    test_val1 = load((Config.CLASH_PATH + '/src_code/pickles/kmeans.pickle'))
    test_val2 = load((Config.CLASH_PATH + '/src_code/pickles/hclust.pickle'))

    print(type(test_val1))
    print(type(test_val2))
Current Timestamp :  09-Jan-2022 (12:47:24.455416)
Analysis being performed with 25 kmeans clusts, and 10 segments...
Iterating through kmeans (1 = yes / 0 = no): 1
Fit complete based upon sample.  Scoring full dataset...
KMeans analysis complete.
Current Timestamp :  09-Jan-2022 (12:47:27.082020)
Composing hierarchical segmentation of KMeans.
Hierarchical segmentation complete.  Aggregating statistics for review...
Current Timestamp :  09-Jan-2022 (12:47:27.082856)
File length: 1356406
Total number of undefined categories is: 1   Total number of categories is: 10
['001 3.8   29.6%  Undefined: Balloon               ', '002 3.1   55.1%  Tesla The_Log X-Bow              ', '003 4.0   43.6%  Tornado Golem Baby_Dragon        ', '004 3.8   59.9%  Goblin_Giant Dark_Prince Sparky  ', '005 3.6   73.1%  Elixir_Golem Electro_Dragon Battle_Healer', '006 3.4   61.2%  Princess Goblin_Barrel Rocket    ', '007 2.7   89.0%  Hog_Rider Fireball Musketeer     ', '008 3.6   66.5%  Royal_Giant Fisherman Fireball   ', '009 3.9   55.6%  Bandit P_E_K_K_A Electro_Wizard  ', '010 4.1   74.4%  Royal_Recruits Royal_Hogs Flying_Machine']
Current Timestamp :  09-Jan-2022 (12:47:48.776581)
Please review the stats in the segment summary file.  Should we iterate again? (y/n)Analysis complete with 25 kmeans clusters and 10 agglomerative clusters
Saving model to pickle for later scoring...
<class 'sklearn.cluster._kmeans.KMeans'>
<class 'sklearn.cluster._agglomerative.AgglomerativeClustering'>

Process finished with exit code 0
Вернуться на верх