本文整理汇总了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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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()));
}
示例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));
}