Skip to content

Instantly share code, notes, and snippets.

View parmarsuraj99's full-sized avatar

Suraj Parmar parmarsuraj99

View GitHub Profile
@parmarsuraj99
parmarsuraj99 / deep_autoencoder.py
Last active September 24, 2019 17:00
A simple Deep Autoencoder using keras
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
<!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();
await model.fit(xs, ys);
// model.fit(xs, ys, epochs=100)
model.predict(tf.tensor1d([6], [1, 1])).print();
<!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>
@parmarsuraj99
parmarsuraj99 / dtclf.py
Created November 4, 2018 09:52
Decision tree Classifier (sklearn)
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
#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
@parmarsuraj99
parmarsuraj99 / linear_model.py
Last active October 4, 2018 06:33
Linear regression using sklearn models
#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
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
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):