Example #1
0
def test_load_data_from_csv_with_initial_mapping():
    csv = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data',
                       'data.csv')
    data, user_index, item_index = load_data_from_csv(csv, {
        'user_id7': 0,
        'user_id3': 1
    }, {
        'item_id53': 0,
        'item_id32': 1
    })
    assert_equal(data, [
        (2, 2),
        (1, 3),
        (0, 0),
        (0, 1),
        (0, 3),
        (3, 4),
        (3, 1),
    ])
    assert_equal(user_index, {
        'user_id7': 0,
        'user_id3': 1,
        'user_id1': 2,
        'user_id8': 3,
    })
    assert_equal(
        item_index, {
            'item_id53': 0,
            'item_id32': 1,
            'item_,id10': 2,
            'item_id0': 3,
            'item_id3': 4,
        })
Example #2
0
def test_load_data_from_csv_with_initial_mapping():
    csv = os.path.join(os.path.abspath(os.path.dirname(__file__)), "data", "data.csv")
    data, user_index, item_index = load_data_from_csv(
        csv, {"user_id7": 0, "user_id3": 1}, {"item_id53": 0, "item_id32": 1}
    )
    assert_equal(data, [(2, 2), (1, 3), (0, 0), (0, 1), (0, 3), (3, 4), (3, 1)])
    assert_equal(user_index, {"user_id7": 0, "user_id3": 1, "user_id1": 2, "user_id8": 3})
    assert_equal(item_index, {"item_id53": 0, "item_id32": 1, "item_,id10": 2, "item_id0": 3, "item_id3": 4})
Example #3
0
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from theano_bpr.utils import load_data_from_csv
from theano_bpr import BPR
import sys

if len(sys.argv) != 3:
    print "Usage: ./example.py training_data.csv testing_data.csv"
    sys.exit(1)

# Loading train data
train_data, users_to_index, items_to_index = load_data_from_csv(sys.argv[1])
# Loading test data
test_data, users_to_index, items_to_index = load_data_from_csv(
    sys.argv[2], users_to_index, items_to_index)

# Initialising BPR model, 10 latent factors
bpr = BPR(10, len(users_to_index.keys()), len(items_to_index.keys()))
# Training model, 30 epochs
bpr.train(train_data, epochs=30)
# Testing model
print bpr.test(test_data)
Example #4
0
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from theano_bpr.utils import load_data_from_csv
from theano_bpr import BPR
import sys

if len(sys.argv) != 3:
    print "Usage: ./example.py training_data.csv testing_data.csv"
    sys.exit(1)

# Loading train data
train_data, users_to_index, items_to_index = load_data_from_csv(sys.argv[1])
# Loading test data
test_data, users_to_index, items_to_index = load_data_from_csv(sys.argv[2], users_to_index, items_to_index)

# Initialising BPR model, 10 latent factors
bpr = BPR(10, len(users_to_index.keys()), len(items_to_index.keys()))
# Training model, 30 epochs
bpr.train(train_data, epochs=30)
# Testing model
print bpr.test(test_data)