def __test_tp1_task2(): np.random.seed(50) X, Y_ = data.sample_gmm(6, 2, 10) W1, b1, W2, b2 = fcann2_train(X, Y_, param_hidden_len=100) decfunc = fcann2_classify_new(W1, b1, W2, b2) Y = np.argmax(fcann2_classify(X, W1, b1, W2, b2), axis=1) bbox = (np.min(X, axis=0), np.max(X, axis=0)) data.graph_surface(decfunc, bbox, offset=0.5) data.graph_data(X, Y_, Y) plt.show()
def __test(): np.random.seed(100) X, Y_ = data.sample_gmm(6, 2, 10) svm = KSVMWrap(X, Y_) Y = svm.predict(X) accuracy, recall, precision = data.eval_perf_binary(Y, Y_) print("Accuracy : ", accuracy) print("Precision : ", precision) print("Recall : ", recall) bbox = (np.min(X, axis=0), np.max(X, axis=0)) data.graph_surface(svm.get_scores, bbox, offset=0) data.graph_data(X, Y_, Y, special=svm.support()) plt.show()
self.clf = self.clf.fit(X, Y_) self.support = self.clf.support_ #Indeksi podataka koji su odabrani za potporne vektore self.Y_ = Y_ def predict(self, X): return self.clf.predict(X) def get_scores(self, X): return classification_report(self.Y_, self.predict(X)) if __name__ == "__main__": # inicijaliziraj generatore slučajnih brojeva np.random.seed(100) #X,Y_ = data.sample_gmm(4, 2, 40) X, Y_ = data.sample_gmm(6, 2, 10) Yoh_ = data.class_to_onehot(Y_) svm2 = KSVMWrap(X, Y_) print(svm2.get_scores(X)) bbox = (np.min(X, axis=0), np.max(X, axis=0)) data.graph_surface(svm2.predict, bbox, offset=0.5, width=256, height=256) data.graph_data(X, Y_, svm2.predict(X), special=svm2.support) plt.show()
def logreg_classify(X, W, b): return output(X, W, b) def logreg_decfun(w, b): def classify(X): return logreg_classify(X, w, b) return classify if __name__ == "__main__": np.random.seed(100) # get the training dataset X, Y_ = data.sample_gmm(5, 2, 100) # train the model W, b = logreg_train(X, Y_) # evaluate the model on the training dataset probs, logprobs = logreg_classify(X, W, b) Y = np.argmax(probs, axis=1) # report performance accuracy, confusion_matrix, recall = data.eval_perf_multi(Y, Y_) print(accuracy, confusion_matrix, recall) data.graph_data(X, Y_, Y, special=[]) decfun = logreg_decfun(W, b)