def fit(self, params): if len(self.data) <= 1: self.DEBUG_INFO = "No samples are there!" self.changed("alert_generated") return X = np.asarray(self.data)[:, 0:2] y = np.asarray(self.data)[:, 2] self.clf = iSVC(C=params['C'], gamma=params['gamma'], degree=params['degree'], coef0=params['coef0'], kernel=params['kernel']) self.clf.fit(X, y) self.is_fitted = True self.changed("model_fitted")
def fit(self, params): if len(self.data) <= 1: self.DEBUG_INFO = "No samples are there!" self.changed("alert_generated") return X = np.asarray(self.data)[:, 0:2] y = np.asarray(self.data)[:, 2] self.clf = iSVC( C=params["C"], gamma=params["gamma"], degree=params["degree"], coef0=params["coef0"], kernel=params["kernel"], ) self.clf.fit(X, y) self.is_fitted = True self.changed("model_fitted")
# main function to test the SVC Model from matplotlib import pyplot as plt import utils from isvc import iSVC import numpy as np import isvc_gui as gui __author__ = 'morgan' clf = iSVC(display=True, gamma=1) # generate data X, y = utils.gen_noise_gauss(100) n = np.size(X, 0) big_x, big_y = utils.getBoxbyX(X, grid=30) big_xy = np.c_[big_x.reshape(big_x.size, 1), big_y.reshape(big_x.size, 1)] # add supervised labels y_semisupervised = np.zeros((n, 1)) n_perm = np.random.permutation(n) # random partition for labeling labeled_fraction = 0.1 num_labels = int(np.ceil(labeled_fraction*n)) # number of labeled examples based on the fraction of dataset size #print "Number of labels used: " + str(num_labels) y_semisupervised[n_perm[0:num_labels]] = y[n_perm[0:num_labels]].reshape(num_labels,1) # label selected examples #x_labeled = X[n_perm[0:num_labels], :] #y_labeled = y[n_perm[0:num_labels]] x_labeled_normal = X[np.where(y_semisupervised==-1)[0], :] x_labeled_anomaly = X[np.where(y_semisupervised==1)[0],:] x_labeled_unknown = X[np.where(y_semisupervised==0)[0],:] #build SVC model
__author__ = 'morgan' # main function to test the SVC Model from matplotlib import pyplot as plt import utils from isvc import iSVC import numpy as np import isvc_gui as gui clf = iSVC(display=True, gamma=1) #generate data X, y = utils.gen_noise_gauss(100) n = np.size(X, 0) big_x, big_y = utils.getBoxbyX(X, grid=30) big_xy = np.c_[big_x.reshape(big_x.size, 1), big_y.reshape(big_x.size, 1)] # add supervised labels y_semisupervised = np.zeros((n, 1)) n_perm = np.random.permutation(n) # random partition for labeling labeled_fraction = 0.1 num_labels = int(np.ceil( labeled_fraction * n)) # number of labeled examples based on the fraction of dataset size #print "Number of labels used: " + str(num_labels) y_semisupervised[n_perm[0:num_labels]] = y[n_perm[0:num_labels]].reshape( num_labels, 1) # label selected examples #x_labeled = X[n_perm[0:num_labels], :] #y_labeled = y[n_perm[0:num_labels]] x_labeled_normal = X[np.where(y_semisupervised == -1)[0], :] x_labeled_anomaly = X[np.where(y_semisupervised == 1)[0], :]