Skip to content

Commit 3ecfdeb

Browse files
Programmer-RD-AIProgrammer-RD-AI
andcommitted
02
Co-Authored-By: Ranuga <[email protected]>
1 parent 5d1ecd1 commit 3ecfdeb

File tree

3 files changed

+524
-44
lines changed

3 files changed

+524
-44
lines changed

.ipynb_checkpoints/02-checkpoint.ipynb

Lines changed: 239 additions & 20 deletions
Large diffs are not rendered by default.

.virtual_documents/02.ipynb.py

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
from sklearn.datasets import make_circles
33
# Make 100 Samples
44
n_samples = 10000
5-
X,y = make_circles(n_samples,noise=0.069,random_state=42)
5+
X,y = make_circles(n_samples,noise=0.125,random_state=42)
66

77

88
import matplotlib.pyplot as plt
99
import numpy as np
1010
import torch
11+
device = 'cuda' if torch.cuda.is_available() else 'cpu'
1112

1213

1314
X[:5],y[:5]
@@ -37,8 +38,8 @@
3738
X.dtype
3839

3940

40-
X = torch.from_numpy(X).type(torch.float32)
41-
y = torch.from_numpy(y).type(torch.float32)
41+
X = torch.from_numpy(X).type(torch.float32).to(device)
42+
y = torch.from_numpy(y).type(torch.float32).to(device)
4243

4344

4445
X[:2],y[:2]
@@ -47,10 +48,51 @@
4748
from sklearn.model_selection import train_test_split
4849

4950

50-
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.25)
51+
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.25,random_state=42)
5152

5253

54+
len(X_train),len(y_test)
5355

5456

57+
import torch
58+
from torch import nn
59+
60+
# Make device agnositic code
61+
device = 'cuda' if torch.cuda.is_available() else 'cpu'
62+
63+
64+
device
65+
66+
67+
class CircleModelV0(nn.Module):
68+
def __init__(self):
69+
super().__init__()
70+
self.layer_1 = nn.Linear(2,1024) #
71+
self.layer_2 = nn.Linear(1024,1)
72+
73+
def forward(self,X):
74+
return self.layer_2(self.layer_1(X)) # x -> layer_1 -> layer_2
75+
76+
77+
model_0 = CircleModelV0().to(device)
78+
79+
80+
model_0
81+
82+
83+
list(model_0.parameters())
84+
85+
86+
model_0 = nn.Sequential(
87+
nn.Linear(in_features=2,out_features=64),
88+
nn.Linear(64,1)
89+
).to(device)
90+
91+
92+
untrained_preds = model_0(X_test)
93+
94+
95+
untrained_preds[0],y_test[0]
96+
5597

5698

02.ipynb

Lines changed: 239 additions & 20 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)