<jupyter_start><jupyter_text>Problem Statement > Should a potential investor invest in 3 bedrooms or 4 bedrooms?  Dataset  Import liberies<jupyter_code>import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Load the dataset<jupyter_code>df = pd.read_csv('kc_house_data.csv')<jupyter_output><empty_output><jupyter_text>Checking the Data<jupyter_code># Determining number of records in the dataset
rows = df.shape[0]
columns = df.shape[1]
print(f'{rows} rows \n {columns} columns')
#Previewing the head of the dataset
df.head()
#Previewing the tail of the dataset
df.tail()
# Checking dataset information
df.info()
# Checking whether each column has an appropriate datatype
df.dtypes
#Checking for Unique Values
df.nunique()
# Checking the columns in the dataset
df.columns<jupyter_output><empty_output><jupyter_text>Data Cleaning<jupyter_code>#Checking for null values
df.isnull().sum()
#Checking for Duplicates
df.duplicated().sum().any()
# Checking dataset information
df.info()
#Changing the values of date column
df['date'] = pd.to_datetime(df['date'])
df.bathrooms.value_counts()
df['bathrooms'] = df.bathrooms.astype(int)
df['bathrooms'].value_counts()
df['floors'] = df.floors.astype(int)
df.head()
df.to_csv('unreal.csv')<jupyter_output><empty_output><jupyter_text>Exploratory Data Analysis  Univariate<jupyter_code>df.columns
df['floors'].value_counts().plot(kind='bar')
df['bathrooms'].value_counts().plot(kind='bar')
df['bedrooms'].value_counts().plot(kind='bar')
df['price'].mean()
df['bedrooms'].mode()[0]
df['bathrooms'].mode()[0]
df.head()
df_1 = df.drop(['id', 'date', 'lat', 'long', 'zipcode'], axis=1)

names = list(df_1.columns)
fig, axes = plt.subplots(8,2, figsize=(20,20) )  

y = 0
for name in names:
  i, j = divmod(y, 2)
  sns.boxplot(x=df[name], ax=axes[i, j])
  axes[i, j].set_title(f'Box plot of {name}', fontsize=20)
  axes[i, j].set_xlabel(name, fontsize=15)
  y+=1

plt.tight_layout()
plt.show()<jupyter_output><empty_output><jupyter_text>Bivariate<jupyter_code><jupyter_output><empty_output><jupyter_text>Multivariate Analysis Factor Analysis<jupyter_code>df_2 = df.drop(['price','id', 'date', 'lat', 'long', 'zipcode', 'yr_built', 'yr_renovated'], axis=1)
df_2.head()
# Installing factor analyzer 
!pip install factor_analyzer==0.2.3


from factor_analyzer.factor_analyzer import calculate_bartlett_sphericity

chi_square_value,p_value=calculate_bartlett_sphericity(df_2)
chi_square_value, p_value
from factor_analyzer.factor_analyzer import calculate_kmo

kmo_all,kmo_model=calculate_kmo(df_2)
kmo_all,kmo_model
#import factor_analyzer as FactorAnalyzer
from factor_analyzer import FactorAnalyzer
# Creating factor analysis object and perform factor analysis
fa = FactorAnalyzer()
fa.analyze(df_2, 13, rotation=None)

# Checking the Eigenvalues
ev, v = fa.get_eigenvalues()
ev
# Creating a scree plot using matplotlib
#
plt.scatter(range(1,df_2.shape[1]+1),ev)
plt.plot(range(1,df_2.shape[1]+1),ev)
plt.title('Scree Plot')
plt.xlabel('Factors')
plt.ylabel('Eigenvalue')
plt.grid()
plt.show()
# Step 12: Performing Factor Analysis
# Creating factor analysis object and perform factor analysis
#
fa = FactorAnalyzer()
fa.analyze(df_2, 4, rotation="varimax")
fa.loadings
# Step 14: Getting variance of each factors
# 
fa.get_factor_variance()<jupyter_output><empty_output><jupyter_text>Hypothesis testing<jupyter_code><jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13674472390864412, 'fraction_numerical': 0.013587742122000578, 'mean_word_length': 7.804071246819339, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '252597', 'license': 'MIT', 'n_tokens_mistral': 1330, 'n_tokens_neox': 1267, 'n_words': 269, 'path': 'Real_Estate_Notebook.ipynb', 'repo_name': 'JeromeMberia/Unreal', 'size': '3459'}