<jupyter_start><jupyter_text>Meu primeiro notebookEste é o meu primeiro notebook com **Keras**.<jupyter_code>from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import OneHotEncoder, StandardScaler
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
import numpy as np

iris = load_iris()
print(type(iris))
print(iris)
attribs = iris['data']
classes = iris['target']
names = iris['target_names']
feature_names = iris['feature_names']
print(type(attribs), attribs)
print(type(classes), classes)
print(type(names), names)
print(type(feature_names), feature_names)
encoder = OneHotEncoder()
iris_encoded = encoder.fit_transform(classes[:, np.newaxis]).toarray()

print(iris_encoded)
X_train, X_test, y_train, y_test = train_test_split(
        attribs, iris_encoded, test_size=0.5, random_state=2)
print(X_train[:10])
print(y_train[:10])
model = Sequential()
model.add(Dense(8, input_dim=4, activation='relu'))
model.add(Dense(3, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
model.fit(X_train, y_train, epochs=150, batch_size=10)
perda,acuracia = model.evaluate(X_test, y_test)
print('Acurácia: %.2f' % (acuracia*100))
model.save("./iris.h5")
# Setosa (1,0,0), Versicolor (0,1,0) e Virgínica (0,0,1)
new_iris_samples = np.array(
    [[5.1, 3.3, 1.7, 0.5],
     [5.9, 3.0, 4.2, 1.5],
     [6.9, 3.1, 5.4, 2.1]], dtype=np.float32)

predictions = model.predict(new_iris_samples)
rounded = [[np.round(float(i), 0) for i in amostra] for amostra in predictions]
print(rounded)<jupyter_output>[[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]
{'fraction_non_alphanumeric': 0.1592356687898089, 'fraction_numerical': 0.042848870874348584, 'mean_word_length': 6.612334801762114, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '428305', 'license': 'Apache-2.0', 'n_tokens_mistral': 708, 'n_tokens_neox': 675, 'n_words': 140, 'path': 'keras/primeiro.ipynb', 'repo_name': 'cleuton/datascience', 'size': '1727'}