SynapseML icon indicating copy to clipboard operation
SynapseML copied to clipboard

lightgbm performance

Open chibberto opened this issue 8 years ago • 2 comments

Hi, I was just trying to look at the performance of lightgbm when varying the number of partitions, and noticed that the model AUC performance is dropping as the number of partitions is increased. It may be that i'm not setting some parameters correctly.

The example is based loosely on here

I've had a look at other datasets and the issue isn't so noticeable when the data is bigger. I'm currently using mmlspark_2.11-0.14.dev13+1.g58a2027c.jar to test.

import pandas as pd
from pyspark.sql.types import IntegerType, StringType, StructType, StructField
from pyspark.ml.evaluation import BinaryClassificationEvaluator
from mmlspark import LightGBMClassifier
from pyspark.ml.feature import Tokenizer, HashingTF, VectorAssembler
from pyspark.sql.functions import size, split, col

dataFilePath = "BookReviewsFromAmazon10K.tsv"
textSchema = StructType([StructField("rating", IntegerType(), False),
                         StructField("text", StringType(), False)])
import os, urllib
if not os.path.isfile(dataFilePath):
    urllib.request.urlretrieve("https://mmlspark.azureedge.net/datasets/" + dataFilePath, dataFilePath)
rawData = spark.createDataFrame(pd.read_csv(dataFilePath, sep="\t", header=None), textSchema)

data = (rawData
    .withColumn('wordCount',size(split(col('text'), ' ')))
    .withColumn("label", rawData["rating"] > 3).drop("rating")
)

# Featurize text column
tokenizer = Tokenizer(inputCol="text", outputCol="tokenizedText")
numFeatures = 10000
hashingScheme = HashingTF(inputCol="tokenizedText",
                          outputCol="TextFeatures",
                          numFeatures=numFeatures)
tokenizedData = tokenizer.transform(data)
featurizedData = hashingScheme.transform(tokenizedData)

# Merge text and numeric features in one feature column
featureColumnsArray = ["TextFeatures", "wordCount"]
assembler = VectorAssembler(
    inputCols = featureColumnsArray,
    outputCol="features")
assembledData = assembler.transform(featurizedData)

# Select only columns of interest
# Convert rating column from boolean to int
processedData = assembledData \
                .select("label", "features") \
                .withColumn("label", assembledData.label.cast(IntegerType()))

# Prepare data for learning
train, test, validation = processedData.randomSplit([0.60, 0.20, 0.20], seed=123)

# Train the models on the 'train' data
learner = LightGBMClassifier(numLeaves = 50)
evaluator = BinaryClassificationEvaluator(rawPredictionCol="rawPrediction",
                                          metricName="areaUnderROC")

partitionSizes = [1,20,50,100]

bestAUC = {}

for numPartitions in partitionSizes:
    train2=train.coalesce(numPartitions).cache()
    
    # Train model
    model = learner.fit(train2)
    scoredData = model.transform(test)
    
    bestAUC[numPartitions] = evaluator.evaluate(scoredData)

print(bestAUC)

# {1: 0.8763641093123599, 20: 0.8051090981424239, 50: 0.7555895584049949, 100: 0.6619671328457325}

Regards, Chris

chibberto avatar Nov 09 '18 13:11 chibberto

@chibberto I would expect AUC to drop but that is dramatically more than what I would expect. Please see this explanation, which I think may actually be the reason for the performance drop here: https://github.com/Azure/mmlspark/issues/381#issuecomment-424406675 Also tagging @guolinke This dataset is actually quite small, with only 10k samples. One thing that I am curious about is the drop from 50 to 100 partitions - did you actually have more than 100 cores? In lightgbm we coalesce to the number of workers, and if you had less than 50 workers the result should actually be the same, say, for the 50 and 100 case. One thing that I would recommend trying is shuffling the data before doing the training. Also, as you increase the number of partitions, I would try increasing the number of iterations, to see if the drop in AUC can be recovered from - or perhaps just using a larger number of iterations for all cases (the default is 100).

imatiach-msft avatar Nov 09 '18 20:11 imatiach-msft

Thanks, I think I understand. The original test did use >100 cores and i've subsequently tested with fewer cores and it does have an impact on the results as you suggest, but the test results were slightly different... I guess this is due to different data being in each partition as per the link above. It's good to know about the shuffling too.

Also, I think the results may be a bit too sensitive without being cross validated so i'm going to close the issue. I will reopen if any further testing needs some of your help. Thanks once again.

chibberto avatar Nov 12 '18 17:11 chibberto