boston = pd.read_csv('boston_house.csv')
boston
boston.head()
boston.describe()
boston['MEDV']
sns.histplot(data=boston, x='MEDV')
boston.plot(kind='scatter', x='RM', y='MEDV')
boston[['MEDV', 'RM', 'AGE', 'CHAS']]
sns.pairplot(boston[['MEDV', 'RM', 'AGE', 'CHAS']])
plt.show()
boston_corr = boston[['MEDV', 'RM', 'AGE', 'CHAs']].corr()
boston_corr
plt.figure(figsize=(10,10))
sns.set(font_scale=0.6)
sns.heatmap(boston_corr, annot=True, cmap='Blues')
plt.show()
boston_corr['MEDV'][:-1].abs().sort_values(ascending=False)
X = boston.drop('MEDV', axis=1)
X
y = bosotn['MEDV']
y
X = X.values
y = y.values
print(X[:2])
print(y[:2])
from sklearn.preprocessing import MinMaxScaler
mmx = MinMaxScaler()
X = mmx.fit_transform(X)
print(X)
X.shape
dt = DecisionTreeRegressor()
dt.fit(X, y)
dt.score(X, y)
from sklearn.ensemble import RandomForestRegressor
rf = RandomForestRegressor()
rf.fit(X, y)
rf.score(X, y)
print(X[149])
print(y[149])
pred = rf.predict([X[149]])
print(pred)
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
model = Sequential()
model.add(Dense(6, activation='relu', input_shape=(13,)))
model.add(Dense(1))
model.compile(loss='mse', optimizer='adam', metrics=['mse', 'mae'])
history = model.fit(X, y, epochs=10, batch_size=8)
-improve the accuracy. increase epochs -> 50
history = model.fit(X, y, epochs=50, batch_size=8)
plt.plot(history.history['loss'], 'r')
plt.plot(history.history['mse'], 'b')
plt.title('Loss and Accuracy')
plt.xlabel("Epochs")
plt.ylabel("Loss")
plt.legent(["Loss", "MSE"])
plt.show()