model

Get data from .pickle

Get data from .pickle Question: I have a model of Multinomial NB(): text_clf_NB = Pipeline([(‘vect’, CountVectorizer()), (‘tfidf’, TfidfTransformer()), (‘clf’, MultinomialNB()), ]) text_clf_NB.fit(Train_X_NB, Train_Y_NB) I save it to .pickle pickle.dump(text_clf_NB, open("NB_classification.pickle", "wb")) In another case I load this model: clf = pickle.load(open("NB_classification.pickle", "rb")) Can you help me, please, how can I get sparse matrix of Train …

Total answers: 1

Django how get all invoices containing item

Django how get all invoices containing item Question: I spent over two days looking in docs and internet and cannont find solution. I have models: class Invoice(models.Model): (…) class Product(models.Model): (…) class InvoicedItems(models.Model): invoice = models.ForeignKey(Invoice, on_delete=CASCADE) article = models.ForeignKey(Product, on_delete=CASCADE) How to get list of all invoices containing one product? I want to make …

Total answers: 3

The first field in the models.py not created, how to fix it? (django)

The first field in the models.py not created, how to fix it? (django) Question: I have written two classes in models.py (Django): class Name_tickers(models.Model): ticker = models.CharField(max_length = 32) name = models.CharField(max_length = 100) def __str__(self): return self.ticker class Close_stock(models.Model): date = models.DateField(), tiker_name = models.ForeignKey(Name_tickers, on_delete=models.CASCADE), price = models.DecimalField(max_digits=15, decimal_places=5) But was created: migrations.CreateModel( …

Total answers: 1

Django: Is possible use _set into the filter() method?

Django: Is possible use _set into the filter() method? Question: I’m working on my ListView called IndexView on my polls app. This view currently return the last five published questions (not including those set to be published in the future). But my view also publish Questions that don’t have any Choice, so I also want …

Total answers: 1

encoded_sentence = [label2int[start_index] for generated_text in input_sentence] keyerror:2

encoded_sentence = [label2int[start_index] for generated_text in input_sentence] keyerror:2 Question: This is a SentenceRecoghizedModel,it can’t work,I don’t have much experience on this,can somebody help me? import torch import torch.nn as nn import torch.optim as optim #導入訓練模型 text = "" #將text中的字數轉換成數字 chars = list(set(text)) #建立labels,用以儲存不同的句子 labels = [""] int2label = dict(enumerate(labels)) label2int = {label: index for index, …

Total answers: 1

I am having a value error in my keras model, calling 'model.fit' gives a value error. i keep getting value error error when i try to fit the model

I am having a value error in my keras model, calling 'model.fit' gives a value error. i keep getting value error error when i try to fit the model Question: X=np.array([-7.0,-4.0,-1.0,2.0,5.0,8.0,11.0,14.0]) y=np.array([3.0,6.0,9.0,12.0,15.0,18.0,21.0,24.0]) X=tf.cast(tf.constant(X), dtype=tf.float32) y=tf.cast(tf.constant(y), dtype=tf.float32) tf.random.set_seed(42) model = tf.keras.Sequential([ tf.keras.layers.Dense(1) ]) model.compile(loss=tf.keras.losses.mae, optimizer=tf.keras.optimizers.SGD(), metrics=["mae"]) model.fit(X, y, epochs=5) `————————————————————————— ValueError Traceback (most recent call last) …

Total answers: 1

How to code unique constraint per parent ForeignKey in Django model?

How to code unique constraint per parent ForeignKey in Django model? Question: Here’s my code: from django.db import models class Parent(models.Model): name = models.CharField(max_length=50, unique=True) def __str__(self): return str(self.name) class Child(models.Model): parent = models.ForeignKey(Parent, on_delete=models.CASCADE) name = models.CharField(max_length=50, unique=True) def __str__(self): return str(self.name) Parents in my database: Rogan Smith Doe In admin dashboard: First, I …

Total answers: 1

how to output data from a linked table in django?

how to output data from a linked table in django? Question: I have a built-in User table and a Note table associated with it by key. class Note(models.Model): header = models.CharField(max_length=100) note_text = models.TextField() data = models.DateField() user = models.ForeignKey(User, on_delete=models.CASCADE) That is, a registered user may have several notes. How do I get all …

Total answers: 1

TensorFlow model subclassing API with vars doesn't show parameters or layers

TensorFlow model subclassing API with vars doesn't show parameters or layers Question: I wrote following code for VGG block, and I want to show the summary of the block: import tensorflow as tf from keras.layers import Conv2D, MaxPool2D, Input class VggBlock(tf.keras.Model): def __init__(self, filters, repetitions): super(VggBlock, self).__init__() self.repetitions = repetitions for i in range(repetitions): vars(self)[f’conv2D_{i}’] …

Total answers: 1