从可处理混合类型数据和缺失值的研究论文中实现最新的距离度量。

distython的Python项目详细描述


距离

从研究论文中实现最新的距离度量,它可以处理混合类型的数据和丢失的值。 目前,heom、hvdm和vdm已经测试并投入使用。vdm和hvdm最近已经发布,如果有错误,请报告。 请随时帮助和贡献的项目,因为缺乏现有的实现距离度量。

安装

使用git clone克隆存储库。 使用pipenv install

安装必要的软件包

示例-heom

# Example code of how the HEOM metric can be used together with Scikit-Learnimportnumpyasnpfromsklearn.neighborsimportNearestNeighborsfromsklearn.datasetsimportload_boston# Importing a custom metric classfromHEOMimportHEOM# Load the dataset from sklearnboston=load_boston()boston_data=boston["data"]# Categorical variables in the datacategorical_ix=[3,8]# The problem here is that NearestNeighbors can't handle np.nan# So we have to set up the NaN equivalentnan_eqv=12345# Introduce some missingness to the data for the purpose of the examplerow_cnt,col_cnt=boston_data.shapeforiinrange(row_cnt):forjinrange(col_cnt):rand_val=np.random.randint(20,size=1)ifrand_val==10:boston_data[i,j]=nan_eqv# Declare the HEOM with a correct NaN equivalent valueheom_metric=HEOM(boston_data,categorical_ix,nan_equivalents=[nan_eqv])# Declare NearestNeighbor and link the metricneighbor=NearestNeighbors(metric=heom_metric.heom)# Fit the model which uses the custom distance metric neighbor.fit(boston_data)# Return 5-Nearest Neighbors to the 1st instance (row 1)result=neighbor.kneighbors(boston_data[0].reshape(1,-1),n_neighbors=5)print(result)

研究论文

该代码基于以下文献实现: heom、vdm和hvdm:https://arxiv.org/pdf/cs/9701101.pdf

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java引用MediaPlayer中断脚本?NullPointerException(JavaFX)   用于查找字符串的java正则表达式模式包含一些单词,而没有其他单词   使用Jfreechart和Runnable接口在java上显示实时数据的多线程处理   java如何在获取imei信息时获取dialogFragment中的上下文   安卓 Java在一个循环中打印每个i   apache kafka主题上的java流媒体没有输出   java是在Akka中模拟大量HTTP连接的最佳方法   java如何使用ibatis注释进行批插入   硬件如何在Linux、Windows和Mac上使用Java+JNI检索硬盘的唯一ID   java声明实例变量并实现getter方法?   java正则表达式和新行   java有没有办法使用安卓的Play Core安装本地apk?   java将Graphics2D绘制到另一个Graphics2D   使用Spring和Glassfish的JtaTransactionManager的java JNDI初始上下文   java是一个JPanel问题   网络Java UDP数据包丢失。50%   java如何从字符串正则表达式中提取数据   java 安卓不录制或编码声音