This file contains 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
Verifying my Blockstack ID is secured with the address 1Jzq7PkwGH34a6iF1PAL6QVuQqatY6MxZy https://explorer.blockstack.org/address/1Jzq7PkwGH34a6iF1PAL6QVuQqatY6MxZy |
This file contains 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 sigmoid(x): | |
return 1 / (1 + np.exp(-x)) | |
def sigmoid_derivative(x): | |
return x * (x - 1) |
This file contains 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
# Input matrix | |
training_inputs = np.array([[0,0,1], | |
[1,1,1], | |
[1,0,1], | |
[0,1,1]]) | |
# Output array (transposed) | |
training_outputs = np.array([[0,1,1,0]]).T |
This file contains 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
# Set seed for pseudo-randomness | |
np.random.seed(1) | |
# Initialize synaptic weights randomly from -1 to 1 with 0 as the mean | |
synaptic_weights = 2 * np.random.random((3, 1)) - 1 |
This file contains 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
# Train by iterating 10,000 times | |
for iteration in range(10000): | |
# Define input layer | |
input_layer = training_inputs | |
# Normalize the product of the input layer with the synaptic | |
# weights by using the sigmoid function to get outputs | |
outputs = sigmoid(np.dot(input_layer, synaptic_weights)) | |
This file contains 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
Random starting synaptic weights: Synaptic weights after training: | |
[-0.16595599] [ 9.67299303] | |
[ 0.44064899] [-0.2078435 ] | |
[-0.99977125] [-4.62963669] | |
Output after training: | |
[0.00966449] | |
[0.99211957] |
This file contains 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
# Dividing data up into training sets and test sets | |
from sklearn.model_selection import train_test_split | |
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 1/3) |
This file contains 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
# Creating the matrix of features and the vector of labels | |
X = df.iloc[:, :-1].values | |
y = df.iloc[:, 1].values |
This file contains 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
from sklearn.linear_model import LinearRegression | |
regressor = LinearRegression() | |
regressor.fit(X_train, y_train) |
This file contains 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
# Visualizing the training set results | |
plt.figure(figsize = (12, 6)) | |
plt.scatter(X_train, y_train, alpha = 0.4, label = 'Observation Points') | |
plt.plot(X_train, regressor.predict(X_train), color = 'green', lw = 0.7, alpha = 0.8, label = 'Best Fit Line') | |
plt.title('Linear Regression (Training Set)') | |
plt.xlabel('Years of Experience') | |
plt.ylabel('Salary') | |
plt.legend() |
OlderNewer