การปรับแต่งค่า contamination
ถึงเวลาปรับแต่งพารามิเตอร์ contamination ที่สำคัญแล้ว ฟังก์ชัน evaluate_outlier_classifier และ evaluate_regressor จากวิดีโอถูกโหลดไว้ให้แล้ว ดูโค้ดด้านล่างได้เลย
def evaluate_outlier_classifier(model, data):
# Get labels
labels = model.fit_predict(data)
# Return inliers
return data[labels == 0]
def evaluate_regressor(inliers):
X = inliers.drop("price", axis=1)
y = inliers[['price']]
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=10)
lr = LinearRegression()
lr.fit(X_train, y_train)
preds = lr.predict(X_test)
rmse = root_mean_squared_error(y_test, preds)
return round(rmse, 3)
ในแบบฝึกหัดนี้จะใช้ข้อมูลตัวอย่างจากชุดข้อมูล US Airbnb Listings ซึ่งโหลดไว้แล้วในชื่อ airbnb_df
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การตรวจจับความผิดปกติใน Python
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Create a list of contaminations and an empty dictionary
contaminations = ____
scores = ____