Skip to content

Instantly share code, notes, and snippets.

View sudipto80's full-sized avatar
🎯
Focusing

Sudipta Mukherjee sudipto80

🎯
Focusing
View GitHub Profile
@sudipto80
sudipto80 / linearRegress.fs
Created January 22, 2016 19:42
Linear Regression
#load "...\packages\MathNet.Numerics.FSharp.3.10.0\MathNet.Numerics.fsx"
open MathNet.Numerics.LinearAlgebra
open System.IO
let velocities = vector[23.;4.;5.;2.]
//let y = matrix [[1.;3.]
// [1.;5.]
// [1.;4.]]
@sudipto80
sudipto80 / sentiment.fs
Created January 22, 2016 19:29
Sentiment Analysis
open System.Text.RegularExpressions
type SentiWordNetEntry = {POS:string; ID:string; PositiveScore:string; NegativeScore:string; Words:string}
let sentiWordList = System.IO.File.ReadAllLines(@"SentiWordNet_3.0.0_20130122.txt")
|> Array.filter (fun line -> not (line.StartsWith("#")))
|> Array.map (fun line -> line.Split '\t')
|> Array.map (fun lineTokens -> {POS = lineTokens.[0];
ID = lineTokens.[1];
PositiveScore = lineTokens.[2].Trim();
@sudipto80
sudipto80 / anomaly.fs
Created January 22, 2016 19:14
Anomaly Detection
//Finds the median
let median numbers =
let sorted = List.sort numbers
let n = float numbers.Length
let x = int (n/2.)
let mutable result = 0.0
if (float numbers.Length) % 2. = 0.0 then result <- float (numbers.[x] +
numbers.[x-1]) / 2.0
else result <- float numbers.[x]
result
@sudipto80
sudipto80 / kNN.fs
Created January 22, 2016 09:03
Identifying Digits with kNN
open System.IO
open System
open System.Windows.Forms
open System.Drawing
//The type that represents each row of the training
//or the test dataset
type Entry = {Label :string; Values : int list}
//Calculates Squared Euclidean distance between pixel
@sudipto80
sudipto80 / rose_And_potato.fs
Created January 22, 2016 08:21
Rose And Potato
open System.IO
let image = System.Drawing.Image.FromFile(@"C:\personal\rose.jpg")
let image2 = System.Drawing.Image.FromFile(@"C:\personal\potato.jpg")
let ms = new MemoryStream()
image.Save(ms,System.Drawing.Imaging.ImageFormat.Jpeg)
let bytes = ms.ToArray() |> Array.map int |> List.ofArray
let ms2 = new MemoryStream()
image2.Save(ms2,System.Drawing.Imaging.ImageFormat.Jpeg)
@sudipto80
sudipto80 / similarCookies.fs
Created January 22, 2016 08:19
Similar Cookies
let biscuitA = ["refined wheat flour";"sugar";"edible vegetable oil";
"edible coconut products";"invert syrup";"milk solids";
"edible starch";"raising agent";"edible common salt";
"baking powder";"solbake";"emulsifier"]
let biscuitB = ["refined wheat flour";"cocoa powder";"suger";"cocoa butter";
"dextrose";"lecithin";"vanillin";"edible vegetable oil";
"raising agent";"cocoa solids";"edible common salt";"emulsifier"]
let biscuitC = ["refined wheat flour";"suger";"cocoa solids";
@sudipto80
sudipto80 / IRLib.fs
Created January 22, 2016 08:18
IR Lib
namespace IRLib
module asymSimilarity =
let private getABCD (first :string list)(second : string list) =
let all = Set.union (first |> Set.ofList) (second |> Set.ofList) |> Set.toList
let firstMatches = all |> List.map (fun t -> first |> List.contains t )
let secondMatches = all |> List.map (fun t -> second |> List.contains t )
@sudipto80
sudipto80 / tf-idf.fs
Created January 22, 2016 01:50
tf idf
let sentence1 = "this is a a sample"
let sentence2 = "this is another another example example example"
let word = "example"
let numberOfDocs = 2.
let tf1 = sentence1.Split ' ' |> Array.filter ( fun t -> t = word)
|> Array.length
let tf2 = sentence2.Split ' ' |> Array.filter ( fun t -> t = word)
|> Array.length
@sudipto80
sudipto80 / CollaborativeFiltering.fs
Created January 21, 2016 08:56
Collaborative Filtering
// Learn more about F# at http://fsharp.org
// See the 'F# Tutorial' project for more help.
//Comprehensive coverage of Collaborative Filtering Techniques
//http://www.hindawi.com/journals/aai/2009/421425/
module confusion =
let TP (matches : int [] []) =
matches |> Array.mapi( fun i j -> matches.[i].[i]) |> Array.sum
@sudipto80
sudipto80 / baseline.fs
Created January 21, 2016 08:55
base line predictor
//Non personalized baseline predictor
let baseline (ratings:(float list)list) =
let mu = ratings |> List.map ( fun ra -> [for i in 0 .. ra.Length - 1 -> ra.[i]]
|> List.filter (fun t -> t <> 0.0)
|> List.average)
|> List.average
let mutable bu = ratings |> List.sumBy (fun rating -> [for i in 0 .. rating.Length - 1 -> rating.[i]]
|> List.filter (fun ri -> ri <> 0.0)
|> List.sumBy (fun ri -> ri - mu))