Posts

Showing posts with the label machine-learning

Classification table reports result of one class only

Classification table reports result of one class only I've fitted a model on the training data and used it on test data for prediction. It has predicted only one class as: 11 "1" 11.1 "1" 12 "1" 15 "1" 9 "1" 9.1 "1" 14 "1" 20 "1" 20.1 "1" 4 "1" But the classification table displays the result of only one class as: class.pre.Ae.test.cp testy.s.w 1 0 5 1 5 It should be: class.pre.Ae.test.cp testy.s.w 1 0 0 5 0 1 5 0 How can i do it? By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

word2vec gensim update learning rate

word2vec gensim update learning rate I trained a w2v model on a big corpus, and I want to update it with a smaller one with new sentences (and new words). In the first big training, I took the default parameters for alpha (0.025 with lin. decay to 0.0001) Now, I want to use model.train to update it. But from the doc I don't understand which (initial and final) learning rate will be used during this update of training. model.train From one side, if you also use 0.025 with lin. decay until 0.0001, it will be too strong for already existing words which appeared a lot in the first big corpus and that will be heavily changed, but from the other side for new words (added with model.build_vocab(sentences, update = True)) a low learning rate of 0.0001 is too small. So my questions are : model.train How I should choose the learning rate in order to take into account this issue of old/new words ? [aside question] Why when I use 2 times model.train on the same sentences, the second time, it...

Error in running randomForest : object not found

Error in running randomForest : object not found So i am trying to fit a random forest classifier for my dataset. I am very new to R and i imagine this is a simple formatting issue. I read in a text file and transform my dataset so it is of this format: (taking out confidential info) >head(df.train,2) GOLGA8A ITPR3 GPR174 SNORA63 GIMAP8 LEF1 PDE4B LOC100507043 TGFB1I1 SPINT1 Sample1 3.726046 3.4013711 3.794364 4.265287 -1.514573 7.725775 2.162616 -1.514573 -1.5145732 -1.514573 Sample2 4.262779 0.9261892 4.744096 7.276971 -1.514573 4.694769 4.707387 2.031476 -0.8325444 2.615991 ... ... CD8B FECH PYCR1 MGC12916 KCNA3 resp Sample1 -1.514573 2.099336 3.427928 1.542951 -1.514573 1 Sample2 -1.145806 1.204241 2.846832 1.523808 1.616791 1 In essence the columns are my features and the rows my samples, the last column is my response vector which is a column of factors, resp. Then i use: set.seed(1) #Set the seed in order to gain reproduci...

why keras model param values change when it is accessed in a tensorflow session?

why keras model param values change when it is accessed in a tensorflow session? I was having trouble with my transfer learning implementation. I guess I found the root cause but it is not clear to me why it works like that. Here is the explanation... If I create a model (e.g. resnet50 from keras.applications), and then try to use it in a tensorflow session, weights all of a sudden change. Here is a simple example: First import the necessary libraries: import tensorflow as tf from keras.applications.resnet50 import ResNet50 from keras.models import Model Then define the model as following: model = ResNet50(weights='imagenet') Now print out parameters from one of the layers as following: model.get_layer('conv1').get_weights() The output is long but it starts as following: [array([[[[ 2.82526277e-02, -1.18737184e-02, 1.51488732e-03, ..., -1.07003953e-02, -5.27982824e-02, -1.36667420e-03], [ 5.86827798e-03, 5.04415408e-02, 3.46324709e-03, ..., ...

How to build a Language model using LSTM that assigns probability of occurence for a given sentence

How to build a Language model using LSTM that assigns probability of occurence for a given sentence Currently, I am using Trigram to do this. It assigns the probability of occurrence for a given sentence. But Its limited to the only context of 2 words. But LSTM's can do more. So how to build an LSTM Model that assigns the probability of occurrence for a given sentence? This question has not received enough attention. (TensorFlow Implementation)[tensorflow.org/versions/master/tutorials/… Can some body provide keras implementation? – Shashi Tunga yesterday 1 Answer 1 I have just coded a very simple example showing how one might compute the probability of occurrence of a sentence with a LSTM model. The full code can be found here. Suppose we want to pre...

How do i represent the chromosome using Genetic Algorithm?

How do i represent the chromosome using Genetic Algorithm? My task is to calculate clashes between alert time schedule and the user calendar schedule to generate the clashes less alert time schedule. How should i represent the chromosome according to this problem? How should i represent the time slots? (Binary or Number) Thank You (Please Consider i'm a beginner to the genetic algorithm studies) 1 Answer 1 Questions would be: What have you tried so far? How good are your results so far? Also your Problem is stated quite unspecific. Thus here is what I can give: I strongly recommend playing around and reading about those Things. This might look like a lot of extra work to implement, but you should rather come to see them as hyperparameters which Need to be tuned in order to receive the best Outcome. Sir, the thing is i have to generate a alert schedule for water drin...

Deep reinforcement learning - how to deal with boundaries in action space

Deep reinforcement learning - how to deal with boundaries in action space I've built a custom reinforcement learning environment and agent which is similar to a labyrinth game. environment agent In labyrinth there're 5 possible actions: up, down, left, right, and stay. While if blocked, e.g. agent can't go up, then how do people design env and agent to simulate that? env agent To be specific, the agent is at current state s0 , and by definition taking actions of down, left, and right will change the state to some other values with an immediate reward (>0 if at the exit). One possible approach is when taking action up , the state will stay at s0 and the reward will be a large negative number. Ideally the agent will learn that and never go up again at this state. s0 up s0 up However, my agent seems not learning this. Instead, it still goes up . Another approach is to hard code the agent and the environment that the agent will not be able to perform the action up whe...

Sklearn : Get last split from timeSeriesSplit

Sklearn : Get last split from timeSeriesSplit So I am using the timeSeriesSplit from sklearn to split my data like this, tscv = TimeSeriesSplit(n_splits=3) Now I know in order to get the split indices we have to iterate over tscv.split(X) . My question here is, is it possible to get directly to the last split, without iterating over the splits. The object returned by the function is not exactly a list, so I am not sure how to do this ? I need the last split only, since my data is large and no. of splits is also large. tscv.split(X) Thanks in advance 2 Answers 2 You can try this def get_last_cv(splits): splits_deque = deque(splits, maxlen=1) last_element = splits_deque.pop() train,test = last_element return train,test and then get the indices like this train_index,test_index = get_last_cv(tscv.split(X)) where X is your data X Split method in TimeSeriesSplit generates split of indi...

why DNN nonlinear regression model underestimate the actual target?

why DNN nonlinear regression model underestimate the actual target? I recently used tensorflow to create a DNN nonlinear regression model. The training dataset size is only 569 examples, the predicted dataset size is 101. The input features are 209 dimensions. The DNN model has three hidden layer with hidden_units=[250, 200, 100, 50]. But the result shows that most of the predicted targets are smaller than the actual targets, which means the model underestimates the actual target. I don't understand what does this mean. Does anyone know how to explain this? By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Making Quantile Regression Example work for my own dataset in sklearn

Making Quantile Regression Example work for my own dataset in sklearn I am trying to implement quantile regression for my problem using the code at http://scikit-learn.org/stable/auto_examples/ensemble/plot_gradient_boosting_quantile.html I want to use the exact same code for my model. I am mainly interested in the quantile part. My data is simple, I have a bunch of features, a 5 dimensional vector as my input and a real value as y. So, instead of the data (x, sin(x)) in the above code, I am trying to get the model work for my own (X, y). The problem is, they are using xx as separate variables in the code, if I set xx to X, the code just gets messed up with a useless noisy visualisation. I described the specific changes I made, hoping the model to work, I tried a few other things as well to retrofit my data to the model. How should the code be modified to work on my inputs. What specific changes should be made? By cli...

How to make the openpose use caffe without cuda supported

How to make the openpose use caffe without cuda supported I wan to try Openpose: https://github.com/CMU-Perceptual-Computing-Lab/openpose in my laptop with an AMD video card,so no cuda is possible, is that possiable?How? 4 Answers 4 Running caffe with non-NVIDIA card requires opencl branch. Integrating that branch with the caffe branch used by OpenPose might be tricky (and might be straight forward - I haven't tried it myself). If you want to "play it safe", you can disable ALL GPU support by setting OpenPose CPU_ONLY := 1 In your Makefile.config before compiling caffe. This way you'll have a CPU version that does not require any CUDA/NVIDIA support. Makefile.config I would add to Shai's answer that you need to disable # USE_CUDNN := 1 sometime when its left on,the setup function of layers do some CUDA ASSERT checking that fails and prevent the program to continue There is...

Which part of the code is wrong for artificial neural network in R? [on hold]

Which part of the code is wrong for artificial neural network in R? [on hold] I'm trying to predict a sales demand by using artificial neural network and 10 fold cross validation. So, I coded by using nnet package as follows: library(nnet) library(plyr) k = 10 question$id <- sample(1:k, nrow(question), replace = TRUE) list <- 1:k prediction <- data.frame() testsetCopy <- data.frame() progress.bar <- create_progress_bar("text") progress.bar$init(k) for(i in 1:k){ trainingset <- subset(question, id %in% list[-i]) testset <- subset(question, id %in% c(i)) mymodel <- nnet(Sales1~ResidentA+ResidentB+ResidentD+DOW+Weather+Amt_Rainfall+Air_Quality+Avg_Temp+Humidity, data=trainingset, size=7, decay=0.1) temp <- as.data.frame(predict(mymodel, testset[,-5])) prediction <- rbind(prediction, temp) testsetCopy <- rbind(testsetCopy, as.data.frame(testset[,3])) progress.bar$step() } However, the result showed less than 1 that it seems something wrong. So...

How to train Actor-Critic (A2C) reinforcement learning

How to train Actor-Critic (A2C) reinforcement learning I am currently been able to train a system using Q-Learning. I will to move it to Actor_Critic (A2C) method. Please don't ask me why for this move, I have to. I am currently borrowing the implementation from https://github.com/higgsfield/RL-Adventure-2/blob/master/1.actor-critic.ipynb The thing is, I am keep getting a success rate of approx ~ 50% (which is basically random behavior). My game is a long episode (50 steps). Should I print out the reward, the value, or what? How should I debug this? Here are some log: simulation episode 2: Success, turn_count =20 loss = tensor(1763.7875) simulation episode 3: Fail, turn_count= 42 loss = tensor(44.6923) simulation episode 4: Fail, turn_count= 42 loss = tensor(173.5872) simulation episode 5: Fail, turn_count= 42 loss = tensor(4034.0889) simulation episode 6: Fail, turn_count= 42 loss = tensor(132.7567) loss = simulation episode 7: Success, turn_count =22 loss = tensor(2099.5344) ...

PyTorch Autograd automatic differentiation feature

Image
PyTorch Autograd automatic differentiation feature I am just curious to know, how does PyTorch track operations on tensors (after the .requires_grad is set as True and how does it later calculate the gradients automatically. Please help me understand the idea behind autograd . Thanks. .requires_grad True autograd 1 Answer 1 That's a great question! Generally, the idea of automatic differentiation ( AutoDiff ) is based on the multivariable chain rule, i.e. . What this means is that you can express the derivative of x with respect to z via a "proxy" variable y; in fact, that allows you to break up almost any operation in a bunch of simpler (or atomic) operations that can then be "chained" together. Now, what AutoDiff packages like Autograd do, is simply to store the derivative of such an atomic operation block, e.g., a division, multiplication, etc. Then, at runtime, your p...