Skip to content

Instantly share code, notes, and snippets.

View Rishit-dagli's full-sized avatar
:octocat:
Making Machines Learn

Rishit Dagli Rishit-dagli

:octocat:
Making Machines Learn
View GitHub Profile
@Rishit-dagli
Rishit-dagli / script.js
Created March 31, 2020 14:24
Simple model with TF.js
function createModel() {
// Create a sequential model
const model = tf.sequential();
// Add a single input layer
model.add(tf.layers.dense({inputShape: [1], units: 1, useBias: true}));
// Add an output layer
model.add(tf.layers.dense({units: 1, useBias: true}));
@Rishit-dagli
Rishit-dagli / script.js
Created March 31, 2020 14:30
Instantiate model, TF.js
const model = createModel();
tfvis.show.modelSummary({name: 'Model Summary'}, model);
@Rishit-dagli
Rishit-dagli / script.js
Created March 31, 2020 14:38
Data preperation for car dataset TF.js
/**
* Convert the input data to tensors that we can use for machine
* learning. We will also do the important best practices of _shuffling_
* the data and _normalizing_ the data
* MPG on the y-axis.
*/
function convertToTensor(data) {
// Wrapping these calculations in a tidy will dispose any
// intermediate tensors.
@Rishit-dagli
Rishit-dagli / script.js
Created March 31, 2020 15:06
Training a sample model TF.js
async function trainModel(model, inputs, labels) {
// Prepare the model for training.
model.compile({
optimizer: tf.train.adam(),
loss: tf.losses.meanSquaredError,
metrics: ['mse'],
});
const batchSize = 32;
const epochs = 50;
@Rishit-dagli
Rishit-dagli / script.js
Created March 31, 2020 15:21
Model predictions with TF.js
function testModel(model, inputData, normalizationData) {
const {inputMax, inputMin, labelMin, labelMax} = normalizationData;
// Generate predictions for a uniform range of numbers between 0 and 1;
// We un-normalize the data by doing the inverse of the min-max scaling
// that we did earlier.
const [xs, preds] = tf.tidy(() => {
const xs = tf.linspace(0, 1, 100);
const preds = model.predict(xs.reshape([100, 1]));
@Rishit-dagli
Rishit-dagli / financial_aid.md
Created April 5, 2020 07:03
My accepted Coursera Financial Aid application for TF in practice specialization

Why are you applying for Financial Aid?

I’m a student from India keen to learn about Machine Learning, Deep Learning, and TensorFlow. Since the quality of education in our institution is not up to the mark, the only way to get a viable career option in the future for me is to take this course. Since I am a student and our college does not permit a part-time job, I would not be able to carry the expenses to pay for the certificate of this course. Financial Aid will help me take this course without any adverse impact on my monthly essential needs. I am really excited for this course since it presents me with a great opportunity to grow my skills and become a professional in this field as I graduate in the same or prospective fields with a great resume.

@Rishit-dagli
Rishit-dagli / np_example.py
Created April 7, 2020 05:33
Numpy Example
# Python
import numpy as np
a = np.arange(15).reshape(3, 5)
print(a.shape == (3, 5)) # True
print(a.ndim == 2) # True
print(a.dtype.name) # 'int64'
b = (np.arange(15) ** 2).reshape(3, 5)
@Rishit-dagli
Rishit-dagli / np_example.kt
Created April 7, 2020 05:34
Numpy Bindings example in Kotlin
// Kotlin
import org.jetbrains.numkt.*
fun main() {
val a = arange(15).reshape(3, 5)
println(a.shape.contentEquals(intArrayOf(3, 5))) // true
println(a.ndim == 2) // true
println(a.dtype) // class java.lang.Integer
@Rishit-dagli
Rishit-dagli / save_model_json.py
Created April 13, 2020 15:49
Create a JSON saved file for saving ML model parameters
```
We can also save the model parameters in a JSON file and load them back.
In the example below, we will save the model coefficients and intercept and load them back.
We will first import the json library, create a dictionary containing the coefficients and intercept.
Coefficients and intercept are an array object.
We cannot dump an array into JSON strings so we convert the array to a list and store it in the dictionary
```
import json
model_param = {}
@Rishit-dagli
Rishit-dagli / 10_Days_Of_ML_CLA.md
Last active May 11, 2020 14:01
CLA for 10 Days of ML

Contribution License Agreement

This Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”), and conveys certain license rights to Rishit Dagli for Your contributions to Rishit Dagli's open source projects. This Agreement is effective upon Your acknowledgment via the CLA Assistant tool. All prospective contributors to Rishit Dagli's open source projects must sign this Agreement (digitally or otherwise) before any changes will be merged.

1. Definitions.

“Code” means the computer software code, whether in human-readable or machine-executable form, that is delivered by You to Rishit Dagli under this Agreement.

“Project” means any of the projects owned or managed by Rishit Dagli in which software is offered under a license approved by the Open Source Initiative (OSI) (www.opensource.org) and/or documentation offered under an OSI or a Creative Commons license (https://creativecommons.org/licenses).

“Submit” is the act of uploading, submitting, transmitting, or distribu