0

I got this error on python 3.12.7:

Traceback (most recent call last):
  File "/Users/hongviet/Library/Mobile Documents/com~apple~CloudDocs/Documents/DataAnlalysCoding/First Week/baitap1.py", line 186, in <module>
    main()
  File "/Users/hongviet/Library/Mobile Documents/com~apple~CloudDocs/Documents/DataAnlalysCoding/First Week/baitap1.py", line 179, in main
    original_scores = scaler.inverse_transform(features[i].numpy().reshape(1, -1)).flatten()

                                      

I dont know Why but i think it can be error by the data: when I tried to transform them from the tensor, here is what method I find on github but it not true, Does anyone know how to fix or has another method

here is my code on main function

build()

# tạo dữ liệu mẫu
features, labels = generate_sample_data(12)
for i in range (12):
    print(features[i], labels[i])


# Tạo mô hình từ file đã lưu
model = MLP()
model.load_state_dict(torch.load('model.pth'))
model.eval()

# Chuẩn hóa dữ liệu
scaler = preprocessing.StandardScaler()
features = scaler.fit_transform(features)
features = torch.tensor(features, dtype=torch.float32)

# Dự đoán
with torch.no_grad():
    y_pred = model(features)
    y_pred = (y_pred > 0.5).float()
    print('Nhãn dự đoán:', y_pred)
    print('Nhãn thực tế:', labels)

# in ra các học sinh đạt dnah hiệu 
# và các học sinh không đạt danh hiệu với số điểm tương ứng mà sinh viên đó có
for i in range(12):
    original_scores = scaler.inverse_transform(features[i].numpy().reshape(1, -1)).flatten()
    if y_pred[i] == 1:
        print('Học sinh đạt danh hiệu với điểm:', features[i])
    else:
        print('Học sinh không đạt danh hiệu với điểm:', features[i])
2
  • What version of NumPy do you have? Commented Jan 8 at 6:18
  • i have 2.1.3numpy version Commented Jan 8 at 14:03

1 Answer 1

1

I have faced this error after the release of numpy 2.0. Not knowing which version of pytorch or numpy you are using. Try:

pip install "numpy<2"

in your python package environment.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.