示例#1
0
    def update_best(self, new_best, new_fn, *args):
        with open("meddocan.log", "a") as fp:
            fp.write(f"solution={repr(new_best)}\nfitness={new_fn}\n\n")

# Basic logging configuration.

logger = MemoryLogger()
loggers = [ProgressLogger(), ConsoleLogger(), logger]

if args.token:
    from autogoal.contrib.telegram import TelegramLogger

    telegram = TelegramLogger(
        token=args.token,
        name=f"MEDDOCAN",
        channel=args.channel,
    )
    loggers.append(telegram)

# Finally, loading the MEDDOCAN dataset, running the `AutoML` instance,
# and printing the results.

X_train, y_train, X_test, y_test = meddocan.load(max_examples=args.examples)

classifier.fit(X_train, y_train, logger=loggers)
score = classifier.score(X_test, y_test)

print(score)
print(logger.generation_best_fn)
print(logger.generation_mean_fn)
示例#2
0
from autogoal.contrib.keras import KerasSequenceClassifier
from autogoal.contrib.torch import BertEmbedding
from autogoal.datasets import haha
from autogoal.kb import CategoricalVector, List, Sentence, Tuple
from autogoal.ml import AutoML
from autogoal.search import ConsoleLogger, ProgressLogger

classifier = AutoML(
    input=List(Sentence()),
    registry=[KerasSequenceClassifier, BertEmbedding],
    # search_kwargs=dict(memory_limit=4 * 1024 ** 3, evaluation_timeout=60),
    search_kwargs=dict(memory_limit=0, evaluation_timeout=0),
)

Xtrain, Xtest, ytrain, ytest = haha.load(max_examples=10)

# embedding = BertEmbedding()
# tokens = embedding.run(Xtrain)

# classifier = KerasSequenceClassifier().sample()
# classifier.run((tokens, ytrain))

classifier.fit(Xtrain, ytrain, logger=[ConsoleLogger(), ProgressLogger()])
示例#3
0
# AutoGOAL Example: basic usage of the AutoML class

from autogoal.datasets import cars
from autogoal.kb import MatrixContinuousDense, Supervised, VectorCategorical
from autogoal.ml import AutoML

# Load dataset
X, y = cars.load()

# Instantiate AutoML and define input/output types
automl = AutoML(
    input=(MatrixContinuousDense, Supervised[VectorCategorical]),
    output=VectorCategorical,
    search_iterations=1,
)

# Run the pipeline search process
automl.fit(X[0:10], y[0:10])

# Report the best pipeline
print(automl.best_pipeline_)
print(automl.best_score_)

# Export the result of the search process onto a brand new image called "AutoGOAL-Cars"
automl.export_portable()
示例#4
0
# AutoGOAL Example: basic usage of the AutoML class

from autogoal.datasets import cars
from autogoal.kb import MatrixContinuousDense, Supervised, VectorCategorical
from autogoal.ml import AutoML

# Load dataset
X, y = cars.load()

# Instantiate AutoML and define input/output types
automl = AutoML(
    input=(MatrixContinuousDense, Supervised[VectorCategorical]),
    output=VectorCategorical,
)

# Run the pipeline search process
automl.fit(X, y)

# Report the best pipeline
print(automl.best_pipeline_)
print(automl.best_score_)
                    search_iterations=args.iterations,
                    pop_size=args.popsize,
                    selection=args.selection,
                    evaluation_timeout=args.timeout,
                    memory_limit=args.memory * 1024**3,
                    early_stop=args.early_stop,
                    search_timeout=args.global_timeout,
                    target_fn=args.target,
                )

                loggers = [
                    JsonLogger(
                        f"unsupervised-log-({n_features}, {centers}, {cluster_std}, {random_state}).json"
                    )
                ]
                automl.fit(X, logger=loggers)

            # generated dataset seed
            # name = f"features:{n_features}, centers:{centers}, cluster_std:{cluster_std}, rs:{random_state}"
            # print("generated dataset:", name)

            # plot purposes
            # pca = PCA(n_components=2)
            # X = pca.fit_transform(X)

            # color_map = get_cmap(centers)
            # features_colors_original = [color_map(y[i]) for i in range(len(X))]

            # #plot original clusters
            # plt.scatter(X[:, 0], X[:, 1],
            #             c=features_colors_original, marker='o',
示例#6
0
# ¿Cómo utilizamos esto en la clase AutoML?
automl = AutoML(
    input=(Seq[Sentence], Supervised[VectorCategorical]),  # **tipos de entrada**
    output=VectorCategorical,  # **tipo de salida**
    # tenemos el parámetro score_metric  para definir la función objetivo,
    # que si no le fijamos un valor utiliza por defecto la función `autogoal.ml.metrics.accuracy`.
)

# Ya hasta aquí hemos definido el problema que queremos resolver
# ahora solo nos resta ejecutar nuestro algoritmo, llamando al método `fit`.

# Para monitorear el estado del proceso de AutoML, podemos pasar un logger al método `fit`.
from autogoal.search import RichLogger

# Entrenando...
automl.fit(X_train, y_train, logger=RichLogger())

# Conociemdo que tan bueno es nuestro algoritmo
score = automl.score(X_test, y_test)
print(f"Score: {score:0.3f}")

# Esto significa que nuestro algoritmo el mejor pipeline que encontró reportó un accuracy "result"

# También puede llamarse al método predict que nos hace la predicción para un conjunto de ejemplos

# Prediciendo...
predictions = automl.predict(X_test)

for sentence, real, predicted in zip(X_test[:10], y_test, predictions):
    print(sentence, "-->", real, "vs", predicted)
def test_run_unsupervised():
    X = np.array([
        [
            0.0,
            0.0,
            0.0,
            1.0,
            1.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            1.0,
            0.0,
            0.0,
            0.0,
            1.0,
            1.0,
            0.0,
            0.0,
            0.0,
            1.0,
            0.0,
        ],
        [
            0.0,
            0.0,
            0.0,
            1.0,
            1.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            1.0,
            0.0,
            0.0,
            0.0,
            1.0,
            1.0,
            0.0,
            0.0,
            0.0,
            0.0,
            1.0,
        ],
        [
            0.0,
            0.0,
            0.0,
            1.0,
            1.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            1.0,
            0.0,
            0.0,
            0.0,
            1.0,
            1.0,
            0.0,
            0.0,
            1.0,
            0.0,
            0.0,
        ],
        [
            0.0,
            0.0,
            0.0,
            1.0,
            1.0,
            0.0,
            0.0,
            0.0,
            0.0,
            1.0,
            0.0,
            0.0,
            0.0,
            0.0,
            1.0,
            1.0,
            0.0,
            0.0,
            0.0,
            1.0,
            0.0,
        ],
        [
            0.0,
            0.0,
            0.0,
            1.0,
            1.0,
            0.0,
            0.0,
            0.0,
            0.0,
            1.0,
            0.0,
            0.0,
            0.0,
            0.0,
            1.0,
            1.0,
            0.0,
            0.0,
            0.0,
            0.0,
            1.0,
        ],
        [
            0.0,
            0.0,
            0.0,
            1.0,
            1.0,
            0.0,
            0.0,
            0.0,
            0.0,
            1.0,
            0.0,
            0.0,
            0.0,
            0.0,
            1.0,
            1.0,
            0.0,
            0.0,
            1.0,
            0.0,
            0.0,
        ],
        [
            0.0,
            0.0,
            0.0,
            1.0,
            1.0,
            0.0,
            0.0,
            0.0,
            1.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            1.0,
            1.0,
            0.0,
            0.0,
            0.0,
            1.0,
            0.0,
        ],
        [
            0.0,
            0.0,
            0.0,
            1.0,
            1.0,
            0.0,
            0.0,
            0.0,
            1.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            1.0,
            1.0,
            0.0,
            0.0,
            0.0,
            0.0,
            1.0,
        ],
        [
            0.0,
            0.0,
            0.0,
            1.0,
            1.0,
            0.0,
            0.0,
            0.0,
            1.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            1.0,
            1.0,
            0.0,
            0.0,
            1.0,
            0.0,
            0.0,
        ],
        [
            0.0,
            0.0,
            0.0,
            1.0,
            1.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            1.0,
            0.0,
            0.0,
            0.0,
            1.0,
            0.0,
            1.0,
            0.0,
            0.0,
            1.0,
            0.0,
        ],
    ])

    automl = AutoML(
        input=MatrixContinuousDense,
        output=VectorCategorical,
        score_metric=calinski_harabasz_score,
        search_timeout=120,
    )
    automl.fit(X, logger=loggers)
示例#8
0
# Una vez que tenemos listo nuestro algoritmo solo nos queda indicarle a la clase AutoML que lo utilice en la búsqueda

# Estos son algunos import que nos hacen falta más adelante
from autogoal.ml import AutoML
from autogoal.contrib import find_classes

# Probemos con HAHA
from autogoal.datasets import haha

# Cargando los datos
X_train, y_train, X_test, y_test = haha.load()

# Creando la instancia de AutoML con nuestra clase
automl = AutoML(
    input=(Seq[Sentence],
           Supervised[VectorCategorical]),  # **tipos de entrada**
    output=VectorCategorical,  # **tipo de salida**
    # Agregando nuestra clase y todo el resto de algortimos de AutoGOAL
    registry=[NewAlgorithm] + find_classes(),
)

# Ahora sencillamente tenemos que ejecutar AutoML y ya nuestro algoritmo aparecerá en algunos pipelines.
# Debemos tener en cuenta que esto no garantiza qeu aparezca en el mejor pipeline encontrado, sino que se conectará
# con el resto de los algoritmo como si fuera nativo de AutoGOAL.

automl.fit(X_train, y_train)

score = automl.score(X_test, y_test)
print(score)