-
Notifications
You must be signed in to change notification settings - Fork 4
/
training.py
58 lines (46 loc) · 1.65 KB
/
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
48
49
50
51
52
53
54
55
56
57
58
#import pandas as pd
import numpy as np
from sklearn.preprocessing import scale
from sklearn.metrics import mean_squared_error
#from sklearn.cross_validation import train_test_split
from sklearn.ensemble import RandomForestRegressor
from sklearn.svm import SVC
import preprocess
import math
F_no = 36
pot_func = preprocess.potential("data/smoke_pot.txt")
#shortest_distance = preprocess.shortest_dist("data/dist.txt")
features = preprocess.all_circles("data/obst.txt")
training_set_size = 100000
"""=
X_all = np.zeros(shape = (25, int(training_set_size*0.9)))
Y_all = np.zeros(shape = (1,int(training_set_size*0.9)))
X_test = np.zeros(shape = (25, int(training_set_size*0.1)))
Y_test = np.zeros(shape = (1,int(training_set_size*0.1)))
"""
train_size = int(training_set_size*0.9)
test_size = int(training_set_size*0.1)
X_all = np.zeros(shape = (train_size, F_no))
Y_all = np.zeros(shape = (train_size,1))
X_test = np.zeros(shape = (test_size, F_no))
Y_test = np.zeros(shape = (test_size,1))
#image = 0
for i in range(train_size):
for j in range(F_no):
#print("fa",features[i][j])
X_all[i][j] = float(features[i][j])
Y_all[i][0] = float(pot_func[i][:-1])
for i in range(test_size):
# if(i>number[image]):
# shortest_dist = shortest_dist[image]
for j in range(F_no):
X_test[i][j] = float(features[i+train_size][j])
Y_test[i][0] = float(pot_func[train_size+i][:-1])
#X_train = np.transpose(X_all)
#print(X_train)
#Y_train = np.transpose(Y_all)
forest_clf = RandomForestRegressor(n_estimators = 100, max_depth = 5, random_state = 0)
forest_clf.fit(X_all, Y_all.ravel())
Y_pred = forest_clf.predict(X_test)
print(Y_pred)
#rms_error=mean_squared_error(Y_test.ravel(),Y_pred)