Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

model.predict python

# Import the libraries required in this example:
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers

inputs = keras.Input(shape=(784,), name="digits")
x = layers.Dense(64, activation="relu", name="dense_1")(inputs)
x = layers.Dense(64, activation="relu", name="dense_2")(x)
outputs = layers.Dense(10, activation="softmax", name="predictions")(x)

model = keras.Model(inputs=inputs, outputs=outputs)

(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()

# Preprocess the data (NumPy arrays):
x_train = x_train.reshape(60000, 784).astype("float32") / 255
x_test = x_test.reshape(10000, 784).astype("float32") / 255

y_train = y_train.astype("float32")
y_test = y_test.astype("float32")

# Allocate 10,000 samples for validation:
x_val = x_train[-10000:]
y_val = y_train[-10000:]
x_train = x_train[:-10000]
y_train = y_train[:-10000]

model.compile(
    optimizer=keras.optimizers.RMSprop(),  # Optimizer
    # Minimize loss:
    loss=keras.losses.SparseCategoricalCrossentropy(),
    # Monitor metrics:
    metrics=[keras.metrics.SparseCategoricalAccuracy()],
)

print("Fit model on training data")
history = model.fit(
    x_train,
    y_train,
    batch_size=64,
    epochs=2,
    # Validation of loss and metrics
    # at the end of each epoch:
    validation_data=(x_val, y_val),
)

history.history

print("Evaluate model on test data")
results = model.evaluate(x_test, y_test, batch_size=128)
print("test loss, test acc:", results)

# Generate a prediction using model.predict() 
# and calculate it's shape:
print("Generate a prediction")
prediction = model.predict(x_test[:1])
print("prediction shape:", prediction.shape)
Comment

model.predict python

#Building the Decision Tree Model on our dataset
from sklearn.tree import DecisionTreeRegressor
DT_model = DecisionTreeRegressor(max_depth=5).fit(X_train,Y_train)
DT_predict = DT_model.predict(X_test) #Predictions on Testing data
print(DT_predict)
Comment

PREVIOUS NEXT
Code Example
Python :: * pattern by python 
Python :: best python books python 3 
Python :: syntax of calloc 
Python :: block content 
Python :: combine picture and audio python 
Python :: python increase one item in list 
Python :: input lstm 
Python :: pandas replace multiple values in column 
Python :: how to know the version of python 
Python :: python genetic algorithm library 
Python :: how to use for in python 
Python :: Write a Python program to remove a key from a dictionary. 
Python :: django swagger 
Python :: foreach loop in python 
Python :: Find Factors of a Number Using Function 
Python :: programmation orienté objet python 
Python :: how to while true python 
Python :: python print set 
Python :: python tutorial 
Python :: django raw without sql injection 
Python :: change column order pandas 
Python :: django many to many post update method via rest 
Python :: defaultdict item count 
Python :: implement stack using list in python 
Python :: parse email python 
Python :: python re.sub() 
Python :: from a list of lists - find all length of list 
Python :: pandas join dataframe 
Python :: python capture stdout 
Python :: ++ in python 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =