Skip to content

Instantly share code, notes, and snippets.

View apachaves's full-sized avatar
💻
Crunching data...

Anderson Chaves apachaves

💻
Crunching data...
View GitHub Profile
@apachaves
apachaves / PRISM.R
Created January 10, 2018 22:38
Algoritmo PRISM para regras de associação (association rules) em R.
## Algoritmo completo modularizado (dividido em pequenas funções para facilitar compreensão). ##
library('plyr')
library('dplyr')
compute_probabilities <- function(df, target_variable_name){
feature_variables_names <- names(df[,!(names(df) %in% target_variable_name)])
rules_probabilities <- as.data.frame(rbind(NULL, NULL))
@apachaves
apachaves / PRISM.py
Created January 10, 2018 22:36
Algoritmo PRISM para regras de associação (association rules) em Python.
## Algoritmo completo modularizado (dividido em pequenas funções para facilitar compreensão). ##
import numpy as np
import pandas as pd
from dfply import *
def compute_probabilities(df, target):
prob_table = pd.DataFrame()
feature_matrix = df.drop(target, axis=1)
feature_variables = feature_matrix.columns.values
@apachaves
apachaves / wdm.py
Last active November 20, 2016 19:24
Final Project of Web Data Models
#Université Paris-Saclay - M2 Data & Knowledge
#Web Data Models - Silviu Maniu - Final Project
#Anderson Pinheiro de Araújo Chaves
def readFileByChunk(file_object):
while True:
data = file_object.readline()
if not data:
break
#elif data != ' ' and data != '\n' and data != '0' and data != '1':
import java.io.IOException;
import java.util.StringTokenizer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import java.io.IOException;
import java.util.ArrayList;
import java.util.StringTokenizer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
@apachaves
apachaves / addFact.java
Created September 30, 2016 20:30
Method to add new facts to the FactBase. Yue Ma's Web Semantic laboratory. Université Paris-Saclay 2016
public void addFact(HashSet<Variable> newfacts) {
for(Variable var : newfacts) {
this.facts.add(var);
}
}
@apachaves
apachaves / forwardChaining.java
Last active October 1, 2016 10:45
Forward Chaining method for Web Semantic's laboratory class. Université Paris-Saclay 2016
public FactBase forwardChaining(Formalism ruleBase, Formalism factBase) {
FactBase updatedFactBase = (FactBase) factBase;
FactBase oldFactBase = (FactBase) factBase;
HornRuleBase hornRuleBase = (HornRuleBase) ruleBase;
do {
oldFactBase = updatedFactBase;
for (HornRule rule : hornRuleBase.getRules()) {
if (this.eval(rule, updatedFactBase)) {
updatedFactBase.addFact(rule.getConclusions());
@apachaves
apachaves / eval_function.java
Last active October 1, 2016 10:43
Evaluation function for Web Semantic course laboratory. Université Paris-Saclay 2016
public boolean eval(HornRule rule, FactBase fb) {
for (Variable condition : rule.getConditions()) {
boolean conditionMatched = false;
for (Variable fact : fb.getFact()) {
if (condition.equals(fact))
conditionMatched = true;
}
if (!conditionMatched)
return false;
}