Witam, potrzebuję pomocy, mam kod z zajęć ze Sztucznej Inteligencji. Na zajęciach na komputerach z uczelni wszystko działało sprawnie. A teraz na moim prywatnym nie chce działać. Wyskakuje mi błąd:
"ImportError: cannot import name 'MutableSet' from 'collections'"
Po szukaniu w internecie znalazłam informację, że jest to związane z tym, że od wersji 3.9 Pythona zamiast
from collections import MutableMapping
powinno się pisać
from collections.abc import MutableMapping
więc zgaduję, że na komputerach na studiach jest po prostu starsza wersja Pythona, ja używam Spydera z Pythonem 3.10.
Gdyby zależało to tylko od dopisania tego, to bym sobie poradziła, niestety program, który mam z zajęć nie odwołuje się do tej biblioteki.
import numpy as np
from neupy import algorithms
import hickle as hkl
from sklearn.model_selection import StratifiedKFold
x,y_t,x_norm,x_n_s,y_t_s = hkl.load('iris.hkl')
y_t -= 1
x=x.T
y_t = np.squeeze(y_t)
lvqnet = algorithms.LVQ(n_inputs=x.shape[0], n_classes=np.unique(y_t).shape[0],step=0.001)
#lvqnet = algorithms.LVQ2(n_inputs=x.shape[0], n_classes=np.unique(y_t).shape[0],step=0.001)
# lvqnet = algorithms.LVQ21(n_inputs=x.shape[0], n_classes=np.unique(y_t).shape[0],step=0.001)
# http://neupy.com/modules/generated/neupy.algorithms.LVQ3.html
# lvqnet = algorithms.LVQ3(n_inputs=x.shape[0], n_classes=np.unique(y_t).shape[0],step=0.001)
lvqnet.train(x, y_t, epochs=100)
y=lvqnet.predict(x)
e = y_t - y
PK = (1 - sum(abs(e)>=0.5)/e.shape[0] ) * 100
print("\nPK = %5d" % PK)
data = x
target = y_t
CVN = 10
skfold = StratifiedKFold(n_splits=CVN)
PK_vec = np.zeros(CVN)
for i, (train, test) in enumerate(skfold.split(data, target), start=0):
x_train, x_test = data[train], data[test]
y_train, y_test = target[train], target[test]
# print(i,train,test)
lvqnet = algorithms.LVQ(n_inputs=x_train.shape[1], n_classes=np.unique(y_train).shape[0],step=0.001)
#lvqnet = algorithms.LVQ2(n_inputs=x.shape[1], n_classes=np.unique(y_t).shape[0],step=0.001)
# lvqnet = algorithms.LVQ21(n_inputs=x.shape[1], n_classes=np.unique(y_t).shape[0],step=0.001)
# http://neupy.com/modules/generated/neupy.algorithms.LVQ3.html
# lvqnet = algorithms.LVQ3(n_inputs=x.shape[1], n_classes=np.unique(y_t).shape[0],step=0.001)
lvqnet.train(x_train, y_train, epochs=100)
result = lvqnet.predict(x_test)
n_test_samples = test.size
PK_vec[i] = np.sum(result == y_test) / n_test_samples
print("Test #{:<2}: PK_vec {} test_size {}".format(i, PK_vec[i], n_test_samples))
PK = np.mean(PK_vec)
print("PK {}".format(PK))
Z góry dziękuję za pomoc