def paint_graphic(X, y, true_score, theta1, theta2, mu, sigma): figure, ax = plt.subplots() pos = (y == 1).ravel() neg = (y == 0).ravel() plt.scatter(X[pos, 0], X[pos, 1], color='blue', marker='o', label = "Legendary") plt.scatter(X[neg, 0], X[neg, 1], color='black', marker='x', label = "Non legendary") x0_min, x0_max = X[:,0].min(), X[:,0].max() x1_min, x1_max = X[:,1].min(), X[:,1].max() xx1, xx2 = np.meshgrid(np.linspace(x0_min, x0_max), np.linspace(x1_min, x1_max)) aux = np.c_[ xx1.ravel(), xx2.ravel()] p, aux = polinomial_features(aux, 5) aux = Normalization.normalize(aux[:, 1:], mu, sigma) sigm = forward_propagate(aux, theta1, theta2)[4] sigm = np.reshape(sigm, np.shape(xx1)) plt.contour(xx1, xx2, sigm, [0.5], linewidths = 1, colors=['red', 'purple']) #formatting the graphic with some labels plt.xlabel("weight_kg") plt.ylabel("speed") plt.suptitle(("Score: " + str(float("{0:.3f}".format(true_score))))) figure.legend() #set the labels to non-normalized values figure.canvas.draw() labels = [item for item in plt.xticks()[0]] for i in range(len(labels)): labels[i] = int(round((labels[i] * sigma[0, 0]) + mu[0, 0], -1)) ax.xaxis.set_ticklabels(labels) labels = [item for item in plt.yticks()[0]] for i in range(len(labels)): labels[i] = int(round((labels[i] * sigma[0, 1]) + mu[0, 1], -1)) ax.yaxis.set_ticklabels(labels) plt.show()
currentTrainY = (trainY == j) * 1 currentValidationY = (validationY == j) * 1 currentTestingY = (testingY == j) * 1 current_svm, C, s = eleccion_parametros_C_y_Sigma(trainX, currentTrainY, validationX, currentValidationY, mu, sigma) current_score = true_score(testingX, currentTestingY, current_svm) if np.shape(trainX)[1] == 2: draw_decisition_boundary(testingX, currentTestingY, current_svm, current_score, mu, sigma, C, s, Data_Management.getTypeByIndex(j)) svms.append(current_svm) print("Score con los ejemplos de testing: " + str(current_score) + " Type: " + Data_Management.getTypeByIndex(j)) while True: user_values = np.array(list(map(float, input("Gimme stats: ").split())), dtype=float) # (features, ) if user_values.size == 0: break user_values = np.reshape(user_values, (np.shape(user_values)[0], 1)) user_values = np.transpose(user_values) user_values = polynomial_features(user_values, grado) user_values = Normalization.normalize(user_values[:, 1:], mu, sigma) #normalization of user values sec, pokemon_type = predict_type(user_values, svms) print("Predicted type: " + Data_Management.getTypeByIndex(pokemon_type) + ". Probability of that type: " + str(sec) + "\n")