could you illustrate what residual plots for diagnosing liner regression
- User
could you illustrate what residual plots for diagnosing liner regression
- Assistant
- User
and, what's normality tests
- Assistant
- User
what do the following python code do ?
import numpy as np import matplotlib.pyplot as plt
Seed for reproducibility
np.random.seed(42)
Generate a dataset that satisfies the linearity assumption
X_linear = np.linspace(0, 10, 100) y_linear = 2 * X_linear + np.random.normal(0, 1, 100)
Generate a dataset that violates the linearity assumption
X_nonlinear = np.linspace(0, 10, 100) y_nonlinear = 2 * X_nonlinear**2 + np.random.normal(0, 5, 100)
Plotting the datasets in subplots
plt.figure(figsize=(12, 6))
Plot for the linear dataset
plt.subplot(1, 2, 1) plt.scatter(X_linear, y_linear, label='Linear Data', color='blue') plt.plot(X_linear, 2 * X_linear, color='red', label='True Relationship') plt.xlabel('Independent Variable') plt.ylabel('Dependent Variable') plt.title('Linear Relationship') plt.legend() plt.grid(True)
Plot for the nonlinear dataset
plt.subplot(1, 2, 2) plt.scatter(X_nonlinear, y_nonlinear, label='Nonlinear Data', color='green') plt.plot(X_nonlinear, 2 * X_nonlinear**2, color='red', label='True Relationship') plt.xlabel('Independent Variable') plt.ylabel('Dependent Variable') plt.title('Nonlinear Relationship') plt.legend() plt.grid(True)
Adjust layout for better spacing
plt.tight_layout()
- Assistant