#!/usr/bin/env python
# coding: utf-8
#
#
Introduction to Kaggle
#
# In[ ]:
# This Python 3 environment comes with many helpful analytics libraries installed
# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python
# For example, here's several helpful packages to load
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
# Input data files are available in the read-only "../input/" directory
# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory
import os
for dirname, _, filenames in os.walk('/kaggle/input'):
for filename in filenames:
print(os.path.join(dirname, filename))
# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using "Save & Run All"
# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session
data = pd.read_csv('https://www.kaggle.com/housing-prices-dataset/Housing.csv')
X = data[['price', 'area', 'bedrooms', 'bathrooms', 'stories']].to_numpy()
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error
Xscaled = StandardScaler().fit_transform(X)
from sklearn.model_selection import train_test_split
Xtrain, Xtest, ytrain, ytest = train_test_split(Xscaled[:, 1:],Xscaled[:,0])
numXP = 100
MSE = np.zeros((4,numXP))
for xp in np.arange(numXP):
for k in np.arange(1,5):
reg = LinearRegression().fit(Xtrain[:,0:k], ytrain)
prediction = reg.predict(Xtest[:,0:k])
MSE[k-1,xp] = mean_squared_error(ytest, prediction)
import matplotlib.pyplot as plt
plt.plot(np.mean(MSE, axis=1))
plt.show()