本文是中国MOOC大学《Python机器学习基础》学习笔记。
DBSCAN(Density-Based Spatial Clustering of Applications with Noise)是一一种基于密度的聚类算法。
现有学生上网数据格式如下:
数据下载地址:https://pan.baidu.com/s/1eR7doh8
目的:通过DBSCAN聚类,分析学生上网时间和上网时长的模式
代码(Python 3.6+):
import numpy as np
import sklearn.cluster as skc
from sklearn import metrics
import matplotlib.pyplot as plt
"""
学生上网日志单条记录格式
记录编号 学生编号 MAC地址 IP地址 开始上网时间 停止上网时间 上网时长
2c929293466b97a6014754607e457d68,U201215025,A417314EEA7B,10.12.49.26,2014-07-20 22:44:18.540000000,2014-07-20 23:10:16.540000000,1558,15,本科生动态IP模版,100元每半年,internet
"""
mac2id = dict()
"""
key是MAC地