Exemple #1
0
 def __init__(self, app):
     self.app = app
     self.tests = load_test('tests.json')
Exemple #2
0
from sklearn.ensemble import RandomForestClassifier, ExtraTreesClassifier
from sklearn.naive_bayes import GaussianNB, BernoulliNB
from sklearn.pipeline import make_pipeline
from sklearn.tree import DecisionTreeClassifier
from tpot.builtins import StackingEstimator
from tools import prepare_dataset, load_test

y, x = prepare_dataset()

x_train = x[:614]
y_train = y[:614].reshape(-1, )

x_valid = x[614:]
y_valid = y[614:].reshape(-1, )

# Average CV score on the training set was:0.8469063987308303
exported_pipeline = make_pipeline(
    StackingEstimator(estimator=DecisionTreeClassifier(criterion="gini", max_depth=4, min_samples_leaf=15, min_samples_split=11)),
    StackingEstimator(estimator=BernoulliNB(alpha=0.01, fit_prior=False)),
    StackingEstimator(estimator=RandomForestClassifier(bootstrap=False, criterion="entropy", max_features=0.45, min_samples_leaf=3, min_samples_split=9, n_estimators=100)),
    StackingEstimator(estimator=ExtraTreesClassifier(bootstrap=False, criterion="gini", max_features=0.9000000000000001, min_samples_leaf=12, min_samples_split=16, n_estimators=100)),
    GaussianNB()
)

exported_pipeline.fit(x_train, y_train)

ids, x = load_test()
predictions = exported_pipeline.predict(x)

for index, id_number in enumerate(ids):
    print(str(int(id_number[0])) + "," + str(int(predictions[index])))
model.add(Dense(20))
model.add(LeakyReLU(0.1))

model.add(Dense(20))
model.add(LeakyReLU(0.1))

model.add(Dense(20))
model.add(LeakyReLU(0.1))

model.add(Dense(20))
model.add(LeakyReLU(0.1))

model.add(Dense(1, activation="sigmoid"))

optimizer = Nadam(lr=0.001)
model.compile(optimizer, 'binary_crossentropy', ['accuracy'])

model.fit(x, y, validation_split=0.05, batch_size=512, epochs=300)

# print(model.evaluate(x_valid, y_valid))

ids, x_test = load_test()
predictions = np.round(model.predict(x_test))

f = open("submission_perceptron.csv", "w")
f.write("PassengerId,Survived\n")
for index, id_number in enumerate(ids):
    f.write(str(int(id_number[0])) + "," + str(int(predictions[index])) + "\n")

f.close()