本文整理汇总了Java中org.apache.mahout.cf.taste.impl.model.GenericPreference类的典型用法代码示例。如果您正苦于以下问题:Java GenericPreference类的具体用法?Java GenericPreference怎么用?Java GenericPreference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GenericPreference类属于org.apache.mahout.cf.taste.impl.model包,在下文中一共展示了GenericPreference类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testBuildKNNRecommender
import org.apache.mahout.cf.taste.impl.model.GenericPreference; //导入依赖的package包/类
@Test
public void testBuildKNNRecommender() {
GenericRecommenderBuilder rb = new GenericRecommenderBuilder();
FastByIDMap<PreferenceArray> userData = new FastByIDMap<PreferenceArray>();
userData.put(1, new GenericUserPreferenceArray(Arrays.asList(new GenericPreference(1, 1, 1),
new GenericPreference(1, 2, 1), new GenericPreference(1, 3, 1))));
userData.put(2, new GenericUserPreferenceArray(Arrays.asList(new GenericPreference(2, 1, 1),
new GenericPreference(2, 2, 1), new GenericPreference(2, 4, 1))));
DataModel dm = new GenericDataModel(userData);
Recommender rec = null;
String recommenderType = "org.apache.mahout.cf.taste.impl.recommender.GenericUserBasedRecommender";
String similarityType = "org.apache.mahout.cf.taste.impl.similarity.PearsonCorrelationSimilarity";
try {
rec = rb.buildRecommender(dm, recommenderType, similarityType);
} catch (RecommenderException e) {
e.printStackTrace();
}
assertTrue(rec instanceof GenericUserBasedRecommender);
}
开发者ID:recommenders,项目名称:rival,代码行数:21,代码来源:GenericRecommenderBuilderTest.java
示例2: extractRawStudentPreferenceData
import org.apache.mahout.cf.taste.impl.model.GenericPreference; //导入依赖的package包/类
private FastByIDMap<Collection<Preference>> extractRawStudentPreferenceData(CloseableIterator<StudentSubjectPreference> iterator) {
FastByIDMap<Collection<Preference>> rawData = new FastByIDMap<>();
iterator.forEachRemaining(it -> {
Collection<Preference> studentPreferences;
if (rawData.containsKey(it.getStudentId())) {
studentPreferences = rawData.get(it.getStudentId());
} else {
studentPreferences = new ArrayList<>();
rawData.put(it.getStudentId(), studentPreferences);
}
studentPreferences.add(new GenericPreference(it.getStudentId(), it.getSubjectId(), it.getPreferenceValue().floatValue()));
});
return rawData;
}
开发者ID:university-information-system,项目名称:uis,代码行数:18,代码来源:StudentNeighborhoodStoreImpl.java
示例3: DataModelWrapper
import org.apache.mahout.cf.taste.impl.model.GenericPreference; //导入依赖的package包/类
/**
* Constructs the wrapper using the provided model.
*
* @param model the model to be used to create the wrapped model
*/
public DataModelWrapper(final net.recommenders.rival.core.TemporalDataModelIF<Long, Long> model) {
FastByIDMap<Collection<Preference>> data = new FastByIDMap<Collection<Preference>>();
FastByIDMap<FastByIDMap<Long>> timestampData = new FastByIDMap<FastByIDMap<Long>>();
for (Long u : model.getUsers()) {
List<Preference> prefs = new ArrayList<Preference>();
FastByIDMap<Long> userTimestamps = new FastByIDMap<Long>();
timestampData.put(u, userTimestamps);
for (Long i : model.getUserItems(u)) {
Iterable<Long> timestamps = model.getUserItemTimestamps(u, i);
long t = -1;
if (timestamps != null) {
for (Long tt : timestamps) {
t = tt;
break;
}
}
userTimestamps.put(i, t);
prefs.add(new GenericPreference(u, i, model.getUserItemPreference(u, i).floatValue()));
}
data.put(u, prefs);
}
FastByIDMap<PreferenceArray> userData = GenericDataModel.toDataMap(data, true);
wrapper = new GenericDataModel(userData, timestampData);
}
开发者ID:recommenders,项目名称:rival,代码行数:31,代码来源:DataModelWrapper.java
示例4: testBuildDefaultRecommender
import org.apache.mahout.cf.taste.impl.model.GenericPreference; //导入依赖的package包/类
@Test
public void testBuildDefaultRecommender() {
RecommenderBuilder rb = new GenericRecommenderBuilder();
FastByIDMap<PreferenceArray> userData = new FastByIDMap<PreferenceArray>();
userData.put(1, new GenericUserPreferenceArray(Arrays.asList(new GenericPreference(1, 1, 1),
new GenericPreference(1, 2, 1), new GenericPreference(1, 3, 1))));
userData.put(2, new GenericUserPreferenceArray(Arrays.asList(new GenericPreference(2, 1, 1),
new GenericPreference(2, 2, 1), new GenericPreference(2, 4, 1))));
DataModel dm = new GenericDataModel(userData);
Recommender rec = null;
try {
rec = rb.buildRecommender(dm);
} catch (TasteException e) {
e.printStackTrace();
}
assertTrue(rec instanceof RandomRecommender);
}
开发者ID:recommenders,项目名称:rival,代码行数:20,代码来源:GenericRecommenderBuilderTest.java
示例5: getPrefDataByFileFast
import org.apache.mahout.cf.taste.impl.model.GenericPreference; //导入依赖的package包/类
public static DataModel getPrefDataByFileFast() throws Exception {
String data = EEG_INTEREST_LEVEL_DATASET_FILE;
FastByIDMap<PreferenceArray> preferences = new FastByIDMap<PreferenceArray>();
BufferedReader br = new BufferedReader(new FileReader(data));
List<Preference> list = new ArrayList<Preference>();
String line = br.readLine();
long uid_init = Long.parseLong(line.split(",")[0]);
while (line != null) {
String[] arr = line.split(",");
long uid = Long.parseLong(arr[0]);
if (uid_init == uid) {
list.add(new GenericPreference(uid, Long.parseLong(arr[1]),
Float.parseFloat(arr[2])));
} else {
preferences.put(uid_init, new GenericUserPreferenceArray(list));
list = new ArrayList<Preference>();
list.add(new GenericPreference(uid, Long.parseLong(arr[1]),
Float.parseFloat(arr[2])));
uid_init = uid;
}
line = br.readLine();
if (line == null) {
preferences.put(uid_init, new GenericUserPreferenceArray(list));
}
}
br.close();
return new GenericDataModel(preferences);
}
开发者ID:melrefaey,项目名称:EEGoVid,代码行数:31,代码来源:InterestLevelDataModel.java
示例6: addPreference
import org.apache.mahout.cf.taste.impl.model.GenericPreference; //导入依赖的package包/类
@Override
public void addPreference(Long u, Long i, Double d) {
if (model != null) {
throw new IllegalArgumentException("DataModel already generated. It is not possible to add more information.");
}
Collection<Preference> prefs = null;
if (!data.containsKey(u)) {
prefs = new ArrayList<Preference>();
data.put(u, prefs);
} else {
prefs = data.get(u);
}
prefs.add(new GenericPreference(u, i, d.floatValue()));
}
开发者ID:recommenders,项目名称:rival,代码行数:15,代码来源:MahoutDataModel.java
示例7: mapRow
import org.apache.mahout.cf.taste.impl.model.GenericPreference; //导入依赖的package包/类
@Override
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
return new GenericPreference(rs.getLong(1), rs.getLong(2), rs.getFloat(3));
}
开发者ID:major2015,项目名称:easyrec_major,代码行数:5,代码来源:MahoutDataModelMappingDAOMysqlImpl.java
注:本文中的org.apache.mahout.cf.taste.impl.model.GenericPreference类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论