简体   繁体   English

我可以将 Tensorboard 用于我的线性回归或线性分类问题吗?

[英]Can i use Tensorboard for my linear regression or linear classification problem?

I am investigating whether I can use tensorboard in my project.我正在研究是否可以在我的项目中使用 tensorboard。 In my project I use data (csv file) and I don't know if I can use tensorboard for loss, predicts or if it can only be used for image recognition.在我的项目中,我使用数据(csv 文件),但我不知道是否可以使用 tensorboard 进行损失、预测或是否只能用于图像识别。 I do not really manage it myself.我自己并没有真正管理它。 does anyone have an idea if this is possible and how you could do this?有没有人知道这是否可行以及如何做到这一点? i use tensorflow.我使用 tensorflow。

Thanks.谢谢。

Yes.是的。 You can use Tensorboard for Regression also.您也可以使用 Tensorboard 进行回归。 You can monitor 'scalars , distributions , graphs , histogram` etc to monitor how parameters are getting updated over epochs or time.您可以监控“标量,分布,图表,直方图”等,以监控参数如何随着时间或时间而更新。

I have used simple example and shown how to usage in colab.我使用了简单的示例并展示了如何在 colab 中使用。

import tensorflow as tf
import numpy as np
from tensorflow import keras
import os
import datetime
model = tf.keras.Sequential([keras.layers.Dense(units=1, input_shape=[1])])
model.compile(optimizer='sgd', loss='mean_squared_error')
xs = np.array([-1.0,  0.0, 1.0, 2.0, 3.0, 4.0], dtype=float)
ys = np.array([-3.0, -1.0, 1.0, 3.0, 5.0, 7.0], dtype=float) # 2*x-1
logdir = os.path.join("logs", datetime.datetime.now().strftime("%Y%m%d-%H%M%S"))
tensorboard_callback = tf.keras.callbacks.TensorBoard(logdir, histogram_freq=1)
model.fit(xs, ys, epochs=500, verbose=0,callbacks=[tensorboard_callback])
print(model.predict([6.0])) # actual value is 11.0 and predicts 10.99

%load_ext tensorboard
%tensorboard --logdir logs

Full code is here for reference.完整代码在这里供参考。

Thanks for your answer.感谢您的回答。 it works well!它运作良好!

But now I have an another problem.但现在我有另一个问题。 I want to use a csv file like this: import tensorflow as tf import numpy as np from tensorflow import keras import pandas as pd import sklearn from sklearn import linear_model I want to use a csv file like this: import tensorflow as tf import numpy as np from tensorflow import keras import pandas as pd import sklearn from sklearn import linear_model

import os
from datetime import datetime

data = pd.read_csv("student-mat.csv", sep=";")
data = data[["G1", "G2", "G3", "studytime", "failures", "absences"]]
predict = "G3"

model = tf.keras.Sequential([
keras.layers.Dense(units=5, input_shape=[5])])
model.compile(optimizer='sgd',
          loss='mean_squared_error',
          metrics=['accuracy'])

xs = np.array(data.drop([predict], 1))
ys = np.array(data[predict])

x_train, x_test, y_train, y_test =         sklearn.model_selection.train_test_split(xs, ys, test_size=0.1)

log_dir= ".\\tensorflow_logs\\test\\"+datetime.now().strftime("%Y%m%d-    %H%M%S")
tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir=log_dir,     histogram_freq=1)

model.fit(x_train,
      y_train,
      epochs=500,
      verbose=0,
      validation_data=(x_test, y_test),
      callbacks=[tensorboard_callback])

I get the error messages:我收到错误消息:

ValueError: A target array with shape (355, 1) was passed for an output of shape (None, 355) while using as loss mean_squared_error . ValueError: 形状为 (355, 1) 的目标数组被传递给形状 (None, 355) 的 output,同时用作 loss mean_squared_error This loss expects targets to have the same shape as the output.这种损失预计目标具有与 output 相同的形状。

do you now a solution for this problem.你现在有解决这个问题的办法吗。 i think it has to do with the input_shape but idk?我认为这与 input_shape 但 idk 有关?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM