<jupyter_start><jupyter_text>Train Test Split ---<jupyter_code>X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = 0)<jupyter_output><empty_output><jupyter_text>Scaling the data---<jupyter_code>from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
X = scaler.fit_transform(X)
X_test = scaler.transform(X_test)
X_train = scaler.transform(X_train)<jupyter_output><empty_output><jupyter_text>Keras model<jupyter_code>import keras
from keras.models import Sequential
from keras.layers import Dense<jupyter_output>Using TensorFlow backend.
/anaconda3/lib/python3.7/importlib/_bootstrap.py:219: RuntimeWarning: compiletime version 3.6 of module 'tensorflow.python.framework.fast_tensor_util' does not match runtime version 3.7
  return f(*args, **kwds)<jupyter_text>Initialize the model and add layers---<jupyter_code>model = Sequential()

# input layer
# units is the number of nodes in hidden layer
# input dimension is the number of features and define them once in the input layer
model.add(Dense(activation="linear", input_dim=13, units=1, kernel_initializer="uniform"))

# Adding output layer
# model.add(Dense(activation="linear", units=1, kernel_initializer="uniform"))<jupyter_output><empty_output><jupyter_text>Compiling the model<jupyter_code># Compile our ANN with Adam GD, Mean Squared Error error metric, and we are optimizing for accuracy
model.compile(optimizer='adam', loss='mse', metrics=['mse'])
# Reminder: batch size is a hyperparameter that defines the number of samples to work 
# through before updating the internal model parameters
# For the difference between epochs and batchsize, 
# read: https://machinelearningmastery.com/difference-between-a-batch-and-an-epoch/

# Fitting the ANN to the training set
model.fit(X_train, y_train, batch_size = 1, epochs=200)<jupyter_output>Epoch 1/200
379/379 [==============================] - 1s 1ms/step - loss: 585.1365 - mean_squared_error: 585.1365
Epoch 2/200
379/379 [==============================] - 0s 1ms/step - loss: 561.7133 - mean_squared_error: 561.7133
Epoch 3/200
379/379 [==============================] - 0s 1ms/step - loss: 540.0371 - mean_squared_error: 540.0371: 0s - loss: 558.0238 - mean_squared_error: 55
Epoch 4/200
379/379 [==============================] - 0s 1ms/step - loss: 519.6475 - mean_squared_error: 519.6475
Epoch 5/200
379/379 [==============================] - 0s 870us/step - loss: 500.4025 - mean_squared_error: 500.4025
Epoch 6/200
379/379 [==============================] - 0s 1ms/step - loss: 482.0972 - mean_squared_error: 482.0972
Epoch 7/200
379/379 [==============================] - 0s 1ms/step - loss: 464.6595 - mean_squared_error: 464.6595
Epoch 8/200
379/379 [==============================] - 0s 926us/step - loss: 447.9399 - mean_squared_error: 447.9399
Epoch 9/200
379/379 [=========[...]<jupyter_text>Predicting the model<jupyter_code>y_pred = model.predict(X_test)<jupyter_output><empty_output><jupyter_text>Evaluate the model accuracy with ANN<jupyter_code>r2_score(y_test, y_pred)
# different way of evaluating the keras model
# ask milad how to use keras model.evaluate function
# score = model.evaluate(y_test, y_pred, batch_size=1)<jupyter_output><empty_output><jupyter_text>Let's compare ANN to sklearn linear regression---<jupyter_code>linear_reg = LinearRegression().fit(X_train, y_train)
linear_reg.score(X_test, y_test)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17520372526193248, 'fraction_numerical': 0.07450523864959255, 'mean_word_length': 6.3283582089552235, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '647176', 'license': 'MIT', 'n_tokens_mistral': 1373, 'n_tokens_neox': 1132, 'n_words': 279, 'path': 'Homework/HW-1/boston_housing_with_keras.ipynb', 'repo_name': 'Sukhrobjon/DS-2.2-DL', 'size': '3436'}