This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Mock Classes that simulate a Pandas frame | |
class loc_class: | |
def __init__(self): | |
self.rows = [] | |
self.csv_df = None | |
def add_row(self, item): | |
self.rows.append(item) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(mvtnorm) | |
library(ggplot2) | |
library(MCMCpack) | |
expected_task <- list(mean=3,sd=2) | |
hyper_parameters <- list(alpha=1, beta=1) | |
data_samples = rnorm(100,6,3) | |
random_samples <- rnorm(100,20,5) | |
find_likelyhood <- function(target_model, target) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(MCMCpack) | |
example_prior <- list(mean=3,sd=2) | |
hyper_parameters <- list(alpha=1, beta=1) | |
data_samples = rnorm(100,6,3) | |
random_samples <- rnorm(100,20,5) | |
find_likelyhood <- function(target_model, target) { | |
return(dnorm(target,target_model$mean, target_model$sd)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
excel_file = 'excel.xlsx' | |
out_file = 'excel.csv' | |
#External Global variables | |
__col_size__ = 14 | |
__i_start__ = 6 | |
__c_size__ = 202 | |
"""Read the country file and parse its contents""" | |
def read_country_data(xls_file, country_size, index_start, output_file, col_size): | |
print('Conversion Starting') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import io | |
from lxml import etree | |
def read_xml(file_name): | |
in_file = open(file_name,"rb") | |
xml_file = etree.parse(in_file) | |
return xml_file | |
def generate_rterms_dic(xml_element): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#returns a randomly generated dirichlet for psuedo counts | |
#Alpha is passed as Shape to the RGamma Function | |
#Beta is passed as scale to the RGamma Function | |
#NVar is the number of variables you are going to psuedocount | |
random_dirichlet <- function(n_var, alpha=0, beta=1) { | |
return_val <- 0 | |
#Prevent alpha being less than n_var other wise | |
#n_var will have empty psuedo-counts, which is what |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#returns a randomly generated dirichlet | |
random_dirichlet <- function(n_var, alpha, beta) { | |
return_val <- 0 | |
for(i in 1:n_var) { | |
return_val[i] <- rgamma(1,shape=alpha,scale = beta) | |
} | |
#Normalise and round to a nice values | |
return_val <- round(return_val/sum(return_val) * 100,1)/100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model.analysis <-function(test_res, predict_rsp) { | |
col_names <- c("TruePositive","FalsePositive", | |
"FalseNegative","Accuracy","Precision","Recall","F1") | |
ret_val <- data.frame(matrix(ncol = length(col_names), nrow = 0)) | |
colnames(ret_val) <- col_names | |
ret_val[nrow(ret_val) + 1,] = c(tp,fp,fn,accuracy,precision,recall,f1) | |
return(ret_val) | |
} |