Colab/머신러닝

04. 선형회귀(linear regression) - 학습, 테스트

HicKee 2023. 3. 2. 16:07
df = pd.read_csv('/content/drive/MyDrive/sample_data/manhattan.csv')  # 맨하탄 입대료
df

df.info()
# rent 타겟 독립변수
df.describe()

#  rent 임대료, bedrooms 침실수,bathrooms  화장실수,size_sqft,  
# 평수 feet,min_to_subway 지하철과의 거리,floor 층수,building_age_yrs 건축된 연도,
#no_fee 수수료,has_roofdeck 옥상,has_washer_dryer 세탁기 건조기,has_doorman 도어맨,
#has_elevator 엘리베이터,has_dishwasher 식기세척기,has_patio 마당 ,has_gym 체육관, 
#헬스장,neighborhood 이웃,borough 자치구
 
 

임대료 예측

# y = b +  a1x1 + a2x2 + a3x3 + ... + anxn
# a1,a2 ... an : 회귀계수
# b 절편 bias

from sklearn.model_selection import train_test_split
y = df[['rent']]  # 타겟, 정답
X = df.drop(['rent','rental_id','neighborhood','borough'], axis=1) # rent 삭제
# df.drop(['neighborhood','borough'])
X
 
 

학습 데이터 , 테스트 데이터 분리해야 한다

x_train, x_test, y_train, y_test = train_test_split(X,y,train_size=0.8, test_size=0.2)
# 과적합(특정데이터 만을 이한 )을 막기위해서 8 : 2 
x_train
y_train
 

모델 생성