-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhousing.py
More file actions
37 lines (29 loc) · 1.28 KB
/
Copy pathhousing.py
File metadata and controls
37 lines (29 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
data = pd.read_csv('housing.csv')
# print(data.head())
# data.info()
data = pd.DataFrame(data)
# print(data[data.isna().any(axis=1)])
#Khoi tao khung bieu do 4 hang 3 cot, kich thuoc frame la 15x15 inch
fig,axes = plt.subplots(4,3,figsize=(15,10))
axes = axes.flatten() #Chuyen mang 2 chieu thanh 1 chieu
#Loc ra cac cot co dinh dang la so thuc hoac so nguyen
num_cols = data.select_dtypes(include=['float64','int64']).columns
#ax = axes[i]: ve bieu do histogram tren o thu i cua khung bieu do
for i, col in enumerate(num_cols):
sns.histplot(data[col], ax=axes[i], kde=True, color = 'Green', bins= 30)
axes[i].set_title(f'Histogram of {col}', fontsize =12)
axes[i].set_xlabel('')
axes[i].set_ylabel('Frequency')
sns.countplot(x='ocean_proximity', data=data, ax=axes[9], color = 'Green')
axes[9].set_title('Countplot of ocean_proximity', fontsize = 10, fontweight = 'bold')
axes[9].tick_params(axis='x', rotation = 30)
for j in range(10,12):
fig.delaxes(axes[j]) #Xoa o thu j trong khung bieu do
plt.tight_layout() #Can chinh lai khung bieu do de cac o khong bi che khuất
plt.show()