-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrandom_forest_training.py
51 lines (35 loc) · 1.48 KB
/
random_forest_training.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
from data_generators import regression_data_generator as rdg
import measure_performance as mp
from experiments import random_forest_dataset_dimensions as random_forest_dimensions
from pyspark.storagelevel import StorageLevel
from spark_session import create_spark_session
from models import random_forest_regression as rfr
spark = create_spark_session()
# define the experiments
random_forest_dimensions = random_forest_dimensions()
# generate the data
num_features, num_samples = rdg.regression_generate_data(random_forest_dimensions['num_samples'], random_forest_dimensions['num_features'])
# Load the dataset
dataset = spark.read.format("libsvm").option("numFeatures", str(num_features)).load("data.libsvm")
dataset.persist(StorageLevel.MEMORY_AND_DISK)
# Define the k-means clustering model
random_forest = rfr.rf_model()
try:
mp.measure_performance(random_forest, dataset, "./results/random_forest.csv")
print("DONE")
with open("exec_log_random_forest.txt", "a") as file:
output = "DONE: num_features: {}, num_samples: {}\n".format(num_features, num_samples)
file.write(output)
file.close()
except Exception as e:
print(e)
with open("exec_log_random_forest.txt", "a") as file:
output = "ERROR: num_features: {}, num_samples: {}\n".format(num_features, num_samples)
file.write(output)
file.close()
dataset.unpersist()
# free the memory
del random_forest
del num_features
del dataset
del random_forest_dimensions