def test_eliminate_NSGA(GaussianNB, RandomForestPipeline, LinearSVC): GaussianNB.fitness = Fitness((3, -2), 0, 0, 0) RandomForestPipeline.fitness = Fitness((4, -2), 0, 0, 0) LinearSVC.fitness = Fitness((3, -1), 0, 0, 0) eliminated = eliminate_from_pareto(pop=[GaussianNB, RandomForestPipeline, LinearSVC], n=1) assert eliminated == [GaussianNB], "The element (3, -2) is dominated by both others and should be eliminated." # Check order independence eliminated = eliminate_from_pareto(pop=[RandomForestPipeline, GaussianNB, LinearSVC], n=1) assert eliminated == [GaussianNB], "Individual should be dominated regardless of order."
def test_create_from_population(opset, GNB, ForestPipeline, LinearSVC): GNB.fitness = Fitness((3, -2), 0, 0, 0) ForestPipeline.fitness = Fitness((4, -2), 0, 0, 0) LinearSVC.fitness = Fitness((3, -1), 0, 0, 0) parents = [GNB, ForestPipeline, LinearSVC] new = create_from_population(opset, pop=parents, n=1, cxpb=0.5, mutpb=0.5) assert 1 == len(new) assert new[0]._id not in map(lambda i: i._id, parents) assert new[0].pipeline_str() not in map(lambda i: i.pipeline_str(), parents)
def evaluate_individual( individual: Individual, evaluate_pipeline: Callable, timeout: float = 1e6, deadline: Optional[float] = None, add_length_to_score: bool = True, **kwargs, ) -> Evaluation: """ Evaluate the pipeline specified by individual, and record Parameters ---------- individual: Individual Blueprint for the pipeline to evaluate. evaluate_pipeline: Callable Function which takes the pipeline and produces validation predictions, scores, estimators and errors. timeout: float (default=1e6) Maximum time in seconds that the evaluation is allowed to take. Don't depend on high accuracy. A shorter timeout is imposed if `deadline` is in less than `timeout` seconds. deadline: float, optional A time in seconds since epoch. Cut off evaluation at `deadline` even if `timeout` seconds have not yet elapsed. add_length_to_score: bool (default=True) Add the length of the individual to the score result of the evaluation. **kwargs: Dict, optional (default=None) Passed to `evaluate_pipeline` function. Returns ------- Evaluation """ result = Evaluation(individual, pid=os.getpid()) result.start_time = datetime.now() if deadline is not None: time_to_deadline = deadline - time.time() timeout = min(timeout, time_to_deadline) with Stopwatch() as wall_time, Stopwatch( time.process_time) as process_time: evaluation = evaluate_pipeline(individual.pipeline, timeout=timeout, **kwargs) result._predictions, result.score, result._estimators, result.error = evaluation result.duration = wall_time.elapsed_time if add_length_to_score: result.score = result.score + (-len(individual.primitives), ) individual.fitness = Fitness( result.score, result.start_time, wall_time.elapsed_time, process_time.elapsed_time, ) return result