Beispiel #1
0
from src.main.model.regression.linearRegression import LinearRegression
from src.main.model.model import Config, Parameters
import tensorflow as tf
from src.main.dataset.inputdata import regression_data
from src.main.model.functions.regularization import Ridge

# model configurations
config = Config(feature_num=2, batch_size=500, learning_rate=0.01, epoche=500)

# dataset
dataset = regression_data(TRUE_W=[[17.0], [4]],
                          TRUE_b=4,
                          NUM_EXAMPLES=10000,
                          batch_size=1000)

# implemented model
sess = tf.Session()
lr = LinearRegression(dataset=dataset, config=config, parameters=Parameters())
sess.run(tf.global_variables_initializer())
lr.training(session=sess)
print(sess.run(lr.weights))
Beispiel #2
0
                          model.final_state,
                          model.optimization], feed_dict={feature: X, target: Y, init_state: training_state})
            training_loss += training_loss_
            if step % 100 == 0 and step > 0:
                if verbose:
                    print("Average loss at step", step, "for last 250 steps:",
                          training_loss / 100)
                training_losses.append(training_loss / 100)
                training_loss = 0

    return training_losses


if __name__ == '__main__':
    configuration = Config(feature_num=1,
                           batch_size=batch_size,
                           epoche=20,
                           learning_rate=learning_rate,
                           min_learning_rate=learning_rate,
                           num_layers=1,
                           num_unrollings=1,
                           num_classes=num_classes,
                           num_nodes=1,
                           dropout=0.1,
                           state_size=state_size,
                           num_steps=num_steps)
    training_losses = main(config=configuration,
                           num_epochs=1,
                           num_steps=num_steps)
    plt.plot(training_losses)
    plt.show()
from src.main.model.classification.logisticRegression import LogisticRegression
from src.main.model.model import Config, Parameters
import tensorflow as tf
from src.main.dataset.inputdata import classification_data

# model configurations
config = Config(feature_num=10, batch_size=50, learning_rate=0.01)

# dataset
NUM_EXAMPLES=10000
dataset = classification_data(batch_size=1000, n_samples=NUM_EXAMPLES, n_features=10)

# model
sess = tf.Session()
model = LogisticRegression(dataset=dataset, config=config, parameters=Parameters())
sess.run(tf.global_variables_initializer())
model.training(session=sess)
print(sess.run([model.weights, model.bias]))
print(sess.run(model.accuracy))