How to model predict on Tensorflow model that has feature columns?

So far all the coding examples using feature columns do not have examples of how to format their model.predict(...). I tried using raw string and also putting them into np.arrays. I am very new so please be gentle :). Here is the official page, as you can see, no predict example: https://www.tensorflow.org/tutorials/structured_data/feature_columns
Category: Data Science

What is the better way to predict classes for the models developed using the functional API in Keras

We can predict the class for new data instances using the Sequential classification model in Keras using the predict_classes() function. What is the way to predict the class for models that developed using the functional API? For example, I have a model (functional API based) with sigmoid activation on the last layer to get probabilities in a multi-label classification. When I apply model.predict(), I got a series of probabilities even though the loss is binary_crossentropy. I understand that I can …
Category: Data Science

How can I choose num of epochs and batch size?

I have the coco 2014 dataset and need to train it as training is around 82700 and testing is 40500. However, I got the same sentence with different values every time with model.pedict() as I used one epoch only. Now, how can I decide the right number of epochs? I am trying 20 epochs now, but without batch size. Is that right?
Category: Data Science

Calculate confidence score of a neural network prediction

I am using a deep neural network model to make predictions. My problem is a classification(binary) problem. I wish to calculate the confidence score of each prediction. As of now, I use predict_proba of sklearn to get probability of a class and consider it as the model confidence for that prediction. Is it the right approach? What could be a better way to calculate the confidence score? Kindly add relevant literature to support your approach.
Category: Data Science

Get the prediction probability using prediction function

I'm new to SVM models. I took custom SVM classifier from the github. In there standard predict function was overwritten by custom predict function. def predict(self, instances): predictions = [] for instance in instances: predictions.append((int)(np.sign(self.weight_vector.dot(instance.T)[0] + self.bias)))#class is determined based on the sign -1,1 I want to get prediction probability of each class. [-1 probability, 1 probability] I know from standard SVM predict_proba function I can get the probability. Since this is a customized SVM how do I get that? …
Topic: predict svm
Category: Data Science

Algorithm to predict the best time to recall a client

Let's immagine I have a dataset of calls from a call center to clients. Each call has a lot of information like at what time it was made, duration, if it was answered or not, if the client purchased something (the call center is selling stuff), and of course the client that has been called (I have an average of ten calls per client). The calls are just made by the call center, it's never the client calling. What would …
Category: Data Science

The sum of multi-class prediction is not 1 using tensorflow and keras?

I am studying how to do text classification with multiple labels using tensorflow. Let's say my model is like: model = tf.keras.Sequential([ tf.keras.layers.Embedding(vocab_size, 50, weights=[embedding_matrix], trainable=False), tf.keras.layers.LSTM(128), tf.keras.layers.Dense(4, activation='sigmoid')]) model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=tf.metrics.categorical_accuracy) I have 4 classes, the prediction function has the following results: pred=model.predict(X_test) pred array([[0.915674 , 0.4272042 , 0.69613266, 0.3520468 ], [0.915674 , 0.42720422, 0.69613266, 0.35204676], [0.915674 , 0.4272042 , 0.69613266, 0.3520468 ], [0.9156739 , 0.42720422, 0.69613266, 0.3520468 ], ...... You can see that every data has 4 prediction …
Category: Data Science

How do I predict a set of frequently bought items?

I have a dataset of retail transactions wherein different users buy certain items together. For example, a user A buys a toothpaste, a toothbrush and a floss at the same time, and a user B buys a toothpaste, a shampoo and a soap together. I'm required to find out for each item in the dataset a list of items that are frequently bought together with it. For instance, one may expect that whenever a toothbrush is purchased, a toothpaste can …
Category: Data Science

Python sklearn model.predict() gives me different results depending on the amount of data

I train my XGBoostClassifier(). If my testing set has: 0: 100 1: 884 It attempts to predict 210 1's. Around 147 are wrong (False positives) and 63 1's correctly predicted (True positives). Then I increase my testing sample: 0: 15,000 1: 884 It attempts to predict 56 1's. Around 40 are wrong (False positives) and 16 1's correctly predicted (True positives). Am I missing something? some theory? some indication on how to use model.predict(X_test)? Does it say somewhere - if …
Category: Data Science

How to predict multiple images from folder in python

Here is the code for the Prediction of multiple images from the folder. But getting the same label(class) for all the images.I'm not able to find out why every image shows the same label. # import the necessary packages from tensorflow.keras.models import load_model import argparse import pickle import cv2 from tensorflow.keras.preprocessing.image import img_to_array from tensorflow.keras.applications.imagenet_utils import decode_predictions import numpy as np import logging, os import sys from keras.preprocessing import image import tensorflow as tf import math import operator from pathlib …
Category: Data Science

(Not a programming question) Is there a common word to indicate predict or forecast

The general understanding is: Predict: past value - could be data the model has seen (data from train set) or past data model has not seen (data from test set) (together in-sample data) Forecast: future value - data which neither model or user has seen (out-of-sample data) Related question: https://stats.stackexchange.com/questions/65287/difference-between-forecast-and-prediction Question: Is there a common word that can mean either? This will help in talking or writing or explaining to non-technical people.
Category: Data Science

Unable to make accurate predictions?

I have a dataset of diabetes patients and I am trying to predict the next blood glucose level. I have attached an image below and I have about 1600 records in that csv file containing data of 10 patients. Each patient is uniquely identified by the Id column and the Glucose_t-1 means the glucose value in which the patient had before the current reading(Glucose_t) likewise this apply to Glucose_t-2 and Glucose_t-3. And same applies to the Insulin_t-1,Insulin_t-2. The event column …
Category: Data Science

How can I get the predict future following value using Tensorflow LSTM?

Thank you for reading. I'm not good at English. I am wondering how to predict and get future time series data after model training. I would like to get the values after N steps. So, I used the time series in the Tensorflow tutorial to practice predicting the model. a = y_val[-look_back:] for i in range(N-step prediction): #predict a new value n times. tmp = model.predict(a.reshape(-1, look_back, num_feature)) #predicted value a = a[1:] #remove first a = np.append(a, tmp) #insert …
Category: Data Science

Issue with predict generator keras

I'm new with keras with tensorflow backend and I'm trying to do transfer learning with pretrained net. The problem is that the accuracy on validation set is very high, around the 90% , but on test set the accuracy is very bad, less that 1%. I solved the problem using opencv to read and resize image, but I'd like to understand why with keras methods I've this problem. I paste my code below. from keras.preprocessing.image import ImageDataGenerator from keras.applications.xception import …
Category: Data Science

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.