|
| 1 | +from numpy import loadtxt, ones, zeros, array, linspace, logspace |
| 2 | +# from pylab import scatter, show, xlabel, ylabel, title, plot, contour |
| 3 | +import matplotlib.pyplot as plt |
| 4 | +import numpy as np |
| 5 | +import pandas as pd |
| 6 | +from sklearn.linear_model import LinearRegression |
| 7 | +from sklearn.model_selection import train_test_split |
| 8 | +from sklearn import metrics |
| 9 | + |
| 10 | +# Load the datasets |
| 11 | +df = pd.read_csv('USA_Housing.csv') |
| 12 | +# print(df.columns) |
| 13 | +x = df[['Avg. Area Income', 'Avg. Area House Age', 'Avg. Area Number of Rooms', |
| 14 | + 'Avg. Area Number of Bedrooms', 'Area Population']] |
| 15 | +x = df[['Avg. Area Number of Rooms', 'Avg. Area Number of Bedrooms']] |
| 16 | +y = df[['Price']] |
| 17 | + |
| 18 | +reg = LinearRegression() |
| 19 | + |
| 20 | +x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.10, random_state=2) |
| 21 | +reg.fit(x_train, y_train) |
| 22 | +print(reg.score(x_test, y_test)) |
| 23 | +print(reg.intercept_) |
| 24 | +print(reg.coef_) |
| 25 | +predictions = reg.predict(x_test) |
| 26 | +print(reg.predict([[5, 6]])) |
| 27 | + |
| 28 | +print('MAE:', metrics.mean_absolute_error(y_test, predictions)) |
| 29 | +print('MSE:', metrics.mean_squared_error(y_test, predictions)) |
0 commit comments