<jupyter_start><jupyter_text>Classification with Fashion MNIST<jupyter_code>%matplotlib inline
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

import tensorflow as tf
(X_train_full, y_train_full), (X_test, y_test) = tf.keras.datasets.fashion_mnist.load_data()
X_valid, X_train = X_train_full[:5000] / 255.0, X_train_full[5000:] / 255.0
y_valid, y_train = y_train_full[:5000], y_train_full[5000:]
class_names = ["T-shirt/top", "Trouser", "Pullover", "Dress", "Coat", "Sandal", "Shirt", "Sneaker", "Bag", "Ankle boot"]

class_names[y_train[10]]
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Flatten(input_shape=[28,28]))
model.add(tf.keras.layers.Dense(300, activation = tf.keras.activations.relu))
model.add(tf.keras.layers.Dense(100, activation = tf.keras.activations.relu))
model.add(tf.keras.layers.Dense(10, activation = tf.keras.activations.softmax))
model.summary()
model.get_layer("dense_2").get_weights()[0].shape
model.compile(loss=tf.keras.losses.sparse_categorical_crossentropy, 
              optimizer=tf.keras.optimizers.SGD(), 
              metrics=[tf.keras.metrics.sparse_categorical_accuracy])
history = model.fit(X_train, y_train, epochs=50, validation_data=(X_valid, y_valid))
history.history
pd.DataFrame(history.history).plot(figsize=(10, 6))
model.evaluate(X_test, y_test)
X_new = X_test[:10]
y_proba = model.predict(X_new)
y_proba.round(2)
y_pred = model.predict_classes(X_new)
y_pred
 np.array(class_names)[y_pred]<jupyter_output><empty_output><jupyter_text>Regression with California Houses<jupyter_code>from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
housing = fetch_california_housing()
X_train_full, X_test, y_train_full, y_test = train_test_split(housing.data, housing.target)
X_train, X_valid, y_train, y_valid = train_test_split(X_train_full, y_train_full)
scaler = StandardScaler()
X_train_scaled = scaler.fit_transform(X_train)
X_valid_scaled = scaler.transform(X_valid)
X_test_scaled = scaler.transform(X_test)
regModel = tf.keras.models.Sequential([
    tf.keras.layers.Dense(30, activation=tf.keras.activations.relu, input_shape=X_train.shape[1:]),
    tf.keras.layers.Dense(1)
])
regModel.compile(loss=tf.keras.losses.mean_squared_error, optimizer=tf.keras.optimizers.SGD())
history = regModel.fit(X_train, y_train, epochs=20, validation_data=(X_valid, y_valid))
history.history
mse_test = regModel.evaluate(X_test, y_test)
X_new = X_test[:3] # pretend these are new instances1
y_pred = regModel.predict(X_new)
y_pred<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12984054669703873, 'fraction_numerical': 0.02126044039483675, 'mean_word_length': 7.39171974522293, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '520930', 'license': 'MIT', 'n_tokens_mistral': 1041, 'n_tokens_neox': 995, 'n_words': 150, 'path': 'neural-networks/neural-networks.ipynb', 'repo_name': 'VladiGGeorgiev/ml-playground', 'size': '2634'}