当前位置: 首页 > news >正文

wap网站模式wordpress收费查看

wap网站模式,wordpress收费查看,建企业网站的步骤,网络科技官网要求: 针对实验1和实验2构建的数据集信息分析 设计实现通过数据简介进行大类分类的程序 代码实现: 训练集数据获取: read_data.py import json import pickledef read_intro():data []trypathr"E:\Procedure\Python\Experiment\f…

要求:

针对实验1和实验2构建的数据集信息分析

设计实现通过数据简介进行大类分类的程序

代码实现:

训练集数据获取:

read_data.py

import json
import pickledef read_intro():data = []trypath=r"E:\Procedure\Python\Experiment\first.json"filepath=r"E:\Procedure\Python\Experiment\res1.json"with open(filepath, 'r', encoding='utf-8') as file:for line in file:record = json.loads(line)if record.get('intro')!='':data.append(record)return datadef store_model(model):# 加载模型file=r'E:\Procedure\Python\Experiment\Machine_Learning\model1.pkl'try:# 尝试以 'xb' 模式打开文件,如果文件不存在则创建新文件with open(file, 'wb') as file:# 使用 pickle 序列化模型并写入文件pickle.dump(model, file)except FileExistsError:print("File already exists. Cannot overwrite existing file.")except Exception as e:print("An error occurred:", e)# 使用加载的模型进行预测#predictions = loaded_model.predict(X_test)
def store_report(report):file=r"E:\Procedure\Python\Experiment\Machine_Learning\class_report.txt"with open(file,'w')as file:file.write(report)returndef get_model():m_path=r'E:\Procedure\Python\Experiment\Machine_Learning\model1.pkl'try:with open(m_path,'rb')as file:loaded_model=pickle.load(file)return loaded_modelexcept Exception as e:print(e)return None
训练模型:

多项式朴素贝叶斯模型用于单一标签文本分类

# 导入所需的库
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.naive_bayes import MultinomialNB
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score, classification_report
import read_data
import random
data=read_data.read_intro()
random.shuffle(data)
X = [item['intro'] for item in data]
y = [item['mainclass'] for item in data]
# 文本向量化
vectorizer = TfidfVectorizer()
X_vectorized = vectorizer.fit_transform(X)# 将数据集划分为训练集和测试集
X_train, X_test, y_train, y_test = train_test_split(X_vectorized, y, test_size=0.2, random_state=42)# 初始化朴素贝叶斯分类器
model = read_data.get_model()
#model = MultinomialNB()
# 训练模型model.fit(X_train, y_train)# 在测试集上进行预测
y_pred = model.predict(X_test)read_data.store_model(model)
# 评估模型性能
accuracy = accuracy_score(y_test, y_pred)
print("Accuracy:", accuracy)# 打印分类报告
print("\nClassification Report:")
report=classification_report(y_test, y_pred,zero_division=0)
print(report)
read_data.store_report(report)

结果:

http://www.yayakq.cn/news/722537/

相关文章:

  • 招商网站建设的必要性北京顺义去哪找做网站的
  • 国外做彩票网站推广是合法的吗深圳网络公司推广平台
  • 闵行建设机械网站做网站需要去哪里备案
  • 校园网站建设依据营销型网站设计招聘
  • 建设工程公司 网站梧州网站建设公司
  • 有没有高质量的网站都懂的外贸网站运营推广
  • 开网站成本济阳做网站多少钱
  • 自己做个网站需要什么风云榜
  • 网站建设流程包括哪些环节企业网站网页设计费用
  • 合肥seo网站管理网页工具大全
  • 网站开发前端招聘网站开发年度总结工作
  • 今傲网站做的怎么样郴州网络工程职业学校
  • 黑龙江住房和城乡建设厅网站施工企业安全总监职责履行情况
  • 兰州网站建设和推广青岛网页设计制作
  • 做外贸网站哪家好班级优化大师手机版下载
  • 提供商城网站建设工程公司资质怎么申请
  • 电子商务网站建设 asp网站建设管理考核办法
  • 郑州制作企业网站企业网站的建立目的和特点是什么
  • 一个备案号可以用几个网站wordpress分页重写
  • 获取网页 代码 做网站濮阳开公司怎么找客户
  • logo设计理念怎么写优化最狠的手机优化软件
  • 泉州 网站建设公司首选南极电商是做什么的
  • 扫码支付个人商城网站开发免费wordpress文章点赞功能
  • 网站建设模板图片百合视频做爰视频网站
  • 安徽省建设项目 备案网站wordpress文本块
  • 华为网站建站广东省白云区属于哪个市
  • 天门市网站建设打扑克软件直播app开发
  • 余姚做网站易迈互联网站建设怎么样
  • 网站右侧二维码西安房价
  • 烟台北京网站建设公司小辉seo