Dalam dunia hartanah, penentuan harga hartanah melibatkan pelbagai faktor, daripada lokasi dan saiz kepada kemudahan dan trend pasaran. Regresi linear mudah, teknik asas dalam pembelajaran mesin, menyediakan cara praktikal untuk meramalkan harga perumahan berdasarkan ciri utama seperti bilangan bilik atau rakaman persegi.
Dalam artikel ini, saya menyelidiki proses menggunakan regresi linear ringkas pada set data perumahan, daripada prapemprosesan data dan pemilihan ciri kepada membina model yang boleh menawarkan cerapan harga yang berharga. Sama ada anda baharu dalam sains data atau ingin mendalami pemahaman anda, projek ini berfungsi sebagai penerokaan langsung tentang cara ramalan terdorong data boleh membentuk keputusan hartanah yang lebih bijak.
Perkara pertama dahulu, anda mulakan dengan mengimport perpustakaan anda:
import pandas as pd import seaborn as sns import numpy as np import matplotlib.pyplot as plt
#Read from the directory where you stored the data data = pd.read_csv('/kaggle/input/california-housing-prices/housing.csv')
data
#Test to see if there arent any null values data.info()
#Trying to draw the same number of null values data.dropna(inplace = True)
data.info()
#From our data, we are going to train and test our data from sklearn.model_selection import train_test_split X = data.drop(['median_house_value'], axis = 1) y = data['median_house_value']
y
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2)
#Examining correlation between x and y training data train_data = X_train.join(y_train)
train_data
#Visualizing the above train_data.hist(figsize=(15, 8))
#Encoding non-numeric columns to see if they are useful and categorical for analysis train_data_encoded = pd.get_dummies(train_data, drop_first=True) correlation_matrix = train_data_encoded.corr() print(correlation_matrix)
train_data_encoded.corr()
plt.figure(figsize=(15,8)) sns.heatmap(train_data_encoded.corr(), annot=True, cmap = "inferno")
import pandas as pd import seaborn as sns import numpy as np import matplotlib.pyplot as plt
#Read from the directory where you stored the data data = pd.read_csv('/kaggle/input/california-housing-prices/housing.csv')
data
kehampiran_laut
DALAM 5183
NEAR OCEAN 2108
NEAR BAY 1783
PULAU 5
Nama: count, dtype: int64
#Test to see if there arent any null values data.info()
#Trying to draw the same number of null values data.dropna(inplace = True)
data.info()
#From our data, we are going to train and test our data from sklearn.model_selection import train_test_split X = data.drop(['median_house_value'], axis = 1) y = data['median_house_value']
y
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2)
#Examining correlation between x and y training data train_data = X_train.join(y_train)
train_data
#Visualizing the above train_data.hist(figsize=(15, 8))
#Encoding non-numeric columns to see if they are useful and categorical for analysis train_data_encoded = pd.get_dummies(train_data, drop_first=True) correlation_matrix = train_data_encoded.corr() print(correlation_matrix)
train_data_encoded.corr()
plt.figure(figsize=(15,8)) sns.heatmap(train_data_encoded.corr(), annot=True, cmap = "inferno")
train_data['total_rooms'] = np.log(train_data['total_rooms'] + 1) train_data['total_bedrooms'] = np.log(train_data['total_bedrooms'] +1) train_data['population'] = np.log(train_data['population'] + 1) train_data['households'] = np.log(train_data['households'] + 1)
train_data.hist(figsize=(15, 8))
0.5092972905670141
#convert ocean_proximity factors into binary's using one_hot_encoding train_data.ocean_proximity.value_counts()
#For each feature of the above we will then create its binary(0 or 1) pd.get_dummies(train_data.ocean_proximity)
0.4447616558596853
#Dropping afterwards the proximity train_data = train_data.join(pd.get_dummies(train_data.ocean_proximity)).drop(['ocean_proximity'], axis=1)
train_data
#recheck for correlation plt.figure(figsize=(18, 8)) sns.heatmap(train_data.corr(), annot=True, cmap ='twilight')
0.5384474921332503
Saya benar-benar akan mengatakan bahawa melatih mesin bukanlah proses yang paling mudah tetapi untuk terus meningkatkan hasil di atas, anda boleh menambah lebih banyak ciri di bawah param_grid seperti min_feature dan dengan cara itu skor penganggar terbaik anda boleh terus meningkat.
Jika anda sampai sejauh ini sila like dan kongsi komen anda di bawah, pendapat anda sangat penting. Terima kasih!??❤️
Atas ialah kandungan terperinci Ramalan_Harga_Rumah. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!