def __init__(self,TRAINVALTEST_DENSE_X,TRAINVALTEST_DENSE_X_NAMES,\ TRAINVAL_SPARSE_X,TRAINVAL_SPARSE_X_NAMES,\ TEST_SPARSE_X,TEST_SPARSE_X_NAMES,\ UF_VW,ADF,TRAINVAL,UF_CSV,TRAINVAL_MERGE,\ TEST_MERGE,TEST,name='ffm',USE_TINY=False,RANDOMSTATE=2018): super(FFM, self).__init__( TRAINVALTEST_DENSE_X,TRAINVALTEST_DENSE_X_NAMES,\ TRAINVAL_SPARSE_X,TRAINVAL_SPARSE_X_NAMES,\ TEST_SPARSE_X,TEST_SPARSE_X_NAMES,\ UF_VW,ADF,TRAINVAL,UF_CSV,TRAINVAL_MERGE,\ TEST_MERGE,TEST,name,USE_TINY,RANDOMSTATE=2018) '''In Ridge, only 'sag' solver can currently fit the intercept when X is sparse.''' self.clf = xl.FFMModel(task='binary', lr=0.2, epoch=10, reg_lambda=0.002, metric='auc')
# 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. import numpy as np import xlearn as xl # param: # 0. binary classification # 1. learning rate: 0.2 # 2. epoch number: 10 (auto early-stop) # 3. evaluation metric: accuracy # 4. use sgd optimization method ffm_model = xl.FFMModel(task='binary', lr=0.2, epoch=10, reg_lambda=0.002, metric='acc') # Start to train # Directly use string to specify data source ffm_model.fit('../criteo_ctr/small_train.txt', eval_set='../criteo_ctr/small_test.txt') # print model weights print(ffm_model.weights) # Generate predictions y_pred = ffm_model.predict('../criteo_ctr/small_test.txt')
nthread=None, n_jobs=4, alpha=1, beta=1, lambda_1=1, lambda_2=1) fmm_model = xl.FFMModel(model_type='ffm', task='binary', metric='auc', block_size=500, lr=0.2, k=4, reg_lambda=0.1, init=0.1, fold=1, epoch=5, stop_window=2, opt='sgd', nthread=None, n_jobs=4, alpha=1, beta=1, lambda_1=1, lambda_2=1) # Start to train for model in [linear_model, fm_model, fmm_model]: model.fit(X_train, y_train, fields=list(range(4)), eval_set=[X_val, y_val], is_lock_free=False)