# Matlab代写，计算机作业代写，高分原创代码

• 计算梯度（斜率），即函数在该点的一阶导数
• 在与梯度相反的方向上迈出一步（移动），斜率的相反方向从当前点增加 alpha 乘以该点的梯度

## 计算机作业代写：使用GD、SGD、ALS方法优化矩阵分解

#### Two datasets are given for you to test your model performance.

1. Optimize Matrix Factorization using GD, SGD, ALS method, using the same set of hyperparameters.
2. Please, visualize the loss history with respect to the iterations to ensure your model is converged within num_iter , the number of iteration you set.
3. Then, report final loss for all methods, and training time. And write a short explanation for your results.
4. set the number of latent factor be 2. ### Visualization Requirement:
5. Please use the same learning rate for both GD and SGD. and choose a relatively suitable value for both of them.
6. Display the training curve in the same graph. Using different colors to represent different optimization method.

#### 1. Toy example

Apart from the general requirements from Part 3, print the matrix factorization result U, and V (User-Feature Matrix, and Item-Feature matrix) for the toy example for each optimization method, respectively.

Below is the data and sample code ).

``````In [ ]:
d = {'item0': [np.nan, 7, 6, 1, 1,5],
'item1': [3, 6, 7, 2, np.nan, 4],
'item2': [3, 7, np.nan, 2, 1,5],
'item3': [1, 4, 4, 3, 2, 3],
'item4': [1, 5, 3, 3, 3, 4],
'item5': [np.nan, 4, 4, 4, 3, 2]}
df = pd.DataFrame(data=d).astype('float32')
X = np.array(df)
#
MF_GD = MatrixFactor(k = 2, opt_method = 'GD', learn_rt = 0.001, num_iter=200
U_GD, VT_GD, loss_hist_GD = MF_GD.fit(X)
``````
``````In [ ]:
print(U_GD, "\nuser-feature matrix using GD")
print(np.transpose(U_GD), "\nitem-feature matrix using GD")``````
``````[[0.79494786 0.78902942]
[1.62009744 2.42686695]
[1.87025306 1.85810683]
[0.71288845 0.98068888]
[1.12185167 0.51928559]
[0.83894803 1.90538961]]
user-feature matrix using GD
[[0.79494786 1.62009744 1.87025306 0.71288845 1.12185167 0.83894803]
[0.78902942 2.42686695 1.85810683 0.98068888 0.51928559 1.90538961]]
item-feature matrix using GD``````
``````In [ ]: import matplotlib.cm as cm
import matplotlib.pyplot as plt
plt.scatter(range(len(loss_hist_GD)), loss_hist_GD, label='GD' )
plt.legend()
``````
``Out[ ]:<matplotlib.legend.Legend at 0x7f9cf2cc6bd0>``

## Recent Case

### 盘点留学生常用5 种最佳笔记方法，哪一种适合您

SCI期刊论文的发表过程是一项复杂而细致的工作，涉

### 轻松掌握万能Essay模板，撰写一篇合格的英文论文

Python可谓是当下最火的编程语言，同时，Pyt