Skip to content

Instantly share code, notes, and snippets.

View bistaumanga's full-sized avatar

bistaumanga bistaumanga

View GitHub Profile
@bistaumanga
bistaumanga / dtw_pattern.py
Created March 11, 2014 11:14
Alignment of tokens in 2 sentence to generate pattern using Dynamic time warp.
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 11 11:05:05 2014
@author: logpoint
"""
import numpy as np
@bistaumanga
bistaumanga / Monoid.scala
Created July 30, 2016 15:28
simulacrum + machinist
import simulacrum.{op, typeclass}
import scala.language.experimental.macros
object MyOps extends machinist.Ops{
override def operatorNames: Map[String, String] = Map(
"$bar$plus$bar" -> "plus"
)
}
@bistaumanga
bistaumanga / loan.scala
Last active February 6, 2016 15:45
pwlktm02
val rawData = sc.textFile("hdfs://hdfs-nn-host.com:9000/user/umb/bank/bank.csv")
rawData.take(5)
// 30;"unemployed";"married";"primary";"no";1787;"no";"no";"cellular";19;"oct";79;1;-1;0;"unknown";"no"
implicit def str2int(x: String) = x.toInt // because i'm lazy
// case class for representing data row
case class DataRow(age: Int,
job: String,
maritial: String,
@bistaumanga
bistaumanga / PR.py
Last active December 29, 2015 10:29
Sainte Laguie Method (modified) to calculate Proportionate Representation seats in Nepal (CA election 2070). Just copy The data from http://election.gov.np/CA2070/CAResults/reportBody.php?selectedMenu1=2&rand=1385472280 to Votes.csv (table only) and run the script.....
# -*- coding: utf-8 -*-
#############################################################################
####### usage : > python PR.py -t 0.01 ###################################
####### OR, > python PR.py --thresh=0.01 ####################################
import numpy as np
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-t", "--thresh", dest="threshold", help="Threshold for PR")
options, args = parser.parse_args()
@bistaumanga
bistaumanga / lof.py
Last active December 25, 2015 01:48
local outler factor
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 25 22:19:09 2014
@author: bistaumanga
Local Outlier factor implementation in python
Implementations are in two version for calculating knn:
1. Naive method
@bistaumanga
bistaumanga / changed.csv
Created August 25, 2014 10:29
Students whose entrance scores changed
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 10.
"","ROLLNO","FORMNO.x","NAME.x","GENDER.x","SCORE.x","RANK.x","FORMNO.y","NAME.y","GENDER.y","SCORE.y","RANK.y","diff_percentage"
"1",6894,"2071-2878","SURENDRA KUNWAR","Male",73.68,499,"2071-2878","SURENDRA KUNWAR","Male",48.223,4294,25.457
"2",7114,"2071-11158","TEZINA KHADKA","Female",66.62,1183,"2071-11158","TEZINA KHADKA","Female",50.076,3919,16.544
"3",7126,"2071-5200","TILAK PRASAD BHATT","Male",65.69,1289,"2071-5200","TILAK PRASAD BHATT","Male",41.51,5766,24.18
"4",7124,"2071-10055","TILAK GIRI","Male",62.32,1713,"2071-10055","TILAK GIRI","Male",72.5,613,-10.18
"5",6895,"2071-317","SURENDRA NEPAL","Male",61.95,1768,"2071-317","SURENDRA NEPAL","Male",87.409,13,-25.459
"6",7122,"2071-7648","TIKAM RAI","Male",59.67,2111,"2071-7648","TIKAM RAI","Male",40.58,5947,19.09
"7",7115,"2071-5978","THAKUR LAMICHHANE","Male",54.93,2936,"2071-5978","THAKUR LAMICHHANE","Male",70.199,801,-15.269
"8",63,"2071-5163","AASHISH CHANDRA","Male",53.31,3237,"2071-5163","AASHISH CHANDRA","Male",45.671,4874,7.639
"9",7113,"2071
@bistaumanga
bistaumanga / ioe.R
Last active August 29, 2015 14:05
Ioe revised entrance analysis
ioe1 <- read.csv('/Volumes/umb/ioe entrance/ioe-first.csv')
ioe1 <- subset(ioe1, select = c(1:6))
ioe2 <- read.csv('/Volumes/umb/ioe entrance/ioe second.csv')
require('dplyr')
ioe_joined = inner_join(ioe1, ioe2, by = "ROLLNO")
ioe_joined$diff_percentage <- ioe_joined$SCORE.x - ioe_joined$SCORE.y
ioe_contrasts <- filter(ioe_joined, diff_percentage > 0.1 | diff_percentage < -0.1)
write.csv(ioe_contrasts, "~/changed.csv")
@bistaumanga
bistaumanga / iris.ipynb
Created July 27, 2014 07:12
iris data analysis and logistic regression
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bistaumanga
bistaumanga / DisjointSet.scala
Last active August 29, 2015 14:03
Union Find data structures implemented as Lazy Unions with optimizations(Union By Rank and Path Compressions)
package util
import scala.collection.mutable.HashMap
import scala.collection.mutable.ArrayBuffer
class DisjointSet[Element] {
private val parent = new HashMap[Element, Element]
private val rank = new HashMap[Element, Int]
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.