Ejemplo n.º 1
0
 def test_residuals_quick_method_missing_data(self):
     """
     Ensure the quick method requires both X_test and y_test if one specified
     """
     msg = "both X_test and y_test are required if one is specified"
     with pytest.raises(YellowbrickValueError, match=msg):
         residuals_plot(Lasso(), self.data.X.train, self.data.y.train,
                        self.data.X.test)
Ejemplo n.º 2
0
    def test_residuals_quick_method_train_only(self):
        """
        Test the quick method with only train data (simplest args)
        """
        oz = residuals_plot(Ridge(random_state=19), self.data.X.train,
                            self.data.y.train)

        assert isinstance(oz, ResidualsPlot)
        self.assert_images_similar(oz)
Ejemplo n.º 3
0
    def test_residuals_quick_method(self):
        """
        Image similarity test using the residuals plot quick method
        """
        _, ax = plt.subplots()

        model = Lasso(random_state=19)
        oz = residuals_plot(
            model,
            self.data.X.train,
            self.data.y.train,
            self.data.X.test,
            self.data.y.test,
            ax=ax,
            line_color="#cccccc",
            test_color="r",
            train_color="y",
        )

        assert isinstance(oz, ResidualsPlot)
        self.assert_images_similar(oz)
Ejemplo n.º 4
0
                                   scoring="neg_root_mean_squared_error")

# Uruchomienie procedury wyszukiwania hyperparametrów
random_search.fit(X_train, y_train)

# Wyświetlenie rezultatów dla poszczególnych prób hyperparametrów
pd.DataFrame(random_search.cv_results_).sort_values("rank_test_score")

# Przypisanie najlepszego, wytrenowanego modelu do zmiennej
best_model = random_search.best_estimator_

# Obliczenie metryk MAPE i RMSE korzystając z funkcji calculate_metrics
calculate_metrics(best_model, X_train, y_train, X_test, y_test)

# Wykres reszt
residuals_plot(best_model, X_train, y_train, X_test, y_test)

# Wykres błędów predykcji
prediction_error(best_model, X_train, y_train, X_test, y_test)

# Próba usunięcia wartości odstających dla zmiennej celu
df_for_modelling_outliers_index = df_for_modelling.copy()
df_for_modelling_outliers_index["zscore"] = zscore(
    df_for_modelling_outliers_index["cena_metr"])

# Wskazanie obserwacji, których moduł wartości zscore przekracza 3 - wartości odstające
outliers_indices = df_for_modelling_outliers_index["zscore"].abs() >= 3

# +
display(df_for_modelling_outliers_index[outliers_indices])