0

So basically, I am working on this bullet optimization program. I wish to study how different ballistics parameters such as weight, length, and mass affect a ballistics coefficient. However, my training accuracy is 0, although there is loss and val_loss. I've read similar Stackoverflow posts regarding this, but none have helped me so far. Perhaps I just didn't do them right; I am referencing https://stackoverflow.com/a/63513872/12349188

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.utils import shuffle

df = pd.read_csv('Bullet Optimization\ShootForum Bullet DB_2.csv')

from sklearn.model_selection import train_test_split
from sklearn import preprocessing
dataset = df.values
X = dataset[:,0:12]
X = np.asarray(X).astype(np.float32)

y = dataset[:,13]
y = np.asarray(y).astype(np.float32)

X_train, X_val_and_test, y_train, y_val_and_test = train_test_split(X, y, test_size=0.3, shuffle=True)
X_val, X_test, y_val, y_test = train_test_split(X_val_and_test, y_val_and_test, test_size=0.5)

from keras.models import Sequential
from keras.layers import Dense, BatchNormalization

model = Sequential(
    [
        #2430 is the shape of X_train
        #BatchNormalization(axis=-1, momentum = 0.1),
        Dense(32, activation='relu'),
        Dense(32, activation='relu'),
        Dense(1,activation='softmax'),
    ]
)

model.compile(optimizer='sgd', loss='binary_crossentropy', metrics=['accuracy'])

history = model.fit(X_train, y_train, batch_size=64, epochs=100, validation_data=(X_val, y_val))

Did I do something wrong in my code? I know some python but I just kind of built upon the tutorials for my own purposes.

Jerome Ariola
  • 135
  • 1
  • 11

1 Answers1

1

There are several problems in your code.

First this line:

Dense(1,activation='softmax')

This line will cause the output 1 every time. So even if you are making classification, your accuracy would be 50% if you had 2 classes. Softmax outputs' sum will be equal to one. So using it with one neuron does not make sense.

You need to change your loss and metric as this is a regression.

loss='mse', metrics=['mse']

Also your output neuron should be linear which means does not need any activation function. It should be like:

Dense(1)
Frightera
  • 4,773
  • 2
  • 13
  • 28
  • I've worked with pre-trained models, and it's high time I learn how to write my own sequential models! Thank you, I'll try it out; there's just so much to know! – Jerome Ariola Feb 28 '21 at 11:04
  • You're welcome, please consider accepting the answer if it solves your problem after. – Frightera Feb 28 '21 at 11:05
  • I know this sounds dumb, but how would I discern classification from regression? I kind of just guessed that this was regression since you're taking a bunch of parameters and fitting them to a single value, but what are some other tasks you would know of other than these two? – Jerome Ariola Feb 28 '21 at 11:19
  • 1
    Classification is the problem of predicting a **discrete class label** output whereas regression is the problem of predicting a **continuous** quantity. [You can find more from here](https://machinelearningmastery.com/classification-versus-regression-in-machine-learning/) – Frightera Feb 28 '21 at 11:22
  • Well said, thank you. And since my current problem is regression, do you think there's a way I can visualize the line fitting as it happens, just as in playground.tensorflow.org ? I would think one uses matplotlib... – Jerome Ariola Feb 28 '21 at 11:46
  • 1
    What do you mean by *as it happens*? If I understood right, you can use Tensorboard. – Frightera Feb 28 '21 at 11:51