无法在Heroku服务器中使用joblib加载模型

时间:2020-05-15 23:15:35

标签: python django heroku scikit-learn joblib

为什么我已经建立了一个带有django框架的网站。我使用Sklean库为我的网站训练模型。我已经用joblib导出了最终模型,并在我的网站中通过了它。当我需要预测时,可以使用jolib的加载功能加载模型。

第一拳,我在本地主机上测试了我的网站,它运行正常。下一步是将我的网站部署到免费主机上,一个不错的选择是heroku。

我已经创建了所有必要的文件和依赖项。在requirements.txt中,我有以下内容:

Django==2.2.4
django-crispy-forms==1.9.0
django-widget-tweaks==1.4.8
entrypoints==0.3
flake8==3.7.8
gunicorn==20.0.4
joblib==0.14.1
mccabe==0.6.1
numpy==1.18.3
pandas==1.0.3
psycopg2==2.8.3
pycodestyle==2.5.0
pyflakes==2.1.1
python-dateutil==2.8.1
pytz==2019.2
scikit-learn==0.22.2.post1
scipy==1.4.1
six==1.14.0
sqlparse==0.3.0

对于runtime.txt:

python-3.7.3

我的问题是,当我需要在服务器中加载模型(GradientBoostingClassifier)时出现值错误

Buffer dtype mismatch, expected 'SIZE_t' but got 'int'

我发现类似的帖子hear关于python的版本。在我第二次尝试解决此问题的过程中,我在服务器中创建了模型,结果再次相同

听到我的模型提取代码

import pandas as pd
import numpy as np
import scipy.io
from numpy import *  
from sklearn.model_selection import train_test_split # Import train_test_split function
from sklearn.externals.six import StringIO  
# gradient boost to read and gready alorithms
from sklearn.ensemble import GradientBoostingClassifier
from joblib import dump
from sklearn.model_selection import cross_val_score



data_set = pd.read_csv('./Final_data_set_for_HCC.csv')



#create the model 

Classifier = GradientBoostingClassifier()

xTrain, xTest, yTrain, yTest = train_test_split(data_set.drop(['Class'], axis=1), data_set.Class, test_size = 0.15, random_state = 10
                                    )

Classifier.fit(xTrain,yTrain)


# Scoring the model (cross validation and test data accuracy)
scores = cross_val_score(Classifier, xTrain, yTrain, cv=5)
print('Mean C-V Score:', round(scores.mean(),3))
print('Model Accuracy:', Classifier.score(xTest, yTest))


# Dumping the model and the feature columns to file
dump(Classifier, './Gradient_Boosting_Classifier_Model.joblib')

如果有人知道如何解决此问题,请在下面发表评论。如果您提交表格,我将住在Heroku并部署在site中,您会看到错误。我在django中使用了调试模式。

谢谢您的时间。

0 个答案:

没有答案