首页 > 其他分享 >决策树实现

决策树实现

时间:2022-12-04 18:55:11浏览次数:35  
标签:fft 实现 torch feature df test import 决策树

import matplotlib.pyplot as plt import numpy as np import pandas as pd import torch import torch.fft as fft df = pd.read_csv('train.csv') df=df.drop(['ID'],axis=1) nmp=df.to_numpy() feature=nmp[:-20,:-1] label=nmp[:-20,-1]#(210,240) feature=torch.fft.fft(torch.Tensor(feature)) feature=torch.abs(feature)/240*2 feature=feature.detach().numpy() sum=1 li=[] for i in range(feature.shape[0]):     index=feature[i,:]>=0.3     index=index.astype(np.int)     index=np.nonzero(index)
    for j in index:         for j1 in j:             if j1 not in li:                 li.append(j1) print(li) print(len(li))
df = pd.read_csv('train.csv') df=df.drop(['ID'],axis=1) nmp=df.to_numpy() feature=nmp[:-20,:-1] label=nmp[:-20,-1]#(210,240) feature=torch.fft.fft(torch.Tensor(feature)) feature=torch.abs(feature)/240*2 feature=feature[:,li] feature=feature.detach().numpy() test_feature=nmp[-20:,:-1] test_label=nmp[-20:,-1]#(210,240)
test_feature=torch.fft.fft(torch.Tensor(test_feature)) test_feature=torch.abs(test_feature)/240*2 test_feature=test_feature[:,li] from torch import nn import torch label=label.reshape(-1,1) test_label=test_label.reshape(-1,1)
from sklearn import svm import matplotlib.pyplot as plt from sklearn import tree clf=tree.DecisionTreeClassifier(criterion='entropy',random_state=0,max_depth=7) # .SVC()就是 SVM 的方程,参数 kernel 为线性核函数 # 训练分类器 import sklearn from sklearn.metrics import accuracy_score clf.fit(feature, label) w=clf.predict(feature) pr=accuracy_score(label, w) print(pr)
w=clf.predict(test_feature) pr=accuracy_score(test_label, w) print(pr) df = pd.read_csv('test.csv') df=df.drop(['ID'],axis=1) nmp=df.to_numpy() feature=nmp[:,:] feature=torch.fft.fft(torch.Tensor(feature)) feature=torch.abs(feature)/240*2 feature=torch.Tensor(feature[:,li]) feature=feature.detach().numpy() out=clf.predict(feature) out=pd.DataFrame(out) out.columns = ['CLASS'] w=[] for k in range(out.shape[0]):     w.append(k+210) out['ID']=np.reshape(w,(-1,1)) out[['ID','CLASS']].to_csv('out.csv',index=False)

标签:fft,实现,torch,feature,df,test,import,决策树
From: https://www.cnblogs.com/hahaah/p/16950416.html

相关文章

  • 如何用JDK优雅的实现几个算法
    今天给大家介绍下八股文中的两个重要成员,LinkedHashMap和TreeMap。 这两者都实现了Map接口,也经常会在面试中被拿来与HashMap比较。 到底它们能使用哪些魔法呢,接下来......
  • Node.js实现国密算法
    一、node.js环境安装1去官网下载压缩包,并放置到/usr/local/bin文件夹下2进行环境变量配置vim/etc/profile在环境变量文件的末尾添加exportNODEJS=/usr/local/b......
  • 11.C语言实现【N子棋】
    C语言实现一个大家小时候都玩过的小游戏的进阶版本,不止是三子棋,可以根据玩家需要设定棋盘大小。的可读性,我将源码分为了三个部分,分别是源文件test.c、game.c、game.h。tes......
  • 19.C语言实现【通讯录】
    简单功能展示增加联系人功能。按照姓名排序功能。保存文件,重新启动重新加载功能。头文件contact.h//文件保存版#include<stdio.h>#include<string.h>#include<s......
  • C++学习---变长参数(stdarg.h)的实现原理
    引用C++中对stdarg.h头文件进行了封装,该头文件实现了函数变长参数,能够在定义函数时不必完全指定参数个数,而编译器能够在代码编译时,拿到所有的参数,并进行相应的处理。stdarg......
  • 使用socketserver实现文件下载
    服务端server.pyimportosimportjsonimportstructimportsocketserverclassMyServer(socketserver.BaseRequestHandler):#重写handle消息的方法def......
  • 【CV算法理解与源码实现】DeepSORT
    前言 论文:​​SimpleOnlineandRealtimeTrackingwithaDeepAssociationMetric​​ 参考1.​​deepsort_github​​;2.​​deepsort_paper​​;3. ​​ComputerVi......
  • 【CV项目实现】交通标志数据集TT100K简介
    前言论文是​​清华-腾讯联合实验室​​提出的,公开了Tsinghua‐Tencent100K数据集,创建了一个大型交通标志基准。该数据集提供了100000张分辨率为2048像素×2048像素、包含......
  • 【计算机视觉(CV)】基于k-means实现鸢尾花聚类
    【计算机视觉(CV)】基于k-means实现鸢尾花聚类作者简介:在校大学生一枚,华为云享专家,阿里云专家博主,腾云先锋(TDP)成员,云曦智划项目总负责人,全国高等学校计算机教学与产业实践资源......
  • Nacos 中的配置文件如何实现加密传输
    小伙伴们知道,SpringCloudConfig很早就提供了配置文件的加解密功能,并且支持对称加密和非对称加密两种不同的模式。Nacos作为分布式配置中心+服务注册中心的合体,在配置文......