Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ train = [
]
v = DictVectorizer()
X = v.fit_transform(train)
print X.toarray()
print(X.toarray())
[[ 19. 0. 0. 0. 1. 1. 0. 0. 0.]
[ 33. 0. 0. 1. 0. 0. 1. 0. 0.]
[ 55. 0. 1. 0. 0. 0. 0. 1. 0.]
Expand Down Expand Up @@ -102,7 +102,7 @@ Training RMSE: 0.43527
# Evaluate
preds = fm.predict(X_test)
from sklearn.metrics import mean_squared_error
print "FM RMSE: %.4f" % mean_squared_error(y_test,preds)
print("FM RMSE: %.4f" % mean_squared_error(y_test,preds))
FM RMSE: 0.9253

```
11 changes: 6 additions & 5 deletions pylibfm.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import random

import numpy as np
from sklearn import cross_validation
import random
from pyfm_fast import FM_fast, CSRDataset

from pyfm_fast import CSRDataset, FM_fast

LEARNING_RATE_TYPES = {"optimal": 0, "invscaling": 1, "constant": 2}
TASKS = {"regression": 0, "classification" : 1}
Expand Down Expand Up @@ -172,7 +174,7 @@ def fit(self, X, y):

# use sklearn to create a validation dataset for lambda updates
if self.verbose == True:
print "Creating validation dataset of %.2f of training for adaptive regularization" % self.validation_size
print("Creating validation dataset of %.2f of training for adaptive regularization" % self.validation_size)
X_train, validation, train_labels, validation_labels = cross_validation.train_test_split(
X, y, test_size=self.validation_size)
self.num_attribute = X_train.shape[1]
Expand Down Expand Up @@ -212,7 +214,7 @@ def fit(self, X, y):
# report epoch information
if self.verbose == True:
print("-- Epoch %d" % (epoch + 1))
print "Train RMSE: %.5f" % (self.sumloss / self.count)
print("Train RMSE: %.5f" % (self.sumloss / self.count))

def predict(self, X):
"""Predict using the factorization machine
Expand All @@ -238,4 +240,3 @@ def _make_dataset(X, y_i):
sample_weight = np.ones(X.shape[0], dtype=np.float64, order='C') # ignore sample weight for the moment
dataset = CSRDataset(X.data, X.indptr, X.indices, y_i, sample_weight)
return dataset