Navigation Menu

Skip to content

Commit

Permalink
script python to blanked one field on csv
Browse files Browse the repository at this point in the history
  • Loading branch information
j3nnn1 committed May 29, 2012
1 parent 58afda9 commit e138052
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
47 changes: 47 additions & 0 deletions weka/putblankfield001.py
@@ -0,0 +1,47 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# j3nnn1 - 0.0.0 -

import os
import string
import random


def cleanstring(l):
l[-1] = l[-1].rstrip("\n")
return([x.strip() for x in l])

def getpercenta(percent, numberlines):
result = percent * numberlines
return result

f = open("outputtree1.csv", "r")
output = open("output.csv", "w")
numlines = 0

for line in f.readlines():
numlines = numlines + 1

endlines = int(getpercenta(0.25, numlines))

f.seek(0)
line = f.readline()
i = 0
j = 0
while line:
i = i + 1
a = line.split(",")
aux = cleanstring(a)

if i%2 and j<=endlines:
j = j +1
indice = random.randint(0, (len(aux)-1))
aux[indice] = ''

aux[-1] = aux[-1]+"\n"
newline = ', '.join(aux)
output.write(newline)
line = f.readline()

f.close()
output.close()
44 changes: 44 additions & 0 deletions weka/treeexercise1.sh
@@ -0,0 +1,44 @@
#!/bin/bash
# #bash_treedecision.sh
# #Path to weka.jar, received a path absolute
# #File to process, received a path absolute
# #classpath
# #interval confidence factor
# #Options
# #args=$#
pathtoweka=$1
file=$2
classpath=$3
options=$5

if [ -z $file ]; then
echo "usage ./bash_treedecision.sh <pathtoweka> <filetoprocess> <options>"
exit 1
fi

if [ -z $options ]; then
options="-i -M 2 -no-cv"
fi
confidencefactor="0.0"
cont=25

echo "size_tree,leaves,confianza,percen_correct,cant_correct"
while [ $cont -le 501 ]; do
if [ $cont -gt 75 ]; then
confidencefactor="0."
fi
#echo "java -classpath $pathtoweka weka.classifiers.trees.J48 -C $confidencefactor$cont $options -t $file"
size=`java -classpath $pathtoweka weka.classifiers.trees.J48 -C $confidencefactor$cont $options -t $file | grep "Size"`;
leaves=`java -classpath $pathtoweka weka.classifiers.trees.J48 -C $confidencefactor$cont $options -t $file | grep "Leaves"`;
correctly=`java -classpath $pathtoweka weka.classifiers.trees.J48 -C $confidencefactor$cont $options -t $file | grep "Correctly Classified Instances"`;
int_size="$(echo $size | awk '{print $6}')"
int_leaves="$(echo $leaves | awk '{print $5}')"
int_cases="$(echo $correctly | awk '{print $4}')"
prc_cases="$(echo $correctly | awk '{print $5}')"
echo "$int_size, $int_leaves, $confidencefactor$cont, $prc_cases, $int_cases"
cont=`expr $cont + 25`
done
exit 0



0 comments on commit e138052

Please sign in to comment.