自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(214)
  • 资源 (1)

原创 Python:将实验结果保存到excel文件中

'''author: Deniu Hedate: 2020-08-28'''import xlwtimport numpy as npimport pandas as pdfrom pathlib import Pathfrom collections import OrderedDictfrom sklearn.model_selection import StratifiedKFoldfrom PWOAL.HCAL_median import HSALMedfrom PWOAL..

2020-10-29 20:11:33 9

原创 Python:Debug for xlwt issue : TypeError: invalid file: WindowsPath(‘D:/Result_HS2/car-result.xls)

import xlwtimport numpy as npfrom pathlib import Path, WindowsPathsheet_names = ["ACC_mean", "ACC_std", "F1_mean", "F1_std", "MAE_mean", "MAE_std", "QYR_mean", "QYR_std", "ALC_Acc_mean", "ALC_Acc_std", "ALC_F1_mean", "ALC_F1_std", "ALC_.

2020-10-29 20:00:58 8

原创 Sigmoid函数求导

sigmoid 函数sigmoid函数求导过程

2020-10-09 19:09:32 20

原创 Python:拉普拉斯正则逻辑回归

'''auther:Deniu Hedate:2020-09-30'''from copy import deepcopyimport numpy as npimport matplotlib.pyplot as pltfrom sklearn import datasetsfrom sklearn.model_selection import train_test_splitfrom sklearn.metrics import accuracy_scorefrom sklearn..

2020-10-04 13:15:09 39 1

原创 Python:绘制动图

import matplotlib.pyplot as pltimport numpy as npx = np.linspace(-1,1,10000)fig = plt.figure()ax = fig.add_subplot(111)ax.set_aspect('equal')P = 5for p in np.arange(0.3,P,0.2): y = np.power(1-np.power(np.abs(x),p),1/p) # 注意plot 是连点绘图方法,所以注.

2020-09-29 09:19:20 34

原创 Python:拉普拉斯正则逻辑回归 Laplacian Regularization Logistic Regression

from copy import deepcopyimport numpy as npimport matplotlib.pyplot as pltfrom sklearn import datasetsfrom sklearn.model_selection import train_test_splitfrom sklearn.metrics import accuracy_scorefrom sklearn.linear_model import LogisticRegressionf.

2020-09-26 21:22:09 41

原创 Python:逻辑回归cvxpy实现

from copy import deepcopyimport numpy as npimport matplotlib.pyplot as pltfrom sklearn import datasetsfrom sklearn.model_selection import train_test_splitimport cvxpy as cvxX ,y = datasets.make_blobs(n_samples=300, n_features=2,centers=2,cluster_st.

2020-09-25 21:09:14 49

原创 Python:数据集左侧加上一列1

import numpy as npimport matplotlib.pyplot as pltfrom sklearn import datasetsimport cvxpy as cvxX ,y = datasets.make_blobs(n_samples=300, n_features=2,centers=2,cluster_std=[2.0,2.0],random_state=123)N = X.shape[0]d = X.shape[1]y = np.vstack(y)p..

2020-09-25 17:16:23 35

原创 Python复现:HS2:Active learning over hypergraphs with pointwise and pairwise queries

目标文献:I (Eli) Chien,Huozhi Zhou andPan Li .HS2:Active learning over hypergraphs with pointwise and pairwise queries. In: Proceedings of the 22nd International Conference on Artificial Intelligence and Statistics (AISTATS) 2019, Naha,Okinawa, Japan. 【...

2020-09-24 20:32:49 46

原创 Python:异常控制 try except

寻找两个顶点之间的的最短路径。如果存在最短路径则返回该路径如果不存在最短路径则反馈None但是调用nx.shortest_path_length(G,source=1,target=11)后,如果不存在最短路径,则该行代码会报错。因此,使用try & except 控制异常。然后问题就解决了。import networkx as nximport numpy as npimport matplotlib.pyplot as plt# nc = 20# nr ..

2020-09-23 09:08:34 28

原创 Python:排列组合三个函数permutations,combinations,product

from itertools import permutations,combinations,producta = [1,2,3,4]b = [5,6,7,8]A = permutations(a,3)print(list(A))B = combinations(a,3)print(list(B))C = product(a,b)print(list(C))permutations(a,3)是排列combinations(a,3)是组合product(a,b)是两.

2020-09-22 17:56:05 33

原创 Python:参考Swendsen-Wang Sampling构建超图

这里的python部分:利用knn获取k=5时,所有的边和边edges的权重costsimport numpy as npfrom itertools import permutations,combinationsfrom sklearn.datasets import load_irisfrom scipy.spatial.distance import pdist,squareformimport matlabimport matlab.engineX,y = load_iri.

2020-09-22 11:07:26 32

原创 Python:Wilcoxon signed-rank test

import scipy.stats as st# A = [0.4268,# 0.2847,# 0.1593,# 0.4842,# 0.3472,# 0.1608,# 0.3755,# 0.5823,# 0.6279,# 0.7582,# 0.3577,# 0.3146,# 0.6209,# 0.7693,# 0.7961,# 0.8744,# 0.5683,# 0.5293# ]## B = [0.4189,# 0.2876,# 0.1849,# 0.4.

2020-09-07 20:25:30 52

原创 Python:S2实现

title={S2: An efficient graph based active learning algorithm with application to nonparametric classification},author={Dasarathy, Gautam and Nowak, Robert and Zhu, Xiaojin}import networkx as nximport matplotlib.pyplot as pltfrom venv.S2 import s2.

2020-09-04 22:29:49 65

原创 Python:将iris数据通过近邻转化为图并展示出来

import numpy as npfrom sklearn import datasetsimport networkx as nxfrom scipy.spatial.distance import pdist, squareformimport matplotlib.pyplot as pltX, y = datasets.load_iris(return_X_y=True)N = X.shape[0]distlist = pdist(X,metric='euclidean')d.

2020-09-04 19:53:13 142

原创 Python:chain construction

'''auther: Deniu Hedate: 2020-08-20at CQUPTminimum margin principleBased on Chain Construct'''import numpy as npimport pandas as pdfrom copy import deepcopyfrom collections import OrderedDictfrom sklearn.linear_model import LogisticRegression.

2020-08-24 16:27:17 86

原创 Python:Chain Construction

import numpy as npfrom collections import OrderedDictfrom copy import deepcopyclass Chain(object): def __init__(self,idx): self.idx = idx self.lead = None self.follow = None self.same = Nonea = [4,5,3,2,1,7,9].

2020-08-23 17:27:43 53

原创 Python:BDOC算法

Binary Decomposition ordinal classificationimport numpy as npimport pandas as pdfrom copy import deepcopyfrom collections import OrderedDictfrom sklearn.linear_model import LogisticRegressionfrom sklearn.metrics import accuracy_score, f1_scorefro.

2020-08-20 21:09:11 65

原创 Python:层次交叉验证StratifiedKFold

from sklearn import datasetsfrom sklearn.model_selection import StratifiedKFoldX , y = datasets.load_iris(return_X_y=True)SKF = StratifiedKFold(n_splits=10, shuffle=True)for train_idx, test_idx in SKF.split(X, y): print(type(train_idx)) prin..

2020-08-16 21:18:12 218

原创 Python: Pair-wise kNN algorithm a rubbish algorithm

如此垃圾的算法!计算复杂度上天!import numpy as npimport pandas as pdfrom copy import deepcopyfrom sklearn import datasetsfrom scipy.spatial.distance import pdist, squareformfrom sklearn.model_selection import train_test_splitfrom collections import OrderedDict.

2020-08-14 22:21:08 54

原创 Python:sklearn单独测试一个数据 的报错处理:ValueError: Expected 2D array, got 1D array instead:

import numpy as npimport pandas as pdfrom copy import deepcopyfrom sklearn import datasetsfrom scipy.spatial.distance import pdist, squareformfrom sklearn.model_selection import train_test_splitfrom collections import OrderedDictfrom itertools impo.

2020-08-14 20:46:13 157

原创 Python:将训练数据集和测试数据集拼接成一个数据集保存为CSV文件

import numpy as npimport pandas as pdpath_test = r"D:\ExperimentalData\datasets-orreview\ordinal-regression\winequality-red\matlab\test_winequality-red.0"path_train = r"D:\ExperimentalData\datasets-orreview\ordinal-regression\winequality-red\matlab\tr.

2020-08-13 10:23:16 237

原创 kronecker delta

参考https://blog.csdn.net/xyqzki/article/details/11747581?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522159723907619195188355475%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=159723907619195188355475&biz_id=0&a

2020-08-13 09:54:01 85

原创 Python:ndarray中删除某个元素

import numpy as npa = np.array([5,4,3,2,1])b = list(a)a = np.delete(a,b.index(2))print(a)

2020-08-06 20:52:22 717

原创 Python:向ndarray中插入一个元素

import numpy as npa = np.array([1,2,3,4,5,6])print(a)a = np.append(a,7)print(a)忘了就再记一遍!!!能有什么方法,python不像C/C++

2020-08-03 21:09:58 470

原创 Python:返回字典中value最大的key【以及字典的相关操作】

from collections import OrderedDictprices = OrderedDict()prices[1] = 123prices[2] = 234prices[3] = 456max_key = max(prices, key=prices.get)print(max_key)参考:https://blog.csdn.net/qq_44589327/article/details/105669362

2020-08-03 11:21:57 98

原创 Python:判断一个字典是否为空

import numpy as npfrom collections import OrderedDicta = np.array([1,2,3,4,5])b = np.random.choice(a,size=4,replace=False)print(b)print(a[[1,2,3]])c = OrderedDict()if c: print("不空")else: print("空的")

2020-08-02 10:18:42 327

原创 Python: 在数据集中每个类别中随机抽取两个样本

'''auther: DeniuHedate:2020-08-01'''import numpy as npfrom sklearn import datasetsfrom scipy.spatial.distance import pdist,squareformfrom sklearn.model_selection import train_test_splitfrom collections import OrderedDictfrom itertools import comb.

2020-08-01 20:24:59 200

原创 Python:基于二分类分解的序分类方法

参考文献:[1]Frank E, Hall M. A simple approach to ordinal classification[C]//European Conference on Machine Learning. Springer, Berlin, Heidelberg, 2001: 145-156.没有进行类封装,仅是做了函数复现~分类效果比单独使用多分类‘OVR’效果要好1-2%个精度import numpy as npfrom copy import deepcopy.

2020-07-30 20:47:29 71

原创 Python:返回ndarray数组中不重复的元素

方法一:使用set()函数但是,太lou了方法二:使用numpy里面的unique()方法a = np.array([5,6,7,8,1,2,3,3,4,2,1])b = np.unique(a)print(b)为了不重复造轮子unique()方法请参考:https://blog.csdn.net/tyro_java/article/details/81052638...

2020-07-30 20:25:12 359

原创 Python:找到ndarray数组中最大元素的位置

import numpy as npfrom sklearn import datasetsfrom sklearn.linear_model import LogisticRegressionfrom sklearn.model_selection import train_test_split# a = np.array([5,6,7,8,1,2,3,3,4,2,1])# b = np.unique(a)# print(b)# X,y = datasets.load_iris(retur.

2020-07-30 20:20:30 250

原创 Python:将一个样本纳入一个序列中,最多需要多少次对比!

import numpy as npfrom copy import deepcopyfor m in range(2,25): a = m #deepcopy(m) count = 0 temp = 0 while temp != 1: temp = np.ceil(a/2) a = a - temp count += 1 print("count={}:{}".format(m,count))公式写不出,.

2020-07-21 11:10:12 64

原创 Python: 曲线比较

import numpy as npimport matplotlib.pyplot as pltA = []for m in range(3,21): A.append(m*(m-1)/2)B = []for m in range(3,21): temp = 1 for i in range(2,m): temp += np.floor(np.log2(i))+1 B.append(temp)print(A)...

2020-07-18 11:10:37 98

原创 Matlab: 获取数组中不重复的元素,可以使用unique(arr)函数即可

matlab中可以使用a = unique(train_target)python中可以使用a = set(train_target)不积跬步,无以至千里;不积小流,无以成江海跟着教程学,是最慢的看别人代码,不懂就查,查了就记,忘了再查,再记~是最快的学习方法。...

2020-07-12 10:09:57 412

原创 Python:python调用matlab代码(标签列的转换)

'''Date:2020-07-11Auther:Deniu HeEmail:hedeniu@163.comOrganization: CQUPT该版本用于测试调用matlab代码'''import matlabimport matlab.engineimport pandas as pdimport numpy as npimport osfrom sklearn import datasetsfrom sklearn.linear_model import LogisticR.

2020-07-11 21:27:47 154

原创 Matlab: dlmwrite()函数用于保存数据

请参考大神解释:https://blog.csdn.net/Autumn_He/article/details/81081528附代码演示:Data = csvread('../../exampledata/ERA.csv');targets = Data(:,end);k = 10;CVO = cvpartition(targets,'KFold',k)nameDataset = 'niuniu';rootDir = fullfile('..','..','exampledata'

2020-07-11 20:07:39 250

原创 Matlab: mkdir()函数的作用

mkdir()用于新建文件夹参考:https://ww2.mathworks.cn/help/matlab/ref/mkdir.html重点参考:https://blog.csdn.net/zhouga/article/details/104444902?utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2~all~first_rank_v2~rank_v25-1-104444902.nonecase...

2020-07-11 19:35:22 758

原创 Matlab: cvpartition()函数实现交叉验证

下面的代码是将一组数据进行10折交叉划分,并将划分好的训练集合测试集存放在一个文件夹下面:% Note: this code should be run from orca/src/code-examplesclear param;if (exist ('OCTAVE_VERSION', 'builtin') > 0) pkg load statisticsend% Load dataERAData = csvread('../../exampledata/ERA.csv')

2020-07-11 19:04:39 406

原创 Python:使用numpy.loadtxt()函数读取无格式数据

import numpy as nppath_train = r"D:\Program Files\MATLAB\orca-master\exampledata\1-holdout\toy\matlab\train_toy.0"path_test = r"D:\Program Files\MATLAB\orca-master\exampledata\1-holdout\toy\matlab\test_toy.0"trainData = np.loadtxt(path_train)testData .

2020-07-11 14:57:08 236

原创 Matlab:etime()函数的介绍

分别计算训练消耗时间和测试消耗时间: c1 = clock; [mInf.projectedTrain, mInf.predictedTrain] = obj.fit(train,param); % Save the model type obj.model.algorithm = class(obj); c2 = clock; mInf....

2020-07-11 11:58:33 348

PSO与捕鱼策略相结合的优化方法

捕鱼策略算法

2017-07-20

空空如也

空空如也
提示
确定要删除当前文章?
取消 删除