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 | |
#Function to calculate error at current m and b | |
def calculate_error(x, y, m, b): | |
error=0 | |
error = np.sum((m*x+b - y)**2) | |
error/=len(x) | |
return error | |
def update_weights(m_current, b_current, x, y, learning_rate): |
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 calculate_error(x, y, m, b): #Function to calculate error at current m and b | |
error=0 | |
error = np.sum((m*x+b - y)**2) | |
error/=len(x) | |
return error | |
def update_weights(m_current, b_current, x, y, learning_rate): | |
m_gradient=0 |
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 libraries needed | |
import numpy as np | |
from sklearn import linear_model | |
if __name__=="__main__": | |
#load Dataset, here i am creating one for Single variable Linear regression | |
x = np.array([2, 4, 3, 6, 7, 6, 9, 10 , 12]) | |
x=x.reshape(-1,1) #reshaping it | |
#slope of the line is 3 and intercept is 6 | |
np.random.seed(18) | |
y = 4.5*x+3*np.random.uniform(0, 100, x.shape)*0.01 |
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 libraries needed | |
import numpy as np | |
from sklearn import linear_model | |
if __name__=="__main__": | |
#load Dataset | |
#here i am creating one for Single variable Linear regression | |
x = np.array([[1, 2], [1, 4], [2, 3], [2, 2], [4.5, 7]]) | |
y = np.array([0, 0, 1, 0, 1]) | |
#Create an object for logistic regression |
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.datasets import load_iris #load dataset from scikitlearn | |
#This is a function which will return X and Y | |
from sklearn import tree | |
iris = load_iris() #load_iris() returns iris.data (x) and iris.target (Y) | |
clf = tree.DecisionTreeClassifier() #we create a Decision Tree Classifier from sklearn.tree | |
clf.fit(iris.data, iris.target) #Training | |
print("input: ", [4.9, 3.4, 2, 0.4]) #predictions |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<!-- Load TFJS | |
loaded from https://github.com/tensorflow/tfjs --> | |
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs/dist/tf.min.js"> </script> | |
<title>Hello TFJS</title> | |
</head> | |
<body> |
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
await model.fit(xs, ys); | |
// model.fit(xs, ys, epochs=100) | |
model.predict(tf.tensor1d([6], [1, 1])).print(); |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs/dist/tf.min.js"> </script> | |
</head> | |
<body> | |
<p id="prediction">Prediction(100): </p> | |
<script> | |
async function run(){ | |
const model=tf.sequential(); |
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 tensorflow as tf | |
from tensorflow import keras | |
from matplotlib import pyplot as plt | |
from keras.datasets import mnist | |
from keras.layers import Input, Dense | |
from keras.models import Model | |
(x_train, y_train), (x_test, y_test) = mnist.load_data() | |
x_train = x_train.astype('float32')/255.0 |