from sklearn import datasets
from sklearn import model_selection
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from mord import LogisticAT
X,y = datasets.make_blobs(n_samples=400, n_features=2,center_box=(-20,20),centers=4,cluster_std=[3,3,3,3],random_state= 3)
# print(np.unique(y))
# for i in np.unique(y):
# idxlist = []
# for j in range(400):
# if y[j] == i:
# idxlist.append(j)
# E = X[idxlist]
# plt.scatter(E[:,0],E[:,1],label=np.str(i))
# plt.legend()
# plt.show()
for i, ele in enumerate(y):
if ele == 3:
y[i] = 0
elif ele == 0:
y[i] = 2
elif ele == 2:
y[i] = 3
for i in range(4):
idxlist = []
for j in range(100):
if y[j] == i:
idxlist.append(j)
E = X[idxlist]
plt.scatter(E[:,0],E[:,1],label=np.str(i))
plt.legend()
plt.show()
y = np.vstack(y)
data = np.hstack((X,y))
data = pd.DataFrame(data)
data.to_csv(r"D:\OCdata\line.csv",header=None,index=None)
Python:生成线性的Ordinal Regression 数据并保存
最新推荐文章于 2022-01-05 19:14:06 发布