自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(229)
  • 资源 (1)
  • 收藏
  • 关注

原创 Python: nump.pad() 函数的使用

import numpy as npa = np.array([1,2,3,4])print(a.shape)b = [0.5,1.2,1.8,1.9,2.1,2.5,2.3,3.4,3.9,4.1]print(b)tmp = a[:,None] - np.array(b)print(tmp)# pred = np.sum(tmp < 0,axis=0)# print(pred)print(" ")prob = np.pad(tmp, pad_width=((0,0),(1,1).

2020-12-02 20:49:28 4

原创 python:np.array的强制类型转换

import numpy as npa = [1,2,3,4]a = np.array(a)print(a)b = a.astype(np.float)print(b)c = b.astype(np.int)print(c)d = np.array([[1,2,],[3,4]])e = d.astype(np.float)print(e)

2020-12-02 18:51:23 16

原创 Python:序分类方法比较

import timeimport xlwtimport matlabimport matlab.engineimport numpy as npimport pandas as pdfrom pathlib import Pathfrom copy import deepcopyfrom collections import OrderedDictfrom sklearn.linear_model import LogisticRegressionfrom sklearn.model.

2020-11-27 15:05:20 15

原创 MATLAB:repmat() 函数的使用

repmat函数repmat函数主要是用于快速的产生一个大的矩阵,它的用法一般有下面几种:B = repmat(A,M,N)矩阵B是矩阵A的复制品,其中B的维度为[size(A,1)*M, size(A,2)*N]。如果你写成repmat(A,[M,N])也是可以的;如果你写成repmat(A,N),那么它等价于repmat(A,N,N)或者repmat(A,[N,N])。其实就是把A当做一个元素,让后生成一个M*N的矩阵,该矩阵的每个元素位置放置一个A首先有A 了得到的B就

2020-11-26 16:41:59 19

原创 二分法找规律

2020-11-25 14:19:11 13

原创 Python:原始TOPSIS算法代码(两个属性)

import numpy as npfrom sklearn.metrics import recall_scorefrom sklearn.preprocessing import MinMaxScalerfrom collections import OrderedDictclass TOPSIS(): def __init__(self,X): self.X = X self.Xbest = self.find_best() print.

2020-11-23 08:38:32 25

原创 Python:a=[2,3], 返回a[1:-1]是啥?

import numpy as npfrom sklearn.metrics import recall_scorefrom collections import OrderedDict# a = [1,2,3,4]# print(a[1:-1])# print(np.random.choice(a[1:-1],1,replace=False))b = [2,3]for lab in b[1:-1]: print("lab",lab)返回一个空

2020-11-22 15:35:39 17

原创 python:计算字典中值的和

import numpy as npfrom sklearn.metrics import recall_scorefrom collections import OrderedDicty_pred = [1,1,1,2,2,2,3,3,3,4,4,4]y_true = [1,1,2,2,2,3,3,4,4,4,4,4]# print(recall_score(y_true=y_true,y_pred=y_pred,average='macro'))# print(recall_score(.

2020-11-18 15:41:09 35

原创 Python:半监督BDOR 效果不好

'''date:2020-11-17半监督方法效果非常不好'''import numpy as npimport pandas as pdimport matplotlib.pyplot as pltfrom pathlib import Pathfrom copy import deepcopyfrom collections import OrderedDictfrom sklearn.linear_model import LogisticRegressionfrom skle.

2020-11-17 10:47:18 27

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

import numpy as npimport pandas as pdimport matplotlib.pyplot as pltfrom pathlib import Pathfrom copy import deepcopyfrom collections import OrderedDictfrom sklearn.linear_model import LogisticRegressionfrom sklearn.svm import SVCfrom sklearn impo.

2020-11-17 10:05:24 29

原创 Python:Binary Decomposition Method for Ordinal Regression

Two strategies:BD--,BD++5 times 10-fold cross validationimport numpy as npimport pandas as pdfrom pathlib import Pathfrom copy import deepcopyfrom collections import OrderedDictfrom sklearn.linear_model import LogisticRegressionfrom sklearn..

2020-11-16 21:57:35 23

原创 Python: equal-frequency-bin 等频装箱

import numpy as npimport pandas as pdpath = r"D:\OCdata\baseball.csv"data = np.array( pd.read_csv(path,header=None))print(data.shape)y = data[:,-1]ord_idx = np.argsort(y)Bins = [67, 68, 68, 67, 67]label = []idx = 0for lab, ele in enumerate(Bins.

2020-11-09 22:40:54 30

原创 Python:更改数据集类别,笨方法。

import numpy as npimport pandas as pdpath = r"D:\OCdata\winequality-white.csv"data = np.array( pd.read_csv(path,header=None))print(data.shape)y = data[:,-1]print(y.shape)print(np.unique(y,return_counts=True))for i, ele in enumerate(y): data[i,.

2020-11-09 21:31:36 31

原创 Python:try 和 except 使用注意事项

无问题代码段落: for pair in pair_list: try: pair_path_dict[pair] = nx.shortest_path(self.G,source=pair[0],target=pair[1]) except: pair_path_dict[pair] = []有问题代码段落: for pair in pair_lis.

2020-11-05 09:41:00 37

原创 Python:调用matlab注意事项1

启动matlab引擎是要花费时间的,大约5秒-10秒这样。engine = matlab.engine.start_matlab()如果有对比算法需要连续顺序运行(都需要启动engine),建议将engine启动语句写在外围,只启动一次,然后多个对比算法调用它。数据类型转换这里不会造成大量时间开销。import numpy as npimport matlaba = np.array([[1,2],[1,2],[1,2],[1,2]])print(a)print([[1,2.

2020-11-05 09:34:41 20

原创 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 167

原创 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 67

原创 Sigmoid函数求导

sigmoid 函数sigmoid函数求导过程

2020-10-09 19:09:32 34

原创 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 68 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 47

原创 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 67

原创 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 64

原创 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 89

原创 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 58

原创 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 40

原创 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 62

原创 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 59

原创 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 89

原创 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 95

原创 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 158

原创 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 95

原创 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 62

原创 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 74

原创 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 309

原创 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 66

原创 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 177

原创 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 327

原创 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 144

原创 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 1321

原创 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 777 1

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

捕鱼策略算法

2017-07-20

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人 TA的粉丝

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