train_model_data.sh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/bin/bash
  2. abs_path=$(cd `dirname $0`; pwd)
  3. sample_path="${abs_path}/../data"
  4. model_path="${abs_path}/../model"
  5. start_date=20250721
  6. end_date=20250727
  7. model_file="${model_path}/str_fm.txt"
  8. feature_file="${sample_path}/feature.csv"
  9. if(($#==4))
  10. then
  11. start_date=$1
  12. end_date=$2
  13. model_file=$3
  14. feature_file=$4
  15. else
  16. start_date=$(date +%Y%m%d -d "-15 $days day")
  17. end_date=$(date +%Y%m%d -d "-2 $days day")
  18. fi
  19. sample_file_list=""
  20. for((i=0; i<=21; i++))
  21. do
  22. data_date=$(date -d "$start_date $i day" +"%Y%m%d")
  23. if [ "$data_date" -le "$end_date" ]
  24. then
  25. tmp_path=$sample_path
  26. test_file="${tmp_path}/${data_date}_00000.csv"
  27. if [ ! -f $test_file ]
  28. then
  29. tmp_path="/data2/jch/project/return_of_view_v6/data"
  30. test_file="${tmp_path}/${data_date}_00000.csv"
  31. fi
  32. if [ -f $test_file ]
  33. then
  34. sample_file="${tmp_path}/${data_date}_00*.csv"
  35. if [[ -z $sample_file_list ]]
  36. then
  37. sample_file_list=$sample_file
  38. else
  39. sample_file_list="$sample_file_list $sample_file"
  40. fi
  41. fi
  42. fi
  43. done
  44. # filter feature
  45. filter_feature="${abs_path}/../data/filter_feature.csv"
  46. if [ -f $filter_feature ]
  47. then
  48. local_feature="${feature_file}.tmp"
  49. awk '{if(NR==FNR){a[$1]=1}else{if(!($1 in a)){print}}}' $filter_feature $feature_file > $local_feature
  50. wait
  51. sleep 20s
  52. feature_file=$local_feature
  53. fi
  54. # model name
  55. model_prefix=`echo $model_file | awk -F".txt" '{print $1}'`
  56. off_model_file="${model_prefix}_offline.txt"
  57. # train
  58. #trainTools="/data2/jch/package/alphaFM/bin/fm_train"
  59. trainTools="/data2/jch/package/onlyTest/alphaFM/bin/fm_train"
  60. trainParam="-dim 1,1,8 -core 24"
  61. echo `date` "cat $sample_file_list | $trainTools -m $off_model_file $trainParam"
  62. cat $sample_file_list | $trainTools -m $off_model_file $trainParam -feature $feature_file -min_feature_cnt 200 &
  63. wait
  64. sleep 30s
  65. # transform model
  66. trans_py="${abs_path}/../src/tools/offline2online_fm.py"
  67. echo `date` "python3 $trans_py --input $off_model_file --output $model_file"
  68. python3 $trans_py --input $off_model_file --output $model_file &
  69. wait
  70. sleep 30s