def Tensorflow_neural_network(X, y, Xt, yt): """ Classification Neural Networks Tensorflows module """ print("-------------------") yp = fns.tensorflow_NNWsolver(X, y, Xt, yt) # print(yp) a = fns.assert_binary_accuracy(yt, yp) return f"Tensorflow NN accuracy: {100*a:.0f} %"
def Sklearn_sgd_classifier(X, y, Xt, yt): """ Classification Logistic Regression Scikit-learns module: SGDClassifier """ print("-------------------") solution = sklearn.linear_model.SGDClassifier(eta0=0.01, max_iter=100).fit(X, y) yp = solution.predict(X) # print(yp) a = fns.assert_binary_accuracy(y, yp) return f"Sklearn\'s SGDClassifier accuracy: {100*a:.0f} %"
def declare_results(self, ytrue, ypred, round=True): """Declare the results, assign the accuracy""" if round: ypred[np.where(ypred>=0.5)] = 1 ypred[np.where(ypred<0.5)] = 0 for i in range(len(ytrue)): if i%20==0: print(f"Output:\t{ypred[i]}\tTrue:\t{ytrue[i]}" + (\ " Correct!" if ypred[i]==ytrue[i] else " ")) else: for i in range(len(ytrue)): print(f"Output:\t{ypred[i]}\tTrue:\t{ytrue[i]}") self.acc = fns.assert_binary_accuracy(ytrue, ypred)
def SGD_with_minibatches(X, y, Xt, yt, gamma, max_iter, batch_size, verbose=False): """ Classification Logistic Regression Our own SGD with mini-batches (see "./lib/logistic_regressionk.py") """ obj = lgr.StochasticGradientDescent(gamma, max_iter, batch_size, verbose=verbose) obj.fit(X, y) yp = obj.predict(Xt) # print(yp) a = fns.assert_binary_accuracy(y, yp) return f"SGD with mini-batches accuracy: {100*a:.0f} %"