# 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


# 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
import pandas as pd 
import numpy as np 
import seaborn as sns 
import matplotlib.pyplot as plt 

df=pd.read_csv('/kaggle/input/housesalesprediction/kc_house_data.csv')
df
df.head(5)
df.info()
df.describe().transpose()
df.isnull().sum()
"""
"""
 As we can see that there are no null data entry 
 

## The Data(insight )


#### Feature Columns
 
* id - Unique ID for each home sold
* date - Date of the home sale
* price - Price of each home sold
* bedrooms - Number of bedrooms
* bathrooms - Number of bathrooms, where .5 accounts for a room with a toilet but no shower
* sqft_living - Square footage of the apartments interior living space
* sqft_lot - Square footage of the land space
* floors - Number of floors
* waterfront - A dummy variable for whether the apartment was overlooking the waterfront or not
* view - An index from 0 to 4 of how good the view of the property was
* condition - An index from 1 to 5 on the condition of the apartment,
* grade - An index from 1 to 13, where 1-3 falls short of building construction and design, 7 has an average level of construction and design, and 11-13 have a high quality level of construction and design.
* sqft_above - The square footage of the interior housing space that is above ground level
* sqft_basement - The square footage of the interior housing space that is below ground level
* yr_built - The year the house was initially built
* yr_renovated - The year of the house’s last renovation
* zipcode - What zipcode area the house is in
* lat - Lattitude
* long - Longitude
* sqft_living15 - The square footage of interior housing living space for the nearest 15 neighbors
* sqft_lot15 - The square footage of the land lots of the nearest 15 neighbors

"""
"""
"""
**Exploratory data analysis **
"""
plt.figure(figsize=(12,12),edgecolor='yellow')
sns.distplot(df['price'])
sns.countplot(df['bedrooms'])
plt.figure(figsize=(12,8))
sns.scatterplot(x='price',y='sqft_living',data=df)
sns.boxplot(x='bedrooms',y='price',data=df)
"""
**Geographical Properties****
"""
plt.figure(figsize=(12,8))
sns.scatterplot(x='price',y='long',data=df)
plt.figure(figsize=(12,8))
sns.scatterplot(x='price',y='lat',data=df)
plt.figure(figsize=(12,8))
sns.scatterplot(x='long',y='lat',data=df,hue='price')
df.sort_values('price',ascending=False).head(20)
len(df)*(0.01)
non_top_1_perc = df.sort_values('price',ascending=False).iloc[216:]
non_top_1_perc
plt.figure(figsize=(12,8))
sns.scatterplot(x='long',y='lat',
                data=non_top_1_perc,hue='price',
                palette='RdYlGn',edgecolor=None,alpha=0.2)
"""
**OTHER FEATURES **
"""
sns.boxplot(x='waterfront',y='price',data=df)
"""
**WORKING WITH FEATURE DATA **
"""
df.head()
df.info()
"""
**here we dont need the id col becuase we can use the predefined index as a way to act as the primary key of the data  **
"""
df.drop(['id'],axis=1,inplace=True)
df.head(5)
"""
**Feature Engineering from date**
"""
df['date'] = pd.to_datetime(df['date'])
df['month'] = df['date'].apply(lambda date:date.month)
df['year'] = df['date'].apply(lambda date:date.year)
sns.boxplot(x='year',y='price',data=df)
sns.boxplot(x='month',y='price',data=df)
df.groupby('month').mean()['price'].plot()
df.groupby('year').mean()['price'].plot()
"""
**NOW WE DONT NEED THE DATE **
"""
df
df.columns
df['zipcode'].value_counts()
df = df.drop('zipcode',axis=1)
df.head()
df['yr_renovated'].value_counts()
df['sqft_basement'].value_counts()
"""
**SCALING AND TRAIN_TEST_SPLIT**
"""