diff --git a/README.md b/README.md index 78695fd..e20d718 100644 --- a/README.md +++ b/README.md @@ -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.] @@ -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 ``` \ No newline at end of file diff --git a/pylibfm.py b/pylibfm.py index 48d6f41..ef22277 100644 --- a/pylibfm.py +++ b/pylibfm.py @@ -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} @@ -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] @@ -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 @@ -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 -