-
Notifications
You must be signed in to change notification settings - Fork 0
/
part_d_ml.py
52 lines (36 loc) · 1.5 KB
/
part_d_ml.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from pyspark.ml.classification import RandomForestClassifier
from pyspark import SparkContext
from pyspark.sql import SQLContext
from pyspark.ml.linalg import Vectors
sc = SparkContext()
sqlContext = SQLContext(sc)
def predict(df_train, df_test):
# TODO: Train random forest classifier
# Hint: Column names in the given dataframes need to match the column names
# expected by the random forest classifier `train` and `transform` functions.
# Or you can alternatively specify which columns the `train` and `transform`
# functions should use
# Result: Result should be a list with the trained model's predictions
# for all the test data points
return []
def main():
raw_training_data = sc.textFile("dataset/training.data")
# TODO: Convert text file into an RDD which can be converted to a DataFrame
# Hint: For types and format look at what the format required by the
# `train` method for the random forest classifier
# Hint 2: Look at the imports above
rdd_train = None
# TODO: Create dataframe from the RDD
df_train = None
raw_test_data = sc.textFile("dataset/test-features.data")
# TODO: Convert text file lines into an RDD we can use later
rdd_test = None
# TODO:Create dataframe from RDD
df_test = None
predictions = predict(df_train, df_test)
# You can take a look at dataset/test-labels.data to see if your
# predictions were right
for pred in predictions:
print(int(pred))
if __name__ == "__main__":
main()