亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Java編程通過(guò)匹配合并數(shù)據(jù)實(shí)例解析(數(shù)據(jù)預(yù)處理)

 更新時(shí)間:2018年01月24日 14:37:42   作者:sober_qianyang  
這篇文章主要介紹了Java編程通過(guò)匹配合并數(shù)據(jù)實(shí)例解析(數(shù)據(jù)預(yù)處理),分享了相關(guān)代碼示例,小編覺(jué)得還是挺不錯(cuò)的,具有一定借鑒價(jià)值,需要的朋友可以參考下

本文研究的主要是Java編程通過(guò)匹配合并數(shù)據(jù)(數(shù)據(jù)預(yù)處理)的相關(guān)內(nèi)容,具體如下。

數(shù)據(jù)描述

以下程序是對(duì)如下格式的數(shù)據(jù)進(jìn)行合并處理。

這個(gè)表的每一行表示用戶id及用戶的特征。其中,一個(gè)用戶只有一個(gè)特征向量,即第一列不會(huì)重復(fù)。

這張表的第一列,表示用戶的id,第二列表示用戶所看的電影,第三列表示用戶對(duì)電影的打分(1-13分),第四列表示用戶對(duì)電影的打分,但分值范圍是1-5分。

問(wèn)題描述

在做數(shù)據(jù)預(yù)處理時(shí),如何將第二張表添加上用戶特征呢?其實(shí),方法很簡(jiǎn)單,將第二張表的用戶id與第一張表的用戶id進(jìn)行匹配就行。合并結(jié)果如下圖所示。

數(shù)據(jù)處理程序

package deal;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/*
 * author:合肥工業(yè)大學(xué) 管院學(xué)院 錢(qián)洋 
 * email:1563178220@qq.com
*/
public class GetPUser {
	public static List<String> readDocs(String docsPath,String code) throws IOException{
		BufferedReader reader = new BufferedReader( new InputStreamReader( new FileInputStream( new File(docsPath)),code));
		String s=null;
		List<String> userproductscore=new ArrayList<String>();
		while ((s=reader.readLine())!=null) {
			userproductscore.add(s);
		}
		reader.close();
		return userproductscore;
	}
	public static HashMap<String, String> MAPread(String docsPath1,String code1) throws IOException{
		BufferedReader reader1 = new BufferedReader( new InputStreamReader( new FileInputStream( new File(docsPath1)),code1));
		String s1=null;
		HashMap<String,String> userfeaturemap=new HashMap<String,String>();
		while ((s1=reader1.readLine())!=null) {
			String arr[]=s1.split("\t");
			String feature="";
			for (int i = 1; i < arr.length; i++) {
				BigDecimal db = new BigDecimal(arr[i]);
				String ii = db.toPlainString();
				feature+=ii+" ";
			}
			userfeaturemap.put(s1.split("\t")[0], feature);
		}
		reader1.close();
		return userfeaturemap;
	}
	public static List<String> match(List<String> userproductscore,HashMap<String, String> userfeaturemap) throws IOException{
		List<String> userscoreandfeature=new ArrayList<>();
		for (int i = 0; i < userproductscore.size(); i++) {
			//獲取用戶id
			String user_id=userproductscore.get(i).split("\t")[0];
			//獲取用戶特征
			String userfeature = userfeaturemap.get(user_id);
			userscoreandfeature.add(userproductscore.get(i)+"\t"+userfeature);
			System.out.println(userproductscore.get(i)+"\t"+userfeature);
		}
		return userscoreandfeature;
	}
	public static void main(String[] args) throws IOException {
		//讀取兩個(gè)文本
		List<String> userproductscore=readDocs("data/train/ydata-ymovies-user-movie-ratings-train-v1_0.txt","gbk");
		HashMap<String, String> userfeaturemap=MAPread("data/fileofuser/yahoo.txt","utf-8");
		//匹配結(jié)果
		match(userproductscore,userfeaturemap);
	}
}

總結(jié)

以上就是本文關(guān)于Java編程通過(guò)匹配合并數(shù)據(jù)實(shí)例解析(數(shù)據(jù)預(yù)處理)的全部?jī)?nèi)容,希望對(duì)大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站其他相關(guān)專(zhuān)題,如有不足之處,歡迎留言指出。感謝朋友們對(duì)本站的支持!

相關(guān)文章

最新評(píng)論