Ds Prac 6
Ds Prac 6
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error, r2_score
# Example dataset
data = {'X': np.random.rand(100), 'Y': np.random.rand(100)}
df = pd.DataFrame(data)
# The coefficients
print('Coefficients:', regr.coef_)
print('Intercept:', regr.intercept_)
# Plot outputs
plt.scatter(X_test, Y_test, color='black')
plt.plot(X_test, Y_pred, color='blue', linewidth=3)
plt.title('Simple Linear Regression Results')
plt.xlabel('X')
plt.ylabel('Y')
plt.show()
--------Multiple linear regression
# The coefficients
print('Coefficients:', regr_multi.coef_)
print('Intercept:', regr_multi.intercept_)
# Note: We cannot plot a 3D plane easily here, so we'll skip the plot for the
multiple regression.