This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| iter = 0 | |
| for epoch in range(num_epochs): | |
| for i, (images, labels) in enumerate(train_loader): | |
| # Load images as Variable | |
| images = Variable(images.view(-1, 28*28)) | |
| labels = Variable(labels) | |
| # Clear gradients w.r.t. parameters | |
| optimizer.zero_grad() | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| def sigmoid(x, derivative=False): | |
| if (derivative == True): | |
| return x * (1 - x) | |
| return 1 / (1 + np.exp(-x)) | |
| x = sigmoid(x) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| def tanh(x, derivative=False): | |
| if (derivative == True): | |
| return (1 - (x ** 2)) | |
| return np.tanh(x) | |
| x = tanh(x) | |
| print(x) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| def relu(x, derivative=False): | |
| if (derivative == True): | |
| for i in range(0, len(x)): | |
| for k in range(len(x[i])): | |
| if x[i][k] > 0: | |
| x[i][k] = 1 | |
| else: | |
| x[i][k] = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| def arctan(x, derivative=False): | |
| if (derivative == True): | |
| return (np.cos(x) ** 2) | |
| return np.arctan(x) | |
| x = arctan(x) | |
| print(x) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| def step(x, derivative=False): | |
| if (derivative == True): | |
| for i in range(0, len(x)): | |
| for k in range(len(x[i])): | |
| if x[i][k] > 0: | |
| x[i][k] = 0 | |
| return x | |
| for i in range(0, len(x)): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| def squash(x, derivative=False): | |
| if (derivative == True): | |
| for i in range(0, len(x)): | |
| for k in range(0, len(x[i])): | |
| if x[i][k] > 0: | |
| x[i][k] = (x[i][k]) / (1 + x[i][k]) | |
| else: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| def gaussian(x, derivative=False): | |
| if (derivative == True): | |
| for i in range(0, len(x)): | |
| for k in range(0, len(x[i])): | |
| x[i][k] = -2* x[i][k] * np.exp(-x[i][k] ** 2) | |
| for i in range(0, len(x)): | |
| for k in range(0, len(x[i])): | |
| x[i][k] = np.exp(-x[i][k] ** 2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| from sklearn import datasets,linear_model | |
| from sklearn.metrics import mean_squared_error,r2_score | |
| diabetes=datasets.load_diabetes() | |
| diabetes_X=diabetes.data[:,np.newaxis,2] | |
| diabetes_X_train=diabetes_X[:-30] #splitting data into training and test sets | |
| diabetes_X_test=diabetes_X[-30:] | |
| diabetes_y_train=diabetes.target[:-30] #splitting targets into training and test sets | |
| diabetes_y_test=diabetes.target[-30:] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| from sklearn import linear_model | |
| xmin,xmax=-7,7 #Test set; straight line with Gaussian noise | |
| n_samples=77 | |
| np.random.seed(0) | |
| x=np.random.normal(size=n_samples) | |
| y=(x>0).astype(np.float) | |
| #Import Library | |
| from sklearn.linear_model import LogisticRegression |
OlderNewer