Cassandra based Mahout user friend recommendations

。_饼干妹妹 提交于 2019-12-04 18:18:56

All the following instructions about required column families by CassandraDataMdoel should be performed in cassandra-cli under the keyspace you created (recommender or other name).

1: Table users

userID is the row key, each itemID has a separate column name, and value is the preference:

CREATE COLUMN FAMILY users
WITH comparator = LongType
AND key_validation_class=LongType
AND default_validation_class=FloatType;

Insert values:

set users[0][0]='1.0';
set users[1][0]='3.0';
set users[2][2]='1.0';

2: Table items

itemID is the row key, each userID has a separate column name, and value is the preference:

CREATE COLUMN FAMILY items
WITH comparator = LongType
AND key_validation_class=LongType
AND default_validation_class=FloatType;

Insert Values:

set items[0][0]='1.0';
set items[0][1]='3.0';
set items[2][2]='1.0';

3: Table userIDs

This table just has one row, but many columns, i.e. each userID has a separate column:

CREATE COLUMN FAMILY userIDs
WITH comparator = LongType
AND key_validation_class=LongType;

Insert Values:

set userIDs[0][0]='';
set userIDs[0][1]='';
set userIDs[0][2]='';

4: Table itemIDs:

This table just has one row, but many columns, i.e. each itemID has a separate column:

CREATE COLUMN FAMILY itemIDs
WITH comparator = LongType
AND key_validation_class=LongType;

Insert Values:

set itemIDs[0][0]='';
set itemIDs[0][1]='';
set itemIDs[0][2]='';

Complementing the answer above, for Cassandra 2.0 the new syntax is the following, according that cli is deprecated.

Table users:

CREATE TABLE users (userID bigint, itemID bigint, value float, PRIMARY KEY (userID, itemID));

Table items:

CREATE TABLE items (itemID bigint, userID bigint, value float, PRIMARY KEY (itemID, userID));

Table userIDs:

CREATE TABLE userIDs (id bigint, userID bigint PRIMARY KEY(id, userID));

Table itemIDs:

CREATE TABLE itemIDs (id bigint, itemID bigint PRIMARY KEY(id, itemID));

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!