Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions python/pyspark/mllib/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def _java2py(sc, r, encoding="bytes"):
return RDD(jrdd, sc)

if clsName == 'DataFrame':
return DataFrame(r, SQLContext(sc))
return DataFrame(r, SQLContext.getOrCreate(sc))

if clsName in _picklable_classes:
r = sc._jvm.SerDe.dumps(r)
Expand All @@ -125,7 +125,7 @@ def callJavaFunc(sc, func, *args):

def callMLlibFunc(name, *args):
""" Call API in PythonMLLibAPI """
sc = SparkContext._active_spark_context
sc = SparkContext.getOrCreate()
api = getattr(sc._jvm.PythonMLLibAPI(), name)
return callJavaFunc(sc, api, *args)

Expand All @@ -135,7 +135,7 @@ class JavaModelWrapper(object):
Wrapper for the model in JVM
"""
def __init__(self, java_model):
self._sc = SparkContext._active_spark_context
self._sc = SparkContext.getOrCreate()
self._java_model = java_model

def __del__(self):
Expand Down
10 changes: 5 additions & 5 deletions python/pyspark/mllib/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class BinaryClassificationMetrics(JavaModelWrapper):

def __init__(self, scoreAndLabels):
sc = scoreAndLabels.ctx
sql_ctx = SQLContext(sc)
sql_ctx = SQLContext.getOrCreate(sc)
df = sql_ctx.createDataFrame(scoreAndLabels, schema=StructType([
StructField("score", DoubleType(), nullable=False),
StructField("label", DoubleType(), nullable=False)]))
Expand Down Expand Up @@ -103,7 +103,7 @@ class RegressionMetrics(JavaModelWrapper):

def __init__(self, predictionAndObservations):
sc = predictionAndObservations.ctx
sql_ctx = SQLContext(sc)
sql_ctx = SQLContext.getOrCreate(sc)
df = sql_ctx.createDataFrame(predictionAndObservations, schema=StructType([
StructField("prediction", DoubleType(), nullable=False),
StructField("observation", DoubleType(), nullable=False)]))
Expand Down Expand Up @@ -197,7 +197,7 @@ class MulticlassMetrics(JavaModelWrapper):

def __init__(self, predictionAndLabels):
sc = predictionAndLabels.ctx
sql_ctx = SQLContext(sc)
sql_ctx = SQLContext.getOrCreate(sc)
df = sql_ctx.createDataFrame(predictionAndLabels, schema=StructType([
StructField("prediction", DoubleType(), nullable=False),
StructField("label", DoubleType(), nullable=False)]))
Expand Down Expand Up @@ -338,7 +338,7 @@ class RankingMetrics(JavaModelWrapper):

def __init__(self, predictionAndLabels):
sc = predictionAndLabels.ctx
sql_ctx = SQLContext(sc)
sql_ctx = SQLContext.getOrCreate(sc)
df = sql_ctx.createDataFrame(predictionAndLabels,
schema=sql_ctx._inferSchema(predictionAndLabels))
java_model = callMLlibFunc("newRankingMetrics", df._jdf)
Expand Down Expand Up @@ -424,7 +424,7 @@ class MultilabelMetrics(JavaModelWrapper):

def __init__(self, predictionAndLabels):
sc = predictionAndLabels.ctx
sql_ctx = SQLContext(sc)
sql_ctx = SQLContext.getOrCreate(sc)
df = sql_ctx.createDataFrame(predictionAndLabels,
schema=sql_ctx._inferSchema(predictionAndLabels))
java_class = sc._jvm.org.apache.spark.mllib.evaluation.MultilabelMetrics
Expand Down
4 changes: 1 addition & 3 deletions python/pyspark/mllib/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

from py4j.protocol import Py4JJavaError

from pyspark import SparkContext, since
from pyspark import since
from pyspark.rdd import RDD, ignore_unicode_prefix
from pyspark.mllib.common import callMLlibFunc, JavaModelWrapper
from pyspark.mllib.linalg import (
Expand Down Expand Up @@ -100,8 +100,6 @@ def transform(self, vector):
:return: normalized vector. If the norm of the input is zero, it
will return the input vector.
"""
sc = SparkContext._active_spark_context
assert sc is not None, "SparkContext should be initialized first"
if isinstance(vector, RDD):
vector = vector.map(_convert_to_vector)
else:
Expand Down