当前位置: 首页 > news >正文

数据挖掘(作业1)

实验开始前先配置环境

以实验室2023安装的版本为例:

1、安装anaconda:(anaconda自带Python,安装了anaconda就不用再安装Python了
下载并安装 Anaconda3-2022.10-Windows-x86_64.exe

自己选择安装路径,其他使用默认选项。

(1)在“Advanced Installation Options”中,
勾选“Add Anaconda3 to my PATH environment variable.”(“添加Anaconda至我的环境变量。”)。

(2)勾选“Register Anaconda3 as my default Python 3.9”。

2、安装pycharm
下载并安装 pycharm-community-2022.2.4.exe 

3、打开cmd窗口,输入以下命令

conda create -n  DMEv  pip python=3.8

 记住DMEV所在的磁盘路径

# 如需删除环境,使用命令 conda remove -n DMEv    --all

 安装要用到的Python库:
activate   DMEv  

pip install numpy==1.20.0 --index-url https://mirrors.aliyun.com/pypi/simple/
pip install matplotlib==3.3.4 --index-url https://mirrors.aliyun.com/pypi/simple/
pip install opencv_python==4.4.0.40 --index-url https://mirrors.aliyun.com/pypi/simple/

pip install scipy==1.6.0 --index-url https://mirrors.aliyun.com/pypi/simple/
pip install scikit-learn==0.24.1 --index-url https://mirrors.aliyun.com/pypi/simple/ 

pip install h5py==2.10.0 --index-url https://mirrors.aliyun.com/pypi/simple/ 

pip install mnist==0.2.2 --index-url https://mirrors.aliyun.com/pypi/simple/ 


4、测试

在Pycharm中创建项目时,DMEV所在的路径下选择python.exe即可


在Pycharm中新建项目,配置 interpreter,运行以下代码:(没有报错,则导入成功
import cv2 as cv
import numpy as np
from sklearn.decomposition import PCA
import mnist
import matplotlib.pyplot as plt 

 

实验1 数据

一、实验目的

(1)练习和掌握python的基本使用。

(2)理解数据类型、数据质量、数据预处理、相似性和相异性度量的概念

(3)理解各种相似性和相异性度量(测度)及其含义,并且能编程计算。

二、实验内容

1编程实现任意给定两个相同维度的向量之间的欧氏距离计算函数dist_E(x,y)。

输入:两个任意k维向量x和y,其中k的值随由数据决定。如x=[3,20,3.5], y=[-3,34,7]。

import numpy as npdef dist_E(vect1, vect2):return np.sqrt(sum(np.power((vect1-vect2),2)))if __name__ == "__main__":x=np.array([3,20,3.5])y=np.array([-3,34,7])dist=dist_E(x,y)print(dist)

2编程实现任意给定两个相同维度的向量之间的夹角余弦相似度计算函数sim=sim_COS(x,y)。输入:两个任意k维向量x和y,其中k的值由数据决定。

import numpy as npdef sim_COS(x, y):num = x.dot(y.T)denom = np.linalg.norm(x) * np.linalg.norm(y)return num / denomif __name__ == "__main__":x=np.array([3, 2, 0, 5, 0, 0, 0, 2, 0, 0])y=np.array([1, 0, 0, 0, 0, 0, 0, 1, 0, 2])sim=sim_COS(x,y)print(sim)

3编程实现任意给定两个相同维度的布尔向量之间的Jaccard系数计算函数dist1=dist_Jaccard(x,y)。

import numpy as npdef sim_Jaccard(vect1, vect2):sim=-1if(vect1.size!=vect2.size):print("length of input vectors must agree")else:ind1=np.logical_and(vect1==1,vect2==1)ind2=np.logical_or(vect1==1,vect2==1)x=vect1[ind1]y=vect2[ind2]n1=np.size(x)n2=np.size(y)sim=n1/n2return simif __name__ == "__main__":x=np.array([1, 0, 0, 0, 0, 0, 1, 0, 0, 0])y=np.array([1, 0, 0, 0, 0, 0, 0, 0, 0, 1])dist=sim_Jaccard(x,y)print(dist)

4编程实现任意给定两个相同维度的布尔向量之间的简单匹配系数计算函数dist1=dist_SMC(x,y)。

import numpy as npdef sim_SMC(vect1, vect2):sim = -1if (vect1.size != vect2.size):print("length of input vectors must agree")else:ind0 = np.logical_and(vect1 == 0, vect2 == 0)ind1 = np.logical_and(vect1 == 1, vect2 == 1)ind2 = np.logical_or(vect1 == 1, vect2 == 1)x = vect1[ind1]y = vect1[ind2]z=vect1[ind0]n1 = np.size(x)n2 = np.size(y)n3 = np.size(z)sim = (n1+n3) / (n2+n3)return simif __name__ == "__main__":x=np.array([1, 0, 0, 0, 0, 0, 1, 0, 0, 0])y=np.array([1, 0, 0, 0, 0, 0, 0, 0, 0, 1])dist=sim_SMC(x,y)print(dist)

http://www.lryc.cn/news/32830.html

相关文章:

  • 【UE4 RTS游戏】01-项目准备
  • 登录系统账号检测--课后程序(Python程序开发案例教程-黑马程序员编著-第3章-课后作业)
  • CentOS8基础篇12:使用RPM管理telnet-server软件包
  • IT女神文章记录之自己
  • Compose 动画 (四) : AnimatedVisibility 各种入场和出场动画效果
  • notepad++学习小技巧
  • Android supports-screens 屏幕适配
  • 操作系统基础知识介绍之Mixed CriticalitySystems——混合关键系统
  • 【数据结构初阶】详解链表OJ题
  • Java基本数据类型变量自动提升、强制类型转换、String基本类型使用
  • Redis锁与幂等性不得不说的故事
  • Spark 应用调优
  • synchronized 与 volatile 关键字
  • 【0成本搭建个人博客】——Hexo+Node.js+Gitee Pages
  • 【面试实战】认证授权流程及原理分析
  • TPM命令解析之tpm2_startauthsession
  • 第14章 局部波动率模型
  • 云原生周刊:开源“赢了”,但它可持续吗?
  • 读《企业IT架构转型之道》
  • Qt中的QTcpSocket、QWebSocket和QLocalSocket
  • 枚举学习贴
  • 【C++】30h速成C++从入门到精通(继承)
  • Java多线程还不会的进来吧,为你量身打造
  • 8 神经网络及Python实现
  • 使用QIS(Quantum Image Sensor)图像重建总结(1)
  • 【SpringCloud】SpringCloud教程之Nacos实战(二)
  • 利用Qemu工具仿真ARM64平台
  • 【Hello Linux】进程控制 (内含思维导图)
  • 嵌入式linux物联网毕业设计项目智能语音识别基于stm32mp157开发板
  • 【黄河流域公安院校网络空间安全技能挑战赛】部分wp