@TOC
一、导包
import pathlib
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
import numpy as np
二、加载数据
# 100个用户,300个物品
data = pd.DataFrame(np.random.randint(5, size=(100, 300)))
三、构建模型
def build_model():
model = keras.Sequential([
layers.Dense(100, activation = 'relu', input_shape=[100]),
layers.Dense(100, activation = 'relu'),
])
optimizer = tf.keras.optimizers.RMSprop(0.001)
model.compile(loss = 'mse',
optimizer = optimizer,
metrics = ['mae', 'mse'])
return model
model = build_model()
model.summary()
四、训练数据
train_data = data.T
EPOCHS = 500
model.fit(train_data,
train_data,
epochs = EPOCHS,
validation_split = 0.1,
verbose = 0)
五、预测结果
pd.DataFrame(model.predict(train_data).T)