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 में Anomaly Detection
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Create a list of contaminations and an empty dictionary
contaminations = ____
scores = ____