-
Notifications
You must be signed in to change notification settings - Fork 834
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for userCol and itemCol as string types in SAR model
Fixes #2275 Add support for `userCol` and `itemCol` as string types in the SAR model. * **Python Files:** - Add `core/src/main/python/synapse/ml/recommendation/SAR.py` to handle string `userCol` and `itemCol`. - Modify `core/src/main/python/synapse/ml/recommendation/SARModel.py` to handle string `userCol` and `itemCol` in the `recommendForUserSubset` function. * **Scala Files:** - Modify `core/src/main/scala/com/microsoft/azure/synapse/ml/recommendation/SAR.scala` to handle string `userCol` and `itemCol` in the `calculateUserItemAffinities` and `calculateItemItemSimilarity` functions. - Modify `core/src/main/scala/com/microsoft/azure/synapse/ml/recommendation/SARModel.scala` to handle string `userCol` and `itemCol`. * **Tests:** - Update `core/src/test/python/synapsemltest/recommendation/test_ranking.py` to include tests for string `userCol` and `itemCol`. - Update `core/src/test/scala/com/microsoft/azure/synapse/ml/recommendation/SARSpec.scala` to include tests for string `userCol` and `itemCol`. * **Documentation:** - Update `docs/Quick Examples/estimators/core/_Recommendation.md` to include examples with string `userCol` and `itemCol`. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/microsoft/SynapseML/issues/2275?shareId=XXXX-XXXX-XXXX-XXXX).
- Loading branch information
Showing
7 changed files
with
531 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Copyright (C) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See LICENSE in the project root for information. | ||
|
||
import sys | ||
|
||
if sys.version >= "3": | ||
basestring = str | ||
|
||
from synapse.ml.core.schema.Utils import * | ||
from synapse.ml.recommendation._SAR import _SAR | ||
|
||
@inherit_doc | ||
class SAR(_SAR): | ||
def __init__(self, **kwargs): | ||
_SAR.__init__(self, **kwargs) | ||
|
||
def calculateUserItemAffinities(self, dataset): | ||
if dataset.schema[self.getUserCol()].dataType == StringType(): | ||
dataset = dataset.withColumn(self.getUserCol(), dataset[self.getUserCol()].cast("int")) | ||
if dataset.schema[self.getItemCol()].dataType == StringType(): | ||
dataset = dataset.withColumn(self.getItemCol(), dataset[self.getItemCol()].cast("int")) | ||
return self._call_java("calculateUserItemAffinities", dataset) | ||
|
||
def calculateItemItemSimilarity(self, dataset): | ||
if dataset.schema[self.getUserCol()].dataType == StringType(): | ||
dataset = dataset.withColumn(self.getUserCol(), dataset[self.getUserCol()].cast("int")) | ||
if dataset.schema[self.getItemCol()].dataType == StringType(): | ||
dataset = dataset.withColumn(self.getItemCol(), dataset[self.getItemCol()].cast("int")) | ||
return self._call_java("calculateItemItemSimilarity", dataset) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
core/src/main/scala/com/microsoft/azure/synapse/ml/recommendation/SARModel.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.