-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
59 lines (44 loc) · 1.27 KB
/
plot.py
File metadata and controls
59 lines (44 loc) · 1.27 KB
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
__author__ = 'raza'
import numpy as np
from sklearn import svm
import sklearn.cross_validation as cv
from sklearn.grid_search import GridSearchCV
from sklearn.linear_model import LinearRegression
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
np.random.seed(43)
data = np.loadtxt('simulation_data.txt', skiprows=1, delimiter=',')
np.random.shuffle(data)
size = 10000
C = 10.0
gamma = 0.0
algo = 'Linear Regression'
x_train = data[:size, :-1]
y_train = data[:size, -1]
# estimator = svm.SVR(C=C, kernel='rbf', gamma=gamma)
# estimator = LinearRegression()
estimator = svm.SVR(C=C, kernel='rbf', gamma=gamma)
y_pred = estimator.fit(x_train, y_train).predict(x_train)
# 3D plot
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# ax.scatter(x_train[:, 0], x_train[:, 1], y_train, c='k', label='data')
plt.hold('on')
plt.plot(x_train[:, 0], x_train[:, 1], y_pred, c='g', label='RBF Model', linestyle=':')
ax.set_xlabel('# of tubes')
ax.set_ylabel('ratio')
ax.set_zlabel('conductance')
plt.title('SVR')
plt.legend()
plt.show()
# 2D plot
'''
plt.scatter(x_train[:, 0], y_train, c='k', label='data')
plt.hold('on')
# plt.plot(x_train, y_pred, c='g', label=algo)
plt.xlabel('# of tubes')
plt.ylabel('conductance')
plt.title('SVR')
plt.legend()
plt.show()
'''