Weka Apriori Algorithm convert dataset - weka

How can I use this dataset with Weka for Apriori Algorithm ?
'A, C, D',
'B, C, E',
'A, B, C, E',
'B, E'

You need to convert it in .arff format.
The format of an .arff file is simple, is composed by three fields:
#relation
#attribute
#data
In case like this, where you have only a single field ("letters" in your case) you should list all the possible attribute (A,B,C,..) in the attribute field, and then format it (in data field) using boolean values describing presence/absence of the specific attribute in each line.
Example:
#relation <file_name>
#attribute 'A' { t}
#attribute 'B' { t}
#attribute 'C' { t}
#attribute 'D' { t}
#attribute 'E' { t}
#data
t, ?, t, t, ?
?, t, t, ?, t
t, t, t, ?, t
?, t, ?, ?, t
As an other example, look at the example of "supermarket.arff" in Weka data folder.

Related

Haskell make a List of own defined type

If I have a defined data type, say:
data Tag = Tag Char Int
Is there a way to define a List of Tag like this:
[("A",1),("A",2),("A",3),("B",1),("B",2)..............("D",2),("D",3)]
Instead of hard-coded?
Yes, you can construct a list with:
[Tag 'A' 1, Tag 'A' 2, Tag 'A' 3, Tag 'B' 1, Tag 'B' 2, Tag 'B' 3, Tag 'C' 1, Tag 'C' 2, Tag 'C' 3, Tag 'D' 1, Tag 'D' 2, Tag 'D' 3]
If you want to use values from two lists, you can work with:
Tag <$> "ABCD" <*> [1,2,3]
This makes use of the instance of a Functor and Applicative of the list instance. This means that Tag <$> "ABCD" will return a list of functions like [Tag 'A', Tag 'B', Tag 'C', Tag 'D'], next it will make use of the (<*>) :: Applicative f => f (a -> b) -> f a -> f b which will take a list of functions and a list of values, and will return a list that contains any combination of a function from the first list, and a value from the second list.
uncurry Tag has type (Char, Int) -> Tag, so if you want to use tuple syntax in your initializer list, you can do so like this:
myTags = uncurry Tag <$> [("A",1),("A",2),("A",3),("B",1),("B",2)..............("D",2),("D",3)]

How to look up a value inside a list in a predicate, in PROLOG

So far I've done my fair amount of research and I've tried different methods, however even after reading multiple stack overflow answers and even a PDF from Addison Wesley, I can't find the way to do it. Here is the code
use_module(library(func)).
% importing library "func"
scale([c, d, e, f, g, a, b]).
scale(c, major, [c, d, e, f, g, a, b]).
scale(c, minor, [c, d, e_b, f, g, a_b, b_b]).
%1st attempt
search(note, scale):- scale(note, scale).
%2nd attempt
scaleOf(note, type_scale):- scale(note, type_scale).
on(item,[item|rest]).
on(item,[disregardHead|tail]):-
scale(tail),
on(item, tail).
%3rd attempt
fatherOf(father,type, son):- scale(father, type, sons), search(son, type, sons).
search(son, type, []):- !, fail.
search(son, type, [son|l]):- !, true.
search(son, type, [c|l]):- search(son, type, l).
What am I attempting? Simple, something that can iterate through the predicate scale(c, [c, d, e, f, g, a, b]). But I can't get it right.
Edit: I have multiple predicates because someone else suggested creating a predicate that would differentiate one scale from the other. I thought I could cram it inside any algorithm but I guess PROLOG is not that lenient :p
You can do that with member/2 [swi-doc]. This can be used to search, unify with a member, or generate a list.
So you can search with:
search(Note, Scale, Item) :-
scale(Note, Scale, Items),
member(Item, Items).
It is important that Note, Scale, Item and Items start with an Uppercase, since identifiers with a lower case are constants or functors. Identifiers with an uppercase are variables.
This will thus unify Item with the items in the list, for the given sample data we for example obtain:
?- search(c, minor, Item).
Item = c ;
Item = d ;
Item = e_b ;
Item = f ;
Item = g ;
Item = a_b ;
Item = b_b.

Unexpected tuple iteration in Julia?

I wanted to iterate over triplets in a tuple and found a weird comma detail in Julia is that what we should expect?
julia> for (k, n, d) in (("x1", "x2", "x3"),); #show k, n, d; end;
(k, n, d) = ("x1", "x2", "x3")
# However if I remove , it doesn't work
julia> for (k, n, d) in (("x1", "x2", "x3")); #show k, n, d; end;
ERROR: BoundsError
Stacktrace:
[1] indexed_next(::String, ::Int64, ::Int64) at ./tuple.jl:56
[2] anonymous at ./<missing>:?
Yes, this is behaving as expected. Parentheses alone do not create tuples. If they did, simply basic math expressions like 2*(3+4) wouldn't work. Parentheses without commas or semicolons in them are used for precedence groupings or function calls. That's why you need that explicit trailing comma in the one-tuple case.
((x,y,z)) is the same as (x,y,z).
((x,y,z),) constructs a one-tuple that contains (x,y,z).

Prolog- Appending a list of lists

My database follows this format:
aminotodna (Amincoacid, [DNA sequence]).
Here are a few examples from the database:
aminotodna(a,[g,c,a]).
aminotodna(a,[g,c,c]).
aminotodna(a,[g,c,g]).
aminotodna(a,[g,c,t]).
aminotodna(c,[t,g,c]).
aminotodna(c,[t,g,t]).
aminotodna(d,[g,a,c]).
aminotodna(d,[g,a,t]).
aminotodna(e,[g,a,a]).
aminotodna(e,[g,a,g]).
aminotodna(f,[t,t,c]).
aminotodna(f,[t,t,t]).
Some aminoacids have multiple DNA sequences.
Here is my question, so in a given list of amino acids for example [d,c,e,f], how can I append their DNA sequences together and give all combinations, as some have more than one sequence.
If it was just two I could do it, it'd just be
listamino(X,Y) :-
aminotodna(X,L),
aminotodna(Y,M),
append(L,M,Z),
print(Z).
hitting ; gives all combinations.
I've tired doing it with a list, but this is my attempt, and it didnt work:
listamino([]).
listamino([H|T]) :-
aminotodna(H,L),
aminotodna(T,M),
append(L,M,X),
print(X).
listamino(T).
When describing lists with Prolog, always consider using DCG notation for convenience and clarity. For example, using a subset of your examples, I first use DCG rules to describe the correspondence (note that I am using a name that makes sense in all directions):
amino_dna(a) --> [g,c,a].
amino_dna(a) --> [g,c,c].
amino_dna(c) --> [t,g,c].
amino_dna(c) --> [t,g,t].
an then I again use DCG rules to describe the concatenation of such lists:
aminos([]) --> [].
aminos([A|As]) --> amino_dna(A), aminos(As).
Sample query:
?- phrase(aminos([a,c]), As).
As = [g, c, a, t, g, c] ;
As = [g, c, a, t, g, t] ;
As = [g, c, c, t, g, c] ;
etc.
No append/3, no additional variables, no additional arguments, no nonsense. Use dcg!
You need an extra parameter to keep track of the current combination:
; invoke a version of listamino which tracks the current combination of DNA sequences, which is initially empty
listamino(X) :-
listamino(X,[]).
; If there are no ore aminos, print the DNA seq list, and we're done
listamino([],X) :-
print(X).
; Otherwise, append the DNA for the first amino to our list, and process the rest of the mains
listamino([H|T],X) :-
aminotodna(H,L),
append(X,L,X2),
listamino(T,X2).

List all US State names that have any two consecutive vowels (a, e, i, o, u). using the character vector state.name?

This is what I have but it returns all 50 states
grep("[a]|[i]|[o]|[u]",state.name, value=TRUE)
grep("[aeiou]{2}", state.name, value=TRUE)