pandas: mean imputation corrupts Argentina's GDP per capita in the later plot

Đang mở Phù hợp với người mới
#658 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
82/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
pandas, python
Lĩnh vực
data, documentation

Hướng nghiên cứu

Bắt đầu với việc nội suy các giá trị bị thiếu và phép tính GDP bình quân đầu người sau đó trong lectures/pandas.md, rồi tái tạo các biểu đồ bằng test_pwt.csv từ QuantEcon/data-lectures. Quyết định giữ giá trị bị lỗi như một bài học về lỗi âm thầm hay thay đổi dữ liệu được nội suy. Hoàn tất khi bài giảng không còn trình bày GDP bình quân đầu người sai của Argentina là hợp lệ, và biểu đồ hoặc phần giải thích làm rõ kết quả.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

In lectures/pandas.md, the missing value imputation step silently corrupts the GDP per capita figures that the lecture plots later.

What happens

  1. "Let's randomly insert some NaN values" sets df.iloc[idx] = np.nan for idx in zip([0, 3, 5, 6], [3, 4, 6, 2]). The first pair is Argentina's POP.
  2. df = df.fillna(df.iloc[:,2:8].mean()) replaces it with the mean population of the other countries, about 196 million, against Argentina's true 37 million. India and the United States pull the mean far up.
  3. "Standardization and Visualization" then computes GDP percap = total GDP * 1e6 / population from this df and plots it.

Argentina's GDP per capita comes out at about 1,500 instead of 7,900, so the sorted bar chart shows Argentina as poorer than India. Nothing in the output signals that anything went wrong.

country true in lecture
Argentina 7,903 1,504
all other countries unchanged unchanged

(Reproduced against test_pwt.csv in QuantEcon/data-lectures, following the lecture's code.)

The other imputed cells (Israel XRAT, South Africa cc, US year) are not used in the GDP per capita calculation, so only Argentina is affected. Imputing year with a column mean is also odd, but harmless here.

Possible fixes

  • Insert the NaNs only in columns not used later (for example cc and cg), or reload the data before "Standardization and Visualization".
  • Alternatively, keep the bug and turn it into a lesson: point out that the code runs without complaint but gives a wrong answer, because imputation is a modeling choice whose errors flow through to everything computed from it. The course version of this lecture does this in a short "silent failures" section: https://jstac.github.io/py_for_ds_public/working_with_data.html

cc @mmcky

Ngôn ngữ chính
JavaScript
Star
73
Fork
34
Merge trung bình
28 phút
Pull request đã merge (30 ngày)
5

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của QuantEcon/lecture-python-programming

Tất cả issue của QuantEcon/lecture-python-programming

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.