2016-08-22 2 views
4
여기

는 JSON에 LogisticRegression 모델로부터 예측을 기록하는 코드의 결과이다 :Spark에서 CSV로 쓸 때 벡터 값에 대해 무엇을합니까?

여기
(predictions 
     .drop(feature_col) 
     .rdd 
     .map(lambda x: Row(weight=x.weight, 
          target=x[target], 
          label=x.label, 
          prediction=x.prediction, 
          probability=DenseVector(x.probability))) 
     .coalesce(1) 
     .toDF() 
     .write 
     .json(
     "{}/{}/summary/predictions".format(path, self._model.bestModel.uid))) 

이다 일례 결과 JSON 개체 : 싶습니다

{"label":1.0,"prediction":0.0,"probability":{"type":1,"values":[0.5835784358591029,0.4164215641408972]},"target":"Male","weight":99} 

가 출력 할 수 있도록 동일한 데이터를 CSV 파일에 저장하십시오 (값 배열의 첫 번째 요소 인 probability.values[0]). 그러나 위 코드와 동일한 코드 조각을 사용하면 .json.csv으로 바꿔서 다음 결과를 얻습니다.

1.0,0.0,"[6,1,0,0,280000001c,c00000002,af154d3100000014,a1d5659f3fe2acac,3fdaa6a6]",Male,99 

세 번째 열 (문자열에 값의 묶음이있는 배열)은 어떻게됩니까?

답변

0

"확률"이 벡터보다 많으면 json 형식이므로 이상한 객체 직렬화가 발생합니다.

봅니다 먼저 문자열로 덤프

withColumn("probability", col("probability").cast("string")) 
관련 문제