尽管有很多关于错误ValueError: negative dimensions are not allowed
的问题线程
我找不到我的问题的答案
使用SGDclassifer训练机器学习模型后
clf=linear_model.SGDClassifier(loss='log',random_state=20000,verbose=1,class_weight='balanced')
model=clf.fit(X,Y)
X的维数是(1651880,246177)
下面的代码有效,即在保存模型对象和使用模型进行预测时
joblib.dump(model, 'trainedmodel.pkl',compress=3)
prediction_result=model.predict(x_test)
但是在加载保存的模型时出错
model = joblib.load('trainedmodel.pkl')
下面是错误消息 请帮我解决。
File "C:\Users\Taxonomy\AppData\Roaming\Python\Python36\site-packages\sklearn\externals\joblib\numpy_pickle.py", line 598, in load
obj = _unpickle(fobj, filename, mmap_mode)
File "C:\Users\Taxonomy\AppData\Roaming\Python\Python36\site-packages\sklearn\externals\joblib\numpy_pickle.py", line 526, in _unpickle
obj = unpickler.load()
File "C:\Users\Taxonomy\Anaconda3\lib\pickle.py", line 1050, in load
dispatch[key[0]](self)
File "C:\Users\Taxonomy\AppData\Roaming\Python\Python36\site-packages\sklearn\externals\joblib\numpy_pickle.py", line 352, in load_build
self.stack.append(array_wrapper.read(self))
File "C:\Users\Taxonomy\AppData\Roaming\Python\Python36\site-packages\sklearn\externals\joblib\numpy_pickle.py", line 195, in read
array = self.read_array(unpickler)
File "C:\Users\Taxonomy\AppData\Roaming\Python\Python36\site-packages\sklearn\externals\joblib\numpy_pickle.py", line 141, in read_array
array = unpickler.np.empty(count, dtype=self.dtype)
ValueError: negative dimensions are not allowed
答案 0 :(得分:0)
尝试使用协议4转储模型。
来自python的泡菜docs:
协议版本4已在Python 3.4中添加。它增加了对 大对象,腌制更多种类的对象以及某些数据格式 优化。有关改进的信息,请参考PEP 3154 由协议4带来。