import numpy as np from rvm import RVMClassification from sklearn.cross_validation import train_test_split from sklearn.metrics import accuracy_score data = np.loadtxt("data_sets/german/german.data-numeric.txt") for el in data: if el[-1] == 2: el[-1] = 0 indexes = [i for i in range(24)] data_x = data[:, indexes] data_t = data[:, [24]] data_t = data_t.reshape((len(data_t), )) train_x, test_x, train_y, test_y = train_test_split(data_x, data_t, test_size=0.3) cl = RVMClassification(kernel='rbf') cl.fit(train_x, train_y) print(accuracy_score(cl.predict(test_x), test_y))
for i in range(n_ex // 2): p = np.random.rand(1, 2)[0, :] p[0] *= np.pi p[1] *= 1.5 while np.sin(p[0]) > p[1]: p = np.random.rand(1, 2)[0, :] p[0] *= np.pi p[1] *= 1.5 train_x.append(p) train_y.append(0) train_x = np.matrix(train_x) train_y = np.array(train_y) cl = RVMClassification(kernel="rbf", gamma=1) cl.fit(train_x, train_y) valid_x = np.matrix(np.random.uniform(0, 1, size=(50, 2))) valid_x[:, 1] *= 1.5 valid_x[:, 0] *= np.pi valid_y = np.sign(np.sin(valid_x[:, 0]) - valid_x[:, 1]) valid_y[valid_y == -1] = 0 predicted_y = cl.predict(valid_x) plt.plot(train_x[:, 0].A[:n_ex // 2], train_x[:, 1].A[:n_ex // 2], 'rx') plt.plot(train_x[:, 0].A[n_ex // 2:], train_x[:, 1].A[n_ex // 2:], 'gx')
import numpy as np from rvm import RVMClassification from sklearn.cross_validation import train_test_split from sklearn.metrics import accuracy_score data = np.loadtxt("data_sets/german/german.data-numeric.txt") for el in data: if el[-1] == 2: el[-1] = 0 indexes = [i for i in range(24)] data_x = data[:, indexes] data_t = data[:, [24]] data_t = data_t.reshape((len(data_t),)) train_x, test_x, train_y, test_y = train_test_split(data_x, data_t, test_size=0.3) cl = RVMClassification(kernel='rbf') cl.fit(train_x, train_y) print(accuracy_score(cl.predict(test_x), test_y))