数据集如下所示
,id,revenue ,profit
0,101,779183,281257
1,101,144829,838451
2,101,766465,757565
3,101,353297,261071
4,101,1615461,275760
5,101,246731,949229
6,101,951518,301016
7,101,444669,430583
代码如下
import pandas as pd;
from sklearn.cluster import DBSCAN
import matplotlib.pyplot as plt
import numpy as np
from sklearn.preprocessing import StandardScaler
import seaborn as sns
from sklearn.neighbors import NearestNeighbors
df = pd.read_csv('1.csv',index_col=None)
df1 = StandardScaler().fit_transform(df)
dbsc = DBSCAN(eps = 2.5, min_samples = 20).fit(df1)
labels = dbsc.labels_
我的df形状是1999
我从下面的方法中得到了倾角值eps
值,从图中可以清楚地看出,eps=2.5
下面是找到最佳每股收益值的方法
ns = 5
nbrs = NearestNeighbors(n_neighbors=ns).fit(df3)
distances, indices = nbrs.kneighbors(df3)
distanceDec = sorted(distances[:,ns-1], reverse=True)
plt.plot(indices[:,0], distanceDec)
#plt.plot(list(range(1,2000)), distanceDec)
eps
?在不查看图形的情况下,我的系统必须告诉besteps
如果我理解正确,您正在寻找ε(x)图中出现的拐点的精确y值(应该在2.0左右),对吗
如果这是正确的,当你的曲线ε(x)时,问题将简化为:
在此,我附上我的答案,基于这两个其他堆栈溢出答案: https://stackoverflow.com/a/26042315/10489040(计算数组的导数) https://stackoverflow.com/a/3843124/10489040(在数组中查找零)
在任何情况下,请记住拐点(2.0左右)与出现在2.5左右的“下倾”点不匹配
相关问题 更多 >
编程相关推荐