我刚刚尝试了kaggle.com上的Indian Pima Diabetes Dataset,该数据集有7个输入和2个输出。我试图在Anaconda和Jupyter Notebook中使用ANFIS-Package在Python中,但是即使我仅使用10或5个样本,也会出现内存错误。我真的不是编程或计算机科学方面的专家,因此,在阅读了互联网上的很多建议后,我完全没有想法,为什么会发生这种情况以及如何解决。所以,我希望您的帮助!
这是我的代码:
import numpy as np
diabetes = np.loadtxt("C:/Users/elihe/Documents/Studium Master/Masterarbeit/diabetes.txt", delimiter = ',')
X = diabetes[:5, 0:8]
y = diabetes[:5, 8]
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)
# Input 0: Schwangerschaften - wenig, normal, viel
mf = [[['gaussmf',{'mean':2.,'sigma':1.}], ['gaussmf', {'mean':6., 'sigma': 1.}], ['sigmf', {'b': 9., 'c':1.}]],
# Input 1: Glukose - niedrig, normal, hoch
[['gaussmf',{'mean':60.,'sigma':10.}], ['gaussmf',{'mean':120.,'sigma':10.}], ['sigmf', {'b': 160., 'c':0.7}]],
# Input 2: Blutdruck - niedrig, normal, hoch
[['gaussmf',{'mean':40.,'sigma':5.}], ['gaussmf',{'mean':80.,'sigma':5.}], ['sigmf', {'b': 100., 'c':0.7}]],
# Input 3: Hautdicke - dünn, normal, dick
[['gaussmf',{'mean':30.,'sigma':5.}], ['gaussmf',{'mean':60.,'sigma':5.}], ['sigmf', {'b': 80., 'c':0.7}]],
# Input 4: Insulin - niedrig, mittel, hoch
[['gaussmf',{'mean':100.,'sigma':15.}], ['gaussmf',{'mean':300.,'sigma':15.}], ['sigmf', {'b': 600., 'c':0.5}]],
# Input 5: BMI - niedrig, normal, hoch
[['gaussmf',{'mean':15.,'sigma':3.}], ['gaussmf',{'mean':30.,'sigma':3.}], ['sigmf', {'b': 40., 'c':1.}]],
# Input 6: Diabetes-Stammbaum-Funktion - niedriges Risiko, normales Risiko, hohes Risiko
[['gaussmf',{'mean':0.5,'sigma':0.5}], ['gaussmf',{'mean':1.5,'sigma':0.5}], ['sigmf', {'b': 2., 'c':2.}]],
# Input 7: Alter - jung, normal, alt
[['gaussmf',{'mean':30,'sigma':3}], ['gaussmf',{'mean':50,'sigma':4}], ['sigmf', {'b': 70., 'c':1.}]]]
import anfis
from anfis.membership import membershipfunction, mfDerivs
mfc = membershipfunction.MemFuncs(mf)
from anfis import anfis
anf = anfis.ANFIS(X_train, y_train, mfc)
# Fitting
anf.trainHybridJangOffLine(epochs=2)
在这一点上,当其他所有事情都变好之后,就会发生此错误:
MemoryErrorTraceback (most recent call last)
<ipython-input-8-a274e224b0d3> in <module>()
4
5 # Fitting
----> 6 anf.trainHybridJangOffLine(epochs=2)
C:\Users\elihe\anaconda3\envs\py27\lib\site-packages\anfis\anfis.pyc in trainHybridJangOffLine(self, epochs, tolerance, initialGamma, k)
67
68 #layer five: least squares estimate
---> 69 layerFive = np.array(self.LSE(layerFour,self.Y,initialGamma))
70 self.consequents = layerFive
71 layerFive = np.dot(layerFour,layerFive)
C:\Users\elihe\anaconda3\envs\py27\lib\site-packages\anfis\anfis.pyc in LSE(self, A, B, initialGamma)
46 coeffMat = A
47 rhsMat = B
---> 48 S = np.eye(coeffMat.shape[1])*initialGamma
49 x = np.zeros((coeffMat.shape[1],1)) # need to correct for multi-dim B
50 for i in range(len(coeffMat[:,0])):
C:\Users\elihe\anaconda3\envs\py27\lib\site-packages\numpy\lib\twodim_base.pyc in eye(N, M, k, dtype, order)
199 if M is None:
200 M = N
--> 201 m = zeros((N, M), dtype=dtype, order=order)
202 if k >= M:
203 return m
MemoryError:
我真的不知道,这是怎么回事:(