Ejemplo n.º 1
0
import numpy as np
from keras.utils.np_utils import to_categorical
from keras.wrappers.scikit_learn import KerasClassifier
from ionyx.contrib.keras_builder import KerasBuilder
from ionyx.datasets import DataSetLoader

print('Beginning keras builder test...')

data, X, y = DataSetLoader.load_forest_cover()
n_classes = len(np.unique(y)) + 1

model = KerasBuilder.build_dense_model(input_size=X.shape[1],
                                       output_size=n_classes,
                                       loss='categorical_crossentropy',
                                       metrics=['accuracy'])
model.fit(X, to_categorical(y, n_classes))
score = model.evaluate(X, to_categorical(y, n_classes))
print('Model score = {0}'.format(score[1]))

estimator = KerasClassifier(build_fn=KerasBuilder.build_dense_model,
                            input_size=X.shape[1],
                            output_size=n_classes,
                            loss='categorical_crossentropy',
                            metrics=['accuracy'])
estimator.fit(X, to_categorical(y, n_classes))
score = estimator.score(X, to_categorical(y, n_classes))
print('Estimator score = {0}'.format(score))

print('Done.')
Ejemplo n.º 2
0
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import KFold
from xgboost import XGBRegressor
from keras.wrappers.scikit_learn import KerasRegressor
from ionyx import Experiment
from ionyx.contrib.keras_builder import KerasBuilder
from ionyx.datasets import DataSetLoader

print('Beginning experiment test...')

data, _, _ = DataSetLoader.load_forest_cover()
X_cols = data.columns[1:].tolist()
y_col = data.columns[0]
logistic = LogisticRegression()
cv = KFold()
experiment = Experiment(package='sklearn',
                        model=logistic,
                        scoring_metric='accuracy',
                        verbose=True,
                        data=data,
                        X_columns=X_cols,
                        y_column=y_col,
                        cv=cv)
experiment.train_model()
experiment.cross_validate()
experiment.learning_curve()
param_grid = [{'alpha': [0.01, 0.1, 1.0]}]
experiment.param_search(param_grid,
                        save_results_path='/home/john/temp/search.csv')
print(experiment.best_model_)
experiment.save_model('/home/john/temp/model.pkl')