Documentation
搜索文档…
Numpy Example
这是一个训练感知器(perceptron)并将结果记录到W&B的完整原始numpt代码示例。
你可以在GitHub上找到这些代码。
1
from sklearn.datasets import load_boston
2
import numpy as np
3
import wandb
4
5
wandb.init()
6
7
# Save hyperparameters
8
wandb.config.lr = 0.000001
9
wandb.config.epochs = 1
10
11
# Load Dataset
12
data, target = load_boston(return_X_y=True)
13
14
# Initialize model
15
weights = np.zeros(data.shape[1])
16
bias = 0
17
18
# Train Model
19
for _ in range(wandb.config.epochs):
20
np.random.shuffle(data)
21
for i in range(data.shape[0]):
22
x = data[i, :]
23
y = target[i]
24
25
err = y - np.dot(weights, x)
26
if (err < 0):
27
weights -= wandb.config.lr * x
28
bias -= wandb.config.lr
29
else:
30
weights += wandb.config.lr * x
31
bias += wandb.config.lr
32
33
# Log absolute error as "loss"
34
wandb.log({"Loss": np.abs(err)})
35
36
# Save Model
37
np.save("weights", weights)
38
wandb.save("weights.npy")
Copied!
最近更新 9mo ago
复制链接