def test_peplot_no_lines(self): """ Test image similarity with no lines drawn on the plot """ visualizer = PredictionError(Lasso(random_state=23, alpha=10), bestfit=False, identity=False) visualizer.fit(self.data.X.train, self.data.y.train) visualizer.score(self.data.X.test, self.data.y.test) visualizer.finalize() self.assert_images_similar(visualizer, tol=1.0, remove_legend=True)
def test_peplot_shared_limits(self): """ Test shared limits on the peplot """ visualizer = PredictionError(LinearRegression(), shared_limits=False) visualizer.fit(self.data.X.train, self.data.y.train) visualizer.score(self.data.X.test, self.data.y.test) visualizer.finalize() xlim = tuple(map(int, visualizer.ax.get_xlim())) ylim = tuple(map(int, visualizer.ax.get_ylim())) assert xlim == ylim
def test_prediction_error(self): """ Test image similarity of prediction error on random data """ _, ax = plt.subplots() model = MLPRegressor(random_state=229) visualizer = PredictionError(model, ax=ax) visualizer.fit(self.data.X.train, self.data.y.train) visualizer.score(self.data.X.test, self.data.y.test) visualizer.finalize() self.assert_images_similar(visualizer, tol=1, remove_legend=True)
def test_peplot_no_shared_limits(self): """ Test image similarity with no shared limits on the peplot """ visualizer = PredictionError(Ridge(random_state=43), shared_limits=False) visualizer.fit(self.data.X.train, self.data.y.train) visualizer.score(self.data.X.test, self.data.y.test) visualizer.finalize() xlim = tuple(map(int, visualizer.ax.get_xlim())) ylim = tuple(map(int, visualizer.ax.get_ylim())) assert not xlim == ylim self.assert_images_similar(visualizer, tol=1.0, remove_legend=True)
def test_prediction_error_pandas(self): """ Test Pandas real world dataset with image similarity on Ridge """ _, ax = plt.subplots() # Load the occupancy dataset from fixtures data = load_energy(return_dataset=True) X, y = data.to_pandas() # Create train/test splits splits = tts(X, y, test_size=0.2, random_state=8873) X_train, X_test, y_train, y_test = splits visualizer = PredictionError(Ridge(random_state=22), ax=ax) visualizer.fit(X_train, y_train) visualizer.score(X_test, y_test) visualizer.finalize() self.assert_images_similar(visualizer, tol=1, remove_legend=True)