通过weka机器学习传递双引号

时间:2015-09-24 16:13:20

标签: string bash escaping weka double-quotes

我正在使用Weka的 var interestItems = [String, NSNumber, Bool]() ,即vector<Vec4i> lines; Vec4i sheaf[10][200]; ,我尝试了许多不同的组合来传递几个参数但没有成功。当我这样通过时:

CLI

程序运行时没有问题,但传递的内容如下:

Primer
使用/ withOut转义字符,甚至是单引号`,在我的bash脚本中出现错误:

weka_options=("weka.classifiers.functions.SMOreg -C 1.0 -N 0")

weka_options=("weka.classifiers.functions.SMOreg -C 1.0 -N 0 -I \"weka.classifiers.functions.supportVector.RegSMOImproved -L 1.0e-3 -W 1 -P 1.0e-12 -T 0.001 -V\" -K \"weka.classifiers.functions.supportVector.NormalizedPolyKernel -C 250007 -E 8.0\"") 包含:

bash ./weka.sh "$sub_working_dir" $train_percentage "$weka_options" $files_string > $predictions

这是我得到的:

weka.sh

任何人都可以查明这个问题吗?

更新的问题:这是代码:

java -Xmx1024m -classpath ".:$WEKAPATH" $weka_options -t "$train_set" -T "$test_set" -c 53 -p 53

文件---Registering Weka Editors--- Trying to add database driver (JDBC): jdbc.idbDriver - Error, not in CLASSPATH? Weka exception: Can't open file No suitable converter found for '0.001'!. 是:

    # Usage:
# 
# ./aca2_explore.sh working-dir datasets/*
# e.g.
# ./aca2_explore.sh "aca2-explore-working-dir/" datasets/*
#
# Place this script in the same folder as aca2.sh and the folder containing the datasets. 
# 
#
# Please note that:
#   - All the notes contained in aca2.sh apply
#   - This script will erase the contents of working-dir

# to properly sort negative floating numbers, independently of local language options

export LC_ALL=C

# parameters parsing

output_directory=$1

first_file_index=2
files=${@:$first_file_index}

# global constants

datasets=$(($# - 1))
output_row=$(($datasets + 3))
output_columns_range="2-7"
learned_model_mae_column=4
results_learned_model_mae_column=4

# parameters

working_dir="$output_directory"
if [ -d "$working_dir" ];
then
    rm -r "$working_dir"
fi
mkdir "$working_dir"

sub_working_dir="$working_dir""aca2-explore-sub-working-dir/"
path_to_results_file="$sub_working_dir""results.csv"

train_percentage=25

logfile="$working_dir""aca2_explore_log.csv"
echo "" > "$logfile"

reduced_log_header="Options,average_test_set_speedup,null_model_mae,learned_model_mae,learned_model_rmse,mae_ratio,R^2"

reduced_logfile="$working_dir""aca2_explore_reduced_log.csv"
echo "$reduced_log_header" > "$reduced_logfile"

sorted_reduced_logfile="$working_dir""aca2_explore_sorted_reduced_log.csv"

weka_options_list=(
"weka.classifiers.functions.LinearRegression -S 0 -R 1.0E-8"
"weka.classifiers.functions.MultilayerPerceptron -L 0.3 -M 0.2 -N 100 -V 0 -S 0 -E 20 -H a"
"weka.classifiers.meta.AdditiveRegression -S 1.0 -I 10 -W weka.classifiers.trees.DecisionStump"
"weka.classifiers.meta.Bagging -P 100 -S 1 -num-slots 1 -I 10 -W weka.classifiers.trees.REPTree -- -M 2 -V 0.001 -N 3 -S 1 -L -1 -I 0.0"
"weka.classifiers.meta.CVParameterSelection -X 10 -S 1 -W weka.classifiers.rules.ZeroR"
"weka.classifiers.meta.MultiScheme -X 0 -S 1 -B \"weka.classifiers.rules.ZeroR \""
"weka.classifiers.meta.RandomCommittee -S 1 -num-slots 1 -I 10 -W weka.classifiers.trees.RandomTree -- -K 0 -M 1.0 -V 0.001 -S 1"
"weka.classifiers.meta.RandomizableFilteredClassifier -S 1 -F \"weka.filters.unsupervised.attribute.RandomProjection -N 10 -R 42 -D Sparse1\" -W weka.classifiers.lazy.IBk -- -K 1 -W 0 -A \"weka.core.neighboursearch.LinearNNSearch -A \"weka.core.EuclideanDistance -R first-last\"\""
"weka.classifiers.meta.RandomSubSpace -P 0.5 -S 1 -num-slots 1 -I 10 -W weka.classifiers.trees.REPTree -- -M 2 -V 0.001 -N 3 -S 1 -L -1 -I 0.0"
"weka.classifiers.meta.RegressionByDiscretization -B 10 -K weka.estimators.UnivariateEqualFrequencyHistogramEstimator -W weka.classifiers.trees.J48 -- -C 0.25 -M 2"
"weka.classifiers.meta.Stacking -X 10 -M \"weka.classifiers.rules.ZeroR \" -S 1 -num-slots 1 -B \"weka.classifiers.rules.ZeroR \""
"weka.classifiers.meta.Vote -S 1 -B \"weka.classifiers.rules.ZeroR \" -R AVG"
"weka.classifiers.rules.DecisionTable -X 1 -S \"weka.attributeSelection.BestFirst -D 1 -N 5\""
"weka.classifiers.rules.M5Rules -M 4.0"
"weka.classifiers.rules.ZeroR"
"weka.classifiers.trees.DecisionStump"
"weka.classifiers.trees.M5P -M 4.0"
"weka.classifiers.trees.RandomForest -I 100 -K 0 -S 1 -num-slots 1"
"weka.classifiers.trees.RandomTree -K 0 -M 1.0 -V 0.001 -S 1"
"weka.classifiers.trees.REPTree -M 2 -V 0.001 -N 3 -S 1 -L -1 -I 0.0")

files_string=""

for file in ${files[@]}
do
    files_string="$files_string""$file"" "
done

#echo $files_string

for weka_options in "${weka_options_list[@]}"
do
        echo "$weka_options"
        echo "$weka_options" >> "$logfile"
        bash ./aca2.sh "$sub_working_dir" $train_percentage "$weka_options" $files_string
        cat "$path_to_results_file" >> "$logfile"

        result_columns=$(tail -n +"$output_row" "$path_to_results_file"  | head -1 | cut -d, -f"$output_columns_range")
        echo "$weka_options"",""$result_columns" >> "$reduced_logfile"

        echo "" >> "$logfile"
done

tail -n +2 "$reduced_logfile" > "$sorted_reduced_logfile"
sort --field-separator=',' --key="$results_learned_model_mae_column" "$sorted_reduced_logfile" -o "$sorted_reduced_logfile"".tmp"
echo "$reduced_log_header" > "$sorted_reduced_logfile"
cat "$sorted_reduced_logfile"".tmp" >> "$sorted_reduced_logfile"
rm "$sorted_reduced_logfile"".tmp"

1 个答案:

答案 0 :(得分:1)

你几乎拥有这个权利。你试图做正确的事情(或者只是意外地关闭)。

不能将字符串用于任意引用的参数(这是Bash FAQ 050)。

您需要使用数组。但是你需要一个带有每个参数的单独元素的数组。不只是一个论点。

weka_options=(weka.classifiers.functions.SMOreg -C 1.0 -N 0)

weka_options=(weka.classifiers.functions.SMOreg -C 1.0 -N 0 -I "weka.classifiers.functions.supportVector.RegSMOImproved -L 1.0e-3 -W 1 -P 1.0e-12 -T 0.001 -V" -K "weka.classifiers.functions.supportVector.NormalizedPolyKernel -C 250007 -E 8.0")

(我假设字符串weka.classifiers.functions.supportVector.RegSMOImproved -L 1.0e-3 -W 1 -P 1.0e-12 -T 0.001 -V-I标志的参数,字符串weka.classifiers.functions.supportVector.NormalizedPolyKernel -C 250007 -E 8.0-K标志的参数。如果是这样的话。事实并非如此,那些引号可能也会被删除。)

然后当您使用数组时,您需要使用"${weka_options[@]}"将数组的元素作为单独的引用单词。

java -Xmx1024m -classpath ".:$WEKAPATH" "${weka_options[@]}" -t "$train_set" -T "$test_set" -c 53 -p 53