keras 를 이용한 다중 선형 회귀

By | 2020년 4월 4일
Table of Content

keras 를 이용한 다중 선형 회귀

from keras.models import Sequential
from keras.layers import Dense
from sklearn.model_selection import train_test_split
import pandas as pd

df = pd.read_csv("/home/ubuntu/workspace/datasets/streeteasy/manhattan.csv")
# df.head()

X = df[['bedrooms',
        'bathrooms',
        'size_sqft',
        'min_to_subway',
        'floor',
        'building_age_yrs',
        'no_fee',
        'has_roofdeck',
        'has_washer_dryer',
        'has_doorman',
        'has_elevator',
        'has_dishwasher',
        'has_patio',
        'has_gym']]
y = df[['rent']]

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)

model = Sequential()
model.add(Dense(30, input_dim=14, activation='relu'))
model.add(Dense(6, activation='relu'))
model.add(Dense(1))

model.compile(loss='mean_squared_error', optimizer='adam')

model.fit(X_train, y_train, epochs=200, batch_size=10)

score = model.evaluate(X_test, y_test, batch_size=10)
print('Test score:', score)

y_prediction = model.predict(X_test).flatten()
y_test = y_test.values

for i in range(10):
    real_price = y_test[i][0]
    predicted_price = y_prediction[i]
    print('Real Price: {:.3f}, Predicted Price: {:.3f}'.format(real_price, predicted_price))
Category: ML

답글 남기기