bred

Generation

generate functionTue, 17 Jan 2023

The function takes in a string, and set a dataset online as a variable. It will then check which information does the string match the most.

import nltk import os from nltk.corpus import stopwords from nltk.tokenize import word_tokenize from nltk.classify.scikitlearn import SklearnClassifier from sklearn.naive_bayes import MultinomialNB,BernoulliNB from sklearn.linear_model import LogisticRegression,SGDClassifier from sklearn.svm import SVC, LinearSVC, NuSVC def classify(text): data = [] if not os.path.isfile('data/data.txt'): with open('data/data.txt', 'wb') as csvfile: writer = csv.writer(csvfile) writer.writerow(('keywords', 'category')) with open('data/data.txt', 'rb') as csvfile: reader = csv.reader(csvfile) for row in reader: data.append(row) train_set = [] for row in data: keywords = row[0

Questions about programming?Chat with your personal AI assistant