<commit_before>// Databricks notebook source
// MAGIC %md
// MAGIC 
// MAGIC # [Scalable Data Science](http://www.math.canterbury.ac.nz/~r.sainudiin/courses/ScalableDataScience/)
// MAGIC 
// MAGIC 
// MAGIC ### prepared by [<NAME>](https://nz.linkedin.com/in/raazesh-sainudiin-45955845)
// MAGIC 
// MAGIC *supported by* [![](https://raw.githubusercontent.com/raazesh-sainudiin/scalable-data-science/master/images/databricks_logoTM_200px.png)](https://databricks.com/)
// MAGIC 
// MAGIC # Activity Recognition from Accelerometer using Random Forest
// MAGIC 
// MAGIC This work is a simpler databricksification of Amira Lakhal's more complex framework for activity recognition:
// MAGIC * [https://github.com/MiraLak/activityRecognitionV2](https://github.com/MiraLak/activityRecognitionV2).

// COMMAND ----------

val data = sc.textFile("dbfs:///datasets/sds/ActivityRecognition/dataTraining.csv")

// COMMAND ----------

data.take(5).foreach(println)

// COMMAND ----------

val dataDF = sqlContext.read    
    .format("com.databricks.spark.csv") // use spark.csv package
    .option("header", "true") // Use first line of all files as header
    .option("inferSchema", "true") // Automatically infer data types
    .option("delimiter", ",") // Specify the delimiter as ','
    .load("dbfs:///datasets/sds/ActivityRecognition/dataTraining.csv")

// COMMAND ----------

dataDF.printSchema()

// COMMAND ----------

display(dataDF)

// COMMAND ----------

dataDF.count()

// COMMAND ----------

dataDF.select($"user_id").distinct().show()

// COMMAND ----------

dataDF.select($"activity").distinct().show()

// COMMAND ----------

display(dataDF.sample(false,0.1))

// COMMAND ----------

// MAGIC %md
// MAGIC # Feature Selection on Running Windows

// COMMAND ----------<commit_msg>added ref to windows in DF<commit_after>// Databricks notebook source
// MAGIC %md
// MAGIC 
// MAGIC # [Scalable Data Science](http://www.math.canterbury.ac.nz/~r.sainudiin/courses/ScalableDataScience/)
// MAGIC 
// MAGIC 
// MAGIC ### prepared by [<NAME>](https://nz.linkedin.com/in/raazesh-sainudiin-45955845)
// MAGIC 
// MAGIC *supported by* [![](https://raw.githubusercontent.com/raazesh-sainudiin/scalable-data-science/master/images/databricks_logoTM_200px.png)](https://databricks.com/)
// MAGIC 
// MAGIC # Activity Recognition from Accelerometer using Random Forest
// MAGIC 
// MAGIC This work is a simpler databricksification of Amira Lakhal's more complex framework for activity recognition:
// MAGIC * [https://github.com/MiraLak/activityRecognitionV2](https://github.com/MiraLak/activityRecognitionV2).

// COMMAND ----------

val data = sc.textFile("dbfs:///datasets/sds/ActivityRecognition/dataTraining.csv")

// COMMAND ----------

data.take(5).foreach(println)

// COMMAND ----------

val dataDF = sqlContext.read    
    .format("com.databricks.spark.csv") // use spark.csv package
    .option("header", "true") // Use first line of all files as header
    .option("inferSchema", "true") // Automatically infer data types
    .option("delimiter", ",") // Specify the delimiter as ','
    .load("dbfs:///datasets/sds/ActivityRecognition/dataTraining.csv")

// COMMAND ----------

dataDF.printSchema()

// COMMAND ----------

display(dataDF)

// COMMAND ----------

dataDF.count()

// COMMAND ----------

dataDF.select($"user_id").distinct().show()

// COMMAND ----------

dataDF.select($"activity").distinct().show()

// COMMAND ----------

display(dataDF.sample(false,0.1))

// COMMAND ----------

// MAGIC %md
// MAGIC # Feature Selection on Running Windows

// COMMAND ----------

// MAGIC %md
// MAGIC See the following for a crash introduction to windows:
// MAGIC * [http://xinhstechblog.blogspot.co.nz/2016/04/spark-window-functions-for-dataframes.html](http://xinhstechblog.blogspot.co.nz/2016/04/spark-window-functions-for-dataframes.html)

// COMMAND ----------
{'fraction_non_alphanumeric': 0.2075812274368231, 'fraction_numerical': 0.011346054667354307, 'mean_word_length': 2.8751248751248752, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 10, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6745809', 'n_tokens_mistral': 1382, 'n_tokens_neox': 1219, 'n_words': 236}