Bắt đầu ngayBắt đầu miễn phí

Tinh chỉnh contamination

Cuối cùng cũng đến lúc tinh chỉnh tham số contamination “khó nhằn”. Hai hàm evaluate_outlier_classifierevaluate_regressor trong video đã được nạp sẵn cho bạn. Bạn có thể xem chúng bên dưới.

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)

Bạn sẽ sử dụng một mẫu của bộ dữ liệu US Airbnb Listings, đã được nạp sẵn dưới tên airbnb_df.

Bài tập này là một phần của khóa học

Phát hiện bất thường với Python

Xem khóa học

Bài tập tương tác thực hành trực tiếp

Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.

# Create a list of contaminations and an empty dictionary
contaminations = ____
scores = ____
Chỉnh sửa và Chạy Mã