การกรองข้อมูลและการวิเคราะห์ขั้นสูง
TechCorp ต้องการระบุพนักงานที่มีศักยภาพสูงสำหรับโปรแกรมพัฒนาภาวะผู้นำ ได้แก่ พนักงานอายุน้อย (ต่ำกว่า 30 ปี) ที่ได้รับเงินเดือนในระดับ Mid หรือ Senior อยู่แล้ว โจทย์นี้ต้องการการลบข้อมูลที่ผิดปกติ (outlier) การสร้างระดับเงินเดือนแบบหมวดหมู่จากข้อมูลตัวเลข และการรวมเงื่อนไขการกรองหลายข้อเข้าด้วยกัน เทคนิคเหล่านี้ช่วยตอบคำถามทางธุรกิจจริงที่การกรองแบบง่ายทำไม่ได้
คลาส Table, Selection, และ StringColumn ได้ถูก import ให้แล้ว
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การนำเข้าข้อมูลใน Java
คำแนะนำการฝึกหัด
- ลบข้อมูลที่ผิดปกติออก (เงินเดือนต่ำกว่า $40K หรือมากกว่า $250K)
- นับจำนวนแถวที่ถูกลบออกหลังการกรอง
- แมปเงินเดือนไปยังระดับ
"Junior","Mid", และ"Senior" - กรองข้อมูลเพื่อหาพนักงานระดับ
"Mid"หรือ"Senior"ที่อายุต่ำกว่า 30 ปี
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
public class DataExploration {
public static void main(String[] args) {
// Start with the high earners table from previous exercises
Table employees = Table.read().csv("employees.csv");
// Remove outliers (salary < $40K or > $250K)
Selection outliers = employees.intColumn("Salary").isLessThan(____)
.or(employees.intColumn("Salary").isGreaterThan(____));
Table cleanedData = employees.____(outliers);
// Count rows removed after filtering
System.out.println("Employees after removing outliers: " + (employees.____() - cleanedData.____()));
// Map salaries to Junior, Mid, and Senior grades
StringColumn salaryGroup = cleanedData.intColumn("Salary").map(
salary -> {
if (salary < 100000) return "____";
else if (salary < 200000) return "Mid";
else if (salary >= 200000) return "____";
else return "Error";
},StringColumn::create).setName("SalaryGrade");
cleanedData = cleanedData.addColumns(salaryGroup);
// Filter for Mid/Senior grades under age 30
Selection highPotential = cleanedData.stringColumn("____")
.isEqualTo("Mid")
.or(cleanedData.stringColumn("SalaryGrade").isEqualTo("Senior"))
.and(cleanedData.intColumn("____").isLessThan(30));
Table highPotentialEmployees = cleanedData.where(____);
System.out.println(highPotentialEmployees.rowCount());
System.out.println(highPotentialEmployees.first(5));
}
}