Skip to content

Instantly share code, notes, and snippets.

View rishisidhu's full-sized avatar
🏠
Working from home

Rishi Sidhu rishisidhu

🏠
Working from home
  • https://aigraduate.com
View GitHub Profile
@rishisidhu
rishisidhu / Factory.java
Last active December 21, 2019 17:47
Code to create a java class and its object instances
public class Factory{
private String SolidFood1; // Solid Food 1st Instance Variable
private String SolidFood2; // Solid Food 2nd Instance Variable
private String LiquidFood1; // Liquid Food 3rd Instance Variable
public Factory(){} // 0-arg constructor (Not used)
public Factory(String sf1, String sf2, String lf1){ // 3-arg constructor
SolidFood1 = sf1;
SolidFood2 = sf2;
LiquidFood1 = lf1;
}
@rishisidhu
rishisidhu / chatbot_nltk.py
Last active January 30, 2020 02:09
A retrieval based python chatbot that acts as an FAQ Answerer
#Imports
import string
import random
import nltk
from nltk.tokenize import sent_tokenize, word_tokenize
from nltk.corpus import stopwords
from nltk.stem import PorterStemmer
from nltk.tokenize import PunktSentenceTokenizer
import sklearn
from sklearn.feature_extraction.text import TfidfVectorizer
@rishisidhu
rishisidhu / Book.java
Created January 10, 2020 08:39
Base class Book. How inheritance works
/**
*Base Class : Book
*Author : Rishi Sidhu
*Organization : AI Graduate
**/
public class Book
{
public String author;
public float costPrice;
public float salePrice;
@rishisidhu
rishisidhu / EBook.java
Created January 10, 2020 11:13
Sub class of Book.java.
/**
*Sub Class : EBook
*Author : Rishi Sidhu
*Organization : AI Graduate
**/
public class EBook extends Book
{
public String downloadSite;
public int sizeMB;
public EBook(String au, float cp, float sp, String tl, int pg, String ds, int sz){
@rishisidhu
rishisidhu / TestBook.java
Created January 10, 2020 11:21
This file tests the Book and Ebook inheritance.
/**
*Test Class : TestBook
*Author : Rishi Sidhu
*Organization : AI Graduate
**/
public class TestBook
{
public static void main(String[] args){ // Main Method - Only this method gets executed
//Create a Book object
Book book1 = new Book("Gary Rich", 8.99f, 19.99f, "How to get rich", 100);
@rishisidhu
rishisidhu / Histogram.java
Created January 28, 2020 11:08
Two different functions to create histogram are compared on speed
import java.util.Random;
public class Histogram {
static int NUM_STUDENTS = 20000;
static int HIGHEST_GRADE = 10;
//Function to compute histogram faster O(N)
public void getHistFast(int iArr[], int oArr[])
{
for(int i=0;i<iArr.length;i++)
from sklearn.datasets import load_iris
from sklearn import tree
import numpy as np
from graphviz import Source
iris = load_iris()
print("Feature Names - ", iris.feature_names,"\n")
print(iris.target)
#Print the row 0,50 and 100 i.e. 1 example for each type
print("\nSetosa flower 1 - ",iris.data[0])
@rishisidhu
rishisidhu / integer_demo.py
Created April 10, 2020 10:56
Integers in Python
a = 10 # Integer
b = -9 # Integer can be negative
c = 0b011 # Integer can be Binary
d = 0o123 # Integer can be Octal
e = 0x9AF # Integer can be Hexadecimal
print("Positive Integer = ",a, " | ", type(a))
print("Negative Integer = ",b, " | ", type(b))
print("Binary Integer = ",c, " | ", type(c))
print("Octal Integer = ",d, " | ", type(d))
@rishisidhu
rishisidhu / types_demo.py
Created April 10, 2020 10:59
Understanding the basic types in Python
in1 = 1+2j # Complex Number 
fl1 = 0.78 # Float 
fl2 = 2.6e-2 # Float with scientific notation. e means 10^ 
fl3 = 1.8*10**308 +1 # One greater than the maximum float 
bl1 = True # Boolean True 
bl2 = False # Boolean False 
st1 = "Hello World!" # String 
bt1 = b"hola" # Byte
@rishisidhu
rishisidhu / list_ops.py
Created April 10, 2020 11:23
List Operations in Python
#Lists 
l2 = [4,1,3,9,7] 
l3 = ['a','ab', 'abc','ab', 'ab'] 
#List Methods
l2.sort() # Sort 
l2.append(12) # Add an element at the end 
sum(l2) # Sum all the elements 
max(l2) # Find the maximum element 
min(l2) # Find the minimum element