juan sebastian mora zapata

All generations.

generate functionThu, 04 May 2023

Construir un árbol de regresión para predecir el salario de las personas, teniendo en cuenta las demás variables existentes. Presentar el mse, para el mejor árbol de regresión encontrado. Determinar el salario esperado que podrían tener las personas de 25 y las de 30 años. Determinar el salario que podrían tener: - Una mujer de 32 años, compradora. - Un hombre de 23 años, no comprador.

# import the library import pandas as pd # import the dataset dataframe = pd.read_csv("/content/sample_data/california_housing_test.csv") # show the data dataframe.head()

Python
View
generate functionThu, 04 May 2023

Haz un ejemplo de la aplicación de la librería PyGAD Python para algoritmos genéticos

import pygad as pg import numpy as np # Defining the fitness function. This function receives a list of bit-strings (i.e. the chromosome). def fitness_func(chromosome): # The chromosome is a numpy array of 32-bits. Therefore, we can compute the floating-point number as follows. chromosome_sum = np.sum(chromosome) # We return the fitness value (the objective value) of the chromosome. return chromosome_sum # The solver performs the minimization of the fitness function. Therefore, the lower the objective value # the better the solution. # The user can specify the `number_of_bits` which is the number of bits per chromosome. solver = pg.genetic_algorithm(population_size=50, number_of_generations=50, fitness_func=fitness_func, number_of_bits=32) # Solving the problem (running the optimization process). solver.run() # Getting the best solution after running the optimization process. best_solution

Python
View
generate functionThu, 04 May 2023

Haz un ejemplo de la aplicación de la librería PyGAD Python para algoritmos genéticos

from pygad import GA import numpy as np # Define the function that the GA will optimise. def fitness_function(solution): x, y = solution return (x - 2) ** 2 + (y - 2) ** 2 ga = GA(num_generations=50, sol_per_pop=50, num_parents_mating=10, fitness_func=fitness_function, crossover_prob=0.7, mutation_prob=0.1, lower_bound=[-100, -100], upper_bound=[100, 100]) ga.run() print(ga.best_solution()) print(ga.best_solution_fitness())

Python
View
generate functionFri, 12 May 2023

Supongamos que desea saber si alguien de su familia está en casa, basándose en la siguiente información:  Si su esposa sale de casa, usualmente (pero no siempre) enciende la luz de la entrada  Hay otras ocasiones en las que también enciende la luz de la entrada  Si no hay nadie en casa, el perro está fuera  Si el perro tiene problemas intestinales, también se deja fuera  Si el perro está fuera, usted oye sus ladridos  Podría oír ladridos y pensar que son de su perro aunque no fuera así. Plantear: 1. Red bayesiana 2. Asignar probabilidades en forma libre. 3. Hallar la probabilidad de que haya alguien esté en la casa, si se observa que el perro está afuera y la luz de entrada está prendida.

import pgmpy from pgmpy.models import BayesianModel from pgmpy.factors.discrete import TabularCPD from pgmpy.inference import VariableElimination import numpy as np familiar_model = BayesianModel([('luz', 'persona'), ('perro', 'persona')]) cpd_luz = TabularCPD(variable='luz', variable_card=2, values=np.array([[0.5, 0.9], [0.5, 0.1]]), evidence=['persona'], evidence_card=[2]) cpd_perro = TabularCPD(variable='perro', variable_card=2, values=np.array([[0.9, 0.1], [0.1, 0.9]]), evidence=['persona'], evidence_card=[2]) cpd_persona = TabularCPD(variable='persona', variable_card=2, values=np.array([[0.9, 0.2], [

Python
View
generate functionThu, 04 May 2023

Haz un ejemplo de la aplicación de la librería PyGAD Python para algoritmos genéticos

from pygad import pygad def fitness_function(solution): """ This is a fitness function which returns the solution's value as is. """ return solution # Initializing the PyGAD class with the following parameters: # 1. sol_per_pop: This is the number of solutions in the population (e.g. number of chromosomes). # 2. num_generations: This is the number of generations (or iterations). # 3. num_parents_mating: The number of solutions to be selected as parents in the mating process. # 4. fitness_func: This is the fitness function which is used to evaluate the solutions in the population. # 5. sol_dimension: This is the dimension of each solution in the population (e.g. the number of parameters of the problem) # 6. maximize: Set to True if the problem is to be maximized. Otherwise, set to False. # 7. mutation_percent_genes: The percentage of genes to mutate in the mutation process. num_generations = 5 sol_per_pop = 8

Python
View
generate functionThu, 04 May 2023

Haz un ejemplo de la aplicación de la librería PyGAD Python para algoritmos genéticos

import PyGAD as pg import random # Defining the fitness function for the genetic algorithm to optimize. def fitness_func(x): return (x[0] - 5)**2 + (x[1] - 5)**2 + (x[2] - 5)**2 + (x[3] - 5)**2 + (x[4] - 5)**2 # Defining the lower and upper bounds for the variables. lower_bound = [0, 0, 0, 0, 0] upper_bound = [10, 10, 10, 10, 10] # Initializing the genetic algorithm to solve the problem. ga_instance = pg.genetic_algorithm(parameters_ga) # Running the genetic algorithm to solve the problem. ga_instance.run() # Getting the best solution after running the genetic algorithm. best_solution, best_fitness, fitness_list = ga_instance.best_solution()

Python
View

Want to kickstart your project?Use the new AI Studio to create your code