microsoft / SynapseML

Simple and Distributed Machine Learning
http://aka.ms/spark
MIT License
5.02k stars 829 forks source link

SynapseML docs: Wrong variable referenced in code example in docs in "Interpretability - Explanation Dashboard" wrapper class #1555

Open glogowski-wojciech opened 2 years ago

glogowski-wojciech commented 2 years ago

Wrong variable referenced in code example in docs in "Interpretability - Explanation Dashboard" wrapper class In https://microsoft.github.io/SynapseML/docs/features/responsible_ai/Interpretability%20-%20Explanation%20Dashboard/ in the class wrapper there is:

class wrapper(object):
  [...]
  def predict(self, data):
    [...]
    return model.transform(sparkdata).select('prediction').toPandas().values.flatten().tolist()

  def predict_proba(self, data):
    [...]
    prediction = model.transform(sparkdata).select('probability').toPandas().values.flatten().tolist()
    [...]

which I believe should refer to self.model instead of just model:

class wrapper(object):
  [...]
  def predict(self, data):
    [...]
    return self.model.transform(sparkdata).select('prediction').toPandas().values.flatten().tolist()

  def predict_proba(self, data):
    [...]
    prediction = self.model.transform(sparkdata).select('probability').toPandas().values.flatten().tolist()
    [...]

Full body of the snippet for context:

class wrapper(object):
  def __init__(self, model):
    self.model = model

  def predict(self, data):
    sparkdata = spark.createDataFrame(data)
    return model.transform(sparkdata).select('prediction').toPandas().values.flatten().tolist()

  def predict_proba(self, data):
    sparkdata = spark.createDataFrame(data)
    prediction = model.transform(sparkdata).select('probability').toPandas().values.flatten().tolist()
    proba_list = [vector.values.tolist() for vector in prediction]
    return proba_list

I found the same issue in wrapper classes in the following files:

AB#1864607

imatiach-msft commented 2 years ago

@glogowski-wojciech great catch. Yes, that needs to be changed to self.model instead of model. I'll send a PR for the fix.

adityakode commented 1 year ago

@imatiach-msft I would love to fix that. Can I work on it?