호그와트

캐글에 있는 house 데이터 실습

영웅*^%&$ 2023. 2. 2. 11:53
728x90

import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import os
os.listdir('/kaggle/input')

df = pd.read_csv('../input/house-prices-advanced-regression-techniques/train.csv')
#print(df.head())
df_features = ['LotArea', 'OverallQual', 'YearBuilt', 'TotalBsmtSF', 'GrLivArea', 'GarageCars']
y = df.SalePrice

df_features =['LotArea', 'OverallQual', 'YearBuilt', 'TotalBsmtSF', 'GrLivArea', 'GarageCars']
X = df[df_features]
X.describe()

from sklearn.tree import DecisionTreeRegressor

house_model = DecisionTreeRegressor(random_state=1)

house_model.fit(X, y)
print(X.head())
print(house_model.predict(X.head()))
print('############################')
print(y.head())

'''from sklearn.model_selection import train_test_split

# Split the data into training and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=1)

# Train the model using the training data
house_model.fit(X_train, y_train)

# Use the trained model to make predictions on the test data
y_pred = house_model.predict(X_test)'''

new_data = pd.read_csv("../input/house-prices-advanced-regression-techniques/test.csv")
new_X = new_data[df_features]
new_X = new_X.fillna(new_X.mean())  # Fill missing values with mean of each column

# Make predictions
new_predictions = house_model.predict(new_X)
print(new_predictions)

#캐글에 있는 기본 강의 내용을 많이 참고하였습니당 

728x90

'호그와트' 카테고리의 다른 글

어허 자네 웹사이트에 얼마나 있는지 좀 볼까?  (0) 2023.03.19
간단하게 요세푸스 순열 구하기  (0) 2023.02.02
알빠펫  (0) 2023.02.01
깊이 우선 탐색  (0) 2023.02.01
골드바흐의 추측 파티션 계산  (0) 2023.01.31