利用艺术家的整数ID映射将标签转换为向量
来源:互联网 发布:武汉ui培训知乎 编辑:程序博客网 时间:2024/06/07 01:07
<strong><span style="font-size:18px;">/*** * @author YangXin * @info Mapper选择艺术家的整数特征ID然后建立单个特征的向量。这些一维的部分 * 向量会传给Reducer,后者会将这些向量简单地进行联结,生成一个完整的向量。 */package unitTwelve;import java.io.IOException;import java.util.HashMap;import java.util.Map;import java.util.regex.Pattern;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.io.DefaultStringifier;import org.apache.hadoop.io.LongWritable;import org.apache.hadoop.io.Text;import org.apache.hadoop.mapreduce.Mapper;import org.apache.hadoop.util.GenericsUtil;import org.apache.mahout.math.NamedVector;import org.apache.mahout.math.SequentialAccessSparseVector;import org.apache.mahout.math.VectorWritable;public class VectorMapper extends Mapper<LongWritable, Text, Text, VectorWritable>{private Pattern splitter;private VectorWritable writer;private Map<String, Integer> dictionary = new HashMap<String, Integer>();@Overrideprotected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException{String[] fields = splitter.split(value.toString());if(fields.length < 4){context.getCounter("Map", "LinesWithErrors").increment(1);return;}String arrtist = fields[1];String tag = fields[2];double weight = Double.parseDouble(fields[3]);NamedVector vector = new NamedVector(new SequentialAccessSparseVector(dictionary.size()), tag);vector.set(dictionary.get(value), weight);writer.set(vector);context.write(new Text(tag), writer);}@Overrideprotected void setup(Context context) throws IOException, InterruptedException{super.setup(context);Configuration conf = context.getConfiguration();DefaultStringifier<Map<String, Integer>> mapStringifier = new DefaultStringifier<Map<String, Integer>>(conf, GenericsUtil.getClass(dictionary));dictionary = mapStringifier.fromString(conf.get("dictionary"));splitter = Pattern.compile("<sep>");writer = new VectorWritable();}}</span></strong>
0 0
- 利用艺术家的整数ID映射将标签转换为向量
- 利用指针完成将一个数字字符串转换为int整数的程序。
- 将一个整数转换为若干连续整数的和
- 将二进制转换为整数,将十六进制转换为整数
- 将整数转换为字符串
- 将字符串转换为整数
- 将字符串转换为整数
- 将字符串转换为整数
- 将字符串转换为整数
- 将字符串转换为整数
- 将字符串转换为整数
- 将整数转换为进制数
- 将整数字符串转换为整数
- 将整数A转换为整数B
- 将Image的名字转换为R.image.id
- 将8进制字符串转换为整数的代码
- 如何将整数转换为相应的字符串
- itoa()函数将整数转换为字符串的一个例子
- Java你可能不知道的事系列1
- 代理模式Proxy入门 之帮你追求心仪的姑娘
- HDU 5636
- 四柱汉诺塔
- GC知识要点回顾
- 利用艺术家的整数ID映射将标签转换为向量
- selector修改TextView中字体的颜色
- 组合部分标签向量并累加成完整向量
- Qt QProgressBar 重写前的练习,了解Qt 槽函数的线程机制
- 使用excel来快捷计算日期的方法
- javascript--判空判等
- html js mysq 命名规范
- VS2015 调试失败 提示拒绝访问解决方法
- jenkins 安装