# Import the necessary libraries from sklearn import datasets from sklearn.model_selection import train_test_split from sklearn.linear_model import LinearRegression from sklearn.metrics import mean_squared_error # Load a sample dataset (e.g., the Boston Housing dataset) data = datasets.load_boston() X, y = data.data, data.target # Split the dataset into training and testing sets X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) # Create a linear regression model model = LinearRegression() # Train the model on the training data model.fit(X_train, y_train) # Make predictions on the test data y_pred = model.predict(X_test) # Calculate the mean squared error to evaluate the model mse = mean_squared_error(y_test, y_pred) print(f"Mean Squared Error: {mse}")