Skip to content

Instantly share code, notes, and snippets.

View CharlesRajendran's full-sized avatar
:octocat:
Living

Charles's Labs CharlesRajendran

:octocat:
Living
View GitHub Profile
@CharlesRajendran
CharlesRajendran / recursive-sum.js
Created October 17, 2019 01:36
recursively calling method chaining [ sum(1)(2)(3)(4)(7)() ]
function sum(num) {
return function(b) {
if (b) {
return sum(num+b);
} else {
return num;
}
}
}
@CharlesRajendran
CharlesRajendran / generate-question.js
Last active October 1, 2019 02:02
Generating Questions with Recursion
// generating questions of some complexity for kids math
// ["5 + 3 =", "3 + 2 =", "0 + 3 =", "2 + 0 =", "1 + 2 ="]
function generateRandomInteger(complexity) {
return Math.floor(Math.random() * complexity);
}
function matchingPairs(complexity) {
const x = generateRandomInteger(complexity);
const y = generateRandomInteger(complexity);
@CharlesRajendran
CharlesRajendran / generate-question.js
Created October 1, 2019 01:56
Generating Questions with Recursion
// generating questions of some complexity for kids math
// ["8 + 8 =", "8 + 5 =", "6 + 5 =", "3 + 9 =", "4 + 8 ="]
function generateRandomInteger(complexity) {
return Math.floor(Math.random() * complexity);
}
function matchingPairs(complexity) {
const x = generateRandomInteger(complexity);
const y = generateRandomInteger(complexity);
@CharlesRajendran
CharlesRajendran / calculate-family-total-age.js
Last active October 1, 2019 01:57
Finding Family Member Age with Recursion
const profile = {
name: "Madasaamy",
age: 80,
kids: [
{
name: "Soori",
age: 57,
kids: [
{
name: "Miller",
console.log('Hello World Brother')
import pandas as pd
dataset = pd.read_csv("data.csv", header=None)
# apriori expects the input as list of list
# [ [item1, item2], [item2, item3, item4], ..... ] ]
transactions = []
for i in range(0, len(dataset)):
transactions.append([str(dataset.values[i, j]) for j in range(0, 20)])
from apyori import apriori
import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_csv('Data.csv')
X = data.iloc[:, 1:3]
# use elbow mwthod to find optimal number of clusters
from sklearn.cluster import KMeans
'''
wcss = []
#plot the scatters
'''
X[y_pred==0] - will list records which belongs to cluster 0
output:
Qty UnitPrice
1 1911 3.39
'''
plt.scatter(X[y_pred == 0].iloc[:, 0], X[y_pred == 0].iloc[:, 1], s=5, c="red")
plt.scatter(X[y_pred == 1].iloc[:, 0], X[y_pred == 1].iloc[:, 1], s=5, c="green")
kmeans = KMeans(n_clusters=4, init="k-means++", max_iter=1000, n_init=10)
y_pred = kmeans.fit_predict(X)
X = data.iloc[:, 1:3]
# use elbow mwthod to find optimal number of clusters
from sklearn.cluster import KMeans
# with in cluster sum of squares
wcss = []
for i in range(1, 11):
kmeans = KMeans(n_clusters =i, init="k-means++", max_iter=300, n_init=10)
kmeans.fit(X)