资源简介

本文档主要是协同过滤算法实现的电影推荐系统源码,对应本人博客MapReduce基于物品的协同过滤算法实现电影推荐系统。欢迎大家关注数据科学,关注我。谢谢

资源截图

代码片段和文件信息

package com.paradeto.recommend;

import java.io.IOException;
import java.text.SimpleDateFormat;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.DistributedFileSystem;
import org.apache.hadoop.io.IOUtils;

/**
 * HDFS文件操作
 * @author youxingzhi
 *
 */
public class HDFSFile {
Configuration conf = new Configuration();
private FileSystem hdfs;
/**
 * 构造方法
 * @param hdfsPath
 * @throws IOException
 */
public HDFSFile(Path hdfsPath) throws IOException{
hdfs = hdfsPath.getFileSystem(conf);
}
/**
 * 创建目录
 * @param path
 * @throws IOException
 */
public void mkDir(Path path) throws IOException{
hdfs.mkdirs(path);
}
/**
 * 上传文件
 * @param src
 * @param dst
 * @throws IOException
 */
public void copyLocalToHdfs(Path srcPath dst) throws IOException{
hdfs.copyFromLocalFile(src dst);
}
/**
 * 删除文件
 * @param path
 * @throws IOException
 */
@SuppressWarnings(“deprecation“)
public void delFile(Path path) throws IOException{
hdfs.delete(path);
}
/**
 * 读取文件内容
 * @param path
 * @throws IOException
 */
public void readFile(Path path) throws IOException{
//获取文件信息
FileStatus filestatus = hdfs.getFileStatus(path);
//FS的输入流
FSDataInputStream in = hdfs.open(path);
//用Hadoop的IOUtils工具方法来让这个文件的指定字节复制到标准输出流上
IOUtils.copyBytes(inSystem.out(int)filestatus.getLen()false);
System.out.println();
}
/**
 * 得到文件的修改时间
 * @param path
 * @throws IOException
 */
public void getModifyTime(Path path) throws IOException{
FileStatus files[] = hdfs.listStatus(path);
for(FileStatus file: files){
//time = file.getModificationTime().
SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd hh:mm:ss“);
String date = sdf.format(file.getModificationTime());
System.out.println(file.getPath()+“\t“+date);
}
}
/**
 * 在hdfs上创建文件并写入内容
 * @param path
 * @param content
 * @throws IOException
 */
public void writeFile(Path pathString content) throws IOException{
FSDataOutputStream os = hdfs.create(path);
//以utf-8的格式写入文件
os.write(content.getBytes(“UTF-8“));
os.close();
}
/**
 * 列出某一路径下所有的文件
 * @param path
 * @throws IOException
 */
public void listFiles(Path path) throws IOException{
hdfs = path.getFileSystem(conf);
FileStatus files[] = hdfs.listStatus(path);
int listlength=files.length;  
        for (int i=0 ;i            if (files[i].isDir() == false) {  
                System.out.println(“filename:“  
                 + files[i].getPath()  + “\tsize:“  
                        + files[i].getLen());  
            } else {  
                Path newpath = new Path(files[i].getPath().toString());  
                listFiles(newpath);  
            }  
        }  
}
public static void main (String arg[]) throws Exception{
//
HDF

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2016-06-03 02:33  Recommend-master\
     文件        2379  2016-06-03 02:33  Recommend-master\README.md
     目录           0  2016-06-03 02:33  Recommend-master\code\
     目录           0  2016-06-03 02:33  Recommend-master\code\recommend\
     文件        5186  2016-06-03 02:33  Recommend-master\code\recommend\.classpath
     文件         420  2016-06-03 02:33  Recommend-master\code\recommend\.project
     目录           0  2016-06-03 02:33  Recommend-master\code\recommend\bin\
     目录           0  2016-06-03 02:33  Recommend-master\code\recommend\bin\com\
     目录           0  2016-06-03 02:33  Recommend-master\code\recommend\bin\com\paradeto\
     目录           0  2016-06-03 02:33  Recommend-master\code\recommend\bin\com\paradeto\recommend\
     文件        4329  2016-06-03 02:33  Recommend-master\code\recommend\bin\com\paradeto\recommend\HDFSFile.class
     文件        3128  2016-06-03 02:33  Recommend-master\code\recommend\bin\com\paradeto\recommend\Recommend.class
     文件        1224  2016-06-03 02:33  Recommend-master\code\recommend\bin\com\paradeto\recommend\SortHashMap$1.class
     文件        2595  2016-06-03 02:33  Recommend-master\code\recommend\bin\com\paradeto\recommend\SortHashMap.class
     文件        2754  2016-06-03 02:33  Recommend-master\code\recommend\bin\com\paradeto\recommend\Step1$Step1_ToItemPreMapper.class
     文件        2801  2016-06-03 02:33  Recommend-master\code\recommend\bin\com\paradeto\recommend\Step1$Step1_ToUserVectorReducer.class
     文件        2567  2016-06-03 02:33  Recommend-master\code\recommend\bin\com\paradeto\recommend\Step1.class
     文件        2467  2016-06-03 02:33  Recommend-master\code\recommend\bin\com\paradeto\recommend\Step2$Step2_UserVectorToConoccurrenceReducer.class
     文件        2997  2016-06-03 02:33  Recommend-master\code\recommend\bin\com\paradeto\recommend\Step2$Step2_UserVectorToCooccurrenceMapper.class
     文件        2469  2016-06-03 02:33  Recommend-master\code\recommend\bin\com\paradeto\recommend\Step2.class
     文件        3040  2016-06-03 02:33  Recommend-master\code\recommend\bin\com\paradeto\recommend\Step3$Step31_UserVectorSplitterMapper.class
     文件        2595  2016-06-03 02:33  Recommend-master\code\recommend\bin\com\paradeto\recommend\Step3$Step32_CooccurrenceColumnWrapperMapper.class
     文件        2764  2016-06-03 02:33  Recommend-master\code\recommend\bin\com\paradeto\recommend\Step3.class
     文件        4087  2016-06-03 02:33  Recommend-master\code\recommend\bin\com\paradeto\recommend\Step4_Update$Step4_AggregateReducer.class
     文件        3703  2016-06-03 02:33  Recommend-master\code\recommend\bin\com\paradeto\recommend\Step4_Update$Step4_PartialMultiplyMapper.class
     文件        2701  2016-06-03 02:33  Recommend-master\code\recommend\bin\com\paradeto\recommend\Step4_Update.class
     文件        2503  2016-06-03 02:33  Recommend-master\code\recommend\bin\com\paradeto\recommend\Step4_Update2$Step4_RecommendMapper.class
     文件        3285  2016-06-03 02:33  Recommend-master\code\recommend\bin\com\paradeto\recommend\Step4_Update2$Step4_RecommendReducer.class
     文件        2624  2016-06-03 02:33  Recommend-master\code\recommend\bin\com\paradeto\recommend\Step4_Update2.class
     文件        3373  2016-06-03 02:33  Recommend-master\code\recommend\bin\com\paradeto\recommend\Step5$Step5_FilterSortMapper.class
     文件        4780  2016-06-03 02:33  Recommend-master\code\recommend\bin\com\paradeto\recommend\Step5$Step5_FilterSortReducer.class
............此处省略52个文件信息

评论

共有 条评论