2017-11-27 4 views
0

組織の従業員に関するデータを含むサンプルデータセットがあります。データセットの下のスキーマを見つけてください。sparkデータフレームのsqlクエリに相関行列を適用する必要があります

私がここで解決しようとしている問題は、従業員が相関行列を使用して組織に固執する最も重要な基準は何か。 私はこれをspark/scalaのSQLクエリで解決しようとしています。

Schema of the Dataset 
|-- satisfaction_level: float 
|-- last_evaluation: float 
|-- number_project: integer 
|-- average_monthly_hours: integer 
|-- time_spend_company: integer 
|-- work_accident: integer 
|-- left: integer 
|-- promotion_last_5years: integer 
|-- department: string 
|-- salary: string 

私は、クエリ以下これを試してみましたが、私はsatisfaction_levelが下がっている時の従業員が組織を離れる傾向にあることを証明することができ、私の理解とデータの分析に従って、それは、私に何も結果が得られていない

val correlationVal = employeesDF.stat.corr("satisfaction_level","left") 

私は上記の問題を解決するためにSQLクエリを書く際に問題を発見していますが、誰も私にこれを手伝うことができますか?この問題の相関行列を適用する正しい方法は何ですか?

注:Sparkを使用してこの問題を解決するためのより簡単なアプローチがある場合は、入力してください。ここ

+0

あなたが言及したコードの結果はどうなりますか? –

答えて

0

は私のために動作し、最小限のコードである:

import org.apache.spark.sql.{DataFrame,Row} 
import org.apache.spark.sql.Row 
import org.apache.spark.sql.types._ 
import org.apache.spark.{SparkConf, SparkContext } 
import org.apache.spark.sql.hive.HiveContext 
val schema = StructType(Array(
     StructField("col1", IntegerType, true), 
     StructField("col2", FloatType, true) 
    )) 

val rdd = sc.parallelize(Seq(Row(1, 1.34.toFloat), Row(2, 2.02.toFloat), Row(3, 3.4.toFloat), Row(4, 4.2.toFloat))) 
val dataFrame = spark.createDataFrame(rdd, schema) 
dataFrame.stat.corr("col1","col2") 

結果はほぼ近くに1列が相関している指示さ0.9914です。

関連する問題