python - Tensorflow 2 坐标分类器

标签 python tensorflow machine-learning keras classification

我是一名尝试机器学习的新手。我看到了这个仓库https://github.com/jbp261/Optimal-Classification-Model-of-BLE-RSSI-Dataset并想重复类似的实验。

所以我有 2 个接收器,想要对给定的 Rssi 值最接近哪一个进行分类。我捕获了一些训练数据并定义了区域 0(靠近信标 1)和区域 1(靠近信标 2)。

我用 keras 构建了一个模型(也尝试过使用 RandomForest,效果很好),但即使以 0.8 的精度评估基础训练数据,我也会得到 50% 的错误预测。

batch_size = 100

#reading the input samples and separating the input from the outputs
dataframe = pd.read_csv("C:\aaa\Log.csv")
labels = dataframe.pop('result')

#creating the dataset from the data
ds = tf.data.Dataset.from_tensor_slices((dict(dataframe), labels))
ds = ds.batch(batch_size)

feature_columns = []
headers = dataframe.columns.tolist()

# numeric cols
for header in headers:
  temp = feature_column.numeric_column(header)
  #feature_columns.append(feature_column.bucketized_column(temp, boundaries=[-70, -60, -50, -40 , -30])) tried also this
  feature_columns.append(temp)

feature_layer = tf.keras.layers.DenseFeatures(feature_columns)

model = tf.keras.Sequential([
  feature_layer,
  layers.Dense(128, activation='relu'),
  layers.Dense(128, activation='relu'),
  layers.Dense(2, activation='sigmoid')
])

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

model.fit(ds, epochs=20)


test_ds = tf.data.Dataset.from_tensor_slices((dict(dataframe), labels))
test_ds = test_ds.batch(batch_size)

loss, accuracy = model.evaluate(test_ds)
print("Accuracy", accuracy)

最佳答案

model.fit()添加一些验证(简单的方法是 validation_split=0.5 或您想要分割的任何百分比。)这会获取您的一些数据,将其与训练数据分开,并且仅在纪元结束后使用它来查看网络对数据的执行情况以前从未见过。这样您将看到损失、准确性、validation_loss和validation_accuracy。后两者更好地反射(reflect)了模型在实际使用中的表现。

一旦开始使用该指标,您就可以查看是否过度拟合,或者对网络所做的更改是否确实有帮助。

关于python - Tensorflow 2 坐标分类器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56169852/

相关文章:

python - Windows 上的 Docker-Cloud CLI 错误

python - Tensorflow 到 Keras : import graph def error on Keras model

python-3.x - Keras 二元分类将输出压缩为 0/1

python - 使用 nlp 从句子中挑选主语 + 形容词对

python - “沙箱”用户定义的Python函数

python - 属性错误: 'bool' object has no attribute '_fields' - Odoo v8

python - 监控 API 的变化 - Pythonic 方式?

python - Tensorflow 磁贴抛出 TypeError : List of Tensors when single Tensor expected

python - 为图像塑造 Tensorflow/TFLearn 输入/输出的问题

machine-learning - 将 optim.step() 与 Pytorch 的 DataLoader 一起使用