text_plain_output_1.png
from sklearn import metrics

from sklearn.linear_model import LinearRegression

from sklearn.linear_model import Ridge

from sklearn.linear_model import Ridge

import matplotlib.pyplot as plt

import matplotlib.pyplot as plt

import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import seaborn as sns

names = ['CRIM', 'ZN', 'INDUS', 'CHAS', 'NOX', 'RM', 'AGE', 'DIS', 'RAD', 'TAX', 'PTRATIO', 'B', 'LSTAT', 'MEDV']
data_df = pd.read_csv('/kaggle/input/boston-house-prices/housing.csv', header=None, delim_whitespace=True, names=names)

data_df.isnull().sum()

data_df.duplicated().any()

import matplotlib.pyplot as plt
import seaborn as sns

from sklearn.linear_model import LinearRegression
lr_all = LinearRegression()
lr_all.fit(X_train, y_train)
y_pred1 = lr_all.predict(X_test)

lr_all.intercept_

lr_all_coeffcients = pd.DataFrame([X_train.columns, lr_all.coef_]).T
lr_all_coeffcients = lr_all_coeffcients.rename(columns={0: 'Attribute', 1: 'Coefficients'})
lr_all_coeffcients

lr_all.score(X_test, y_test)

from sklearn import metrics

from sklearn.linear_model import Ridge
rr1 = Ridge(alpha=0.01)
rr1.fit(X_train, y_train)
rr2 = Ridge(alpha=100)
rr2.fit(X_train, y_train)

import matplotlib.pyplot as plt
plt.plot(names[0:13], lr_all.coef_, alpha=0.4, linestyle='none', marker='o', markersize=7, color='green', label='Linear Regression')
plt.plot(names[0:13], rr1.coef_, alpha=0.4, linestyle='none', marker='*', markersize=7, color='red', label='Ridge;$\\alpha=0.01$')
plt.plot(names[0:13], rr2.coef_, alpha=0.4, linestyle='none', marker='d', markersize=7, color='blue', label='Ridge;$\\alpha=100$')
plt.xlabel('Coefficient Index', fontsize=16)
plt.ylabel('Coefficient Magnitude', fontsize=16)
plt.legend(fontsize=13, loc=4)
plt.show()