Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.3 kB
3
Indexable
Never
import pandas as pd
from sklearn import preprocessing
from keras.api.models import Sequential
from keras.api.layers import Dense
import matplotlib.pyplot as plt
dh = pd.read_csv('housepricedata.csv')
datahouse = dh.values
X = datahouse[:,0:10]
Y = datahouse[:,10]
min_max_scaler = preprocessing.MinMaxScaler()
X_scale = min_max_scaler.fit_transform(X)
X_scale
from sklearn.model_selection import train_test_split
X_train, X_val_and_test, Y_train, Y_val_and_test = train_test_split(X_scale, Y, test_size = 0.3)
X_val, X_test, Y_val, Y_test = train_test_split(X_val_and_test, Y_val_and_test, test_size = 0.5)
print(X_train.shape, X_val.shape, X_test.shape, Y_train.shape, Y_val.shape, Y_test.shape)

model = Sequential([
    Dense(100, activation='relu', input_shape=(10,)),
    Dense(100, activation='relu'),
    Dense(1, activation='sigmoid'),
])

model.compile(optimizer='sgd', loss='binary_crossentropy' , metrics=['accuracy'])
hist = model.fit(X_train, Y_train,
                 batch_size=32, epochs=100,
                 validation_data=(X_val, Y_val))
plt.plot(hist.history['loss'])
plt.plot(hist.history['val_loss'])
plt.title('Model loss')
plt.ylabel('Loss')
plt.xlabel('Epoch')
plt.legend(['Train', 'Val'], loc='upper right')
plt.show()
model.evaluate(X_test, Y_test)[1]
Leave a Comment