How to plot loss curve in Tensorflow without using Tensorboard? - python-3.x

Hey I am new to Tensorflow. I used DNN to train the model and I would like to plot the loss curve. However, I do not want to use Tensorboard since I am really not familiar with that. I wonder whether it is possible to extract the loss info info in each step and plot it use other plotting package or scikit-learn?
Really appreciated!

Change your sess.run(training_function, feed_dict) statement so it includes your loss function as well. Then use something like Matplotlib to plot the data.
_, loss = sess.run((training_function, loss_function), feed_dict)
loss_list.append(loss)
import matplotlib.pyplot as plt
plt.plot(loss_list)

Related

Python XGBoost prediction discrepancies with DMatrix

I found there are 2 problems with xbgoost predictions. I trained the model with XGBClassifier and tried to load the model using Booster for prediction, I found
Predictions are slightly different using xbg.Booster and xgb.Classifier, see below.
Predictions are different between list and numpy array when using DMatrix, see below,
Some difference is quite big, I am not sure why this is happening and which prediction should be the source of truth?
For the second question, your data types could change when you convert a list to a numpy array (depending on the numpy version you're using). For example on numpy 1.19.5, try converting list ["1",1] to a numpy array and see the result.

How do I visualize CNN on pytorch

I've just learned a little about pytorch. I built a CNN to calculate the effects of various optimization algorithms with the official documents of pytorch (I've just finished from SGD to adagrad). However, most of the official documents and tutorial videos ended when the accuracy and time-consuming were calculated, and the code of model visualization ,I had no idea at all. I would like to ask what is used for visualization similar to the following two figures. Is it Matplotlib pyplot or the visualization tool corresponding to pytorch?enter image description here
I can not tell you what library is used to generate the plot you linked to.
There are plenty of options, all of which you can use once you have the data.
One of these options is matplotlib. Others include using Matlab or pgfplots if you want to include your plots in a LaTeX document. These are the tools I use somewhat frequently. They are purely subjective choices.
However, pytorch also supports tensorboard, which is especially useful for live tracking of the training progress.
Have a look at this tutorial: https://pytorch.org/tutorials/recipes/recipes/tensorboard_with_pytorch.html
it looks like matplotlib pyplot to me. While training, you can store all the loss values and accuracy values and plot them after the network is trained.

Pytorch Reproducible - torch_scatter: can not be reproducible?

I am a training a GNN model using Pytorch. I set the seed to a constant, but still can not get the same training results. I used torch_scatter. Is the scatter function can not be reproducible? If it can not be reproducible, what can I do? Please help me. Thanks very much.
from torch_scatter import scatter
out = scatter(agg_embed, index, dim=0, out=None, dim_size=t_embed.size, reduce='mean')

Skorch: How to plot training and validation Accuracy

Is there a way how to plot a training and validation accuracy after we finished training with Skorch net.fit(X_train, y_train). We can see the train_loss, valid_loss, and valid_acc but how about train_acc?
Thank you.
This was also answered in the skorch issue tracker but in short
you can simply add further scorer for the train accuracy:
net = NeuralNetClassifier(
# ...
callbacks=[
EpochScoring(scoring='accuracy', name='train_acc', on_train=True),
],
)
If you are working in a jupyter notebook you can simply run
import matplotlib.pyplot as plt
plt.plot(net.history[:, 'train_acc'])

Exponential Curve Fitting Python

Dataset with X and Y values and I don't know the function that describes the relationship. I want to determine the function that provides good fit in python. Shared the scatterplot with original data.
I have tried polynomial regression but reading about it shows that the data might over-fit.
enter image description here
This looks like a logarithmic function to me. Can someone help me on how to find the best fit for such a graph.
from sklearn.preprocessing import PolynomialFeatures
poly=PolynomialFeatures(degree=4)
poly_data=poly.fit_transform(file[["x"]])
model=LinearRegression()
model.fit(poly_data, file["y"])
plt.scatter(file["x"], file["y"])
plt.plot(file["x"], model.predict(poly.fit_transform(file[["x"]])))
plt.show()
enter image description here
Please let me know if you want to see the dataset.

Resources