转化非正态分布数据
摘要:在对数据进行线性拟合时,常常要求该变量满足正态分布,通常变量不满足或者正态分布拟合的不是很好。 如何把这些数据转换成正态分布的数据? 1.使用log()函数通常能使数据集向正态分布靠近。 若数据集中数据存在负数,则需要对数据进行预处理: 大致预处理如下:1)对数据进行归一化,即把数据映射到[0,1]
阅读全文
posted @
2018-03-18 22:45
郑哲
阅读(2518)
推荐(0) 编辑
使用NetworkX来进行数据可视化
摘要:1 %matplotlib notebook 2 3 import networkx as nx 4 import matplotlib.pyplot as plt 5 6 # 数据读取 7 G = nx.read_gpickle('major_us_cities') 1 # draw the graph using the default spring layout 2 plt.fig...
阅读全文
posted @
2018-03-15 16:34
郑哲
阅读(4660)
推荐(2) 编辑
使用NetworkX进行社交分析
摘要:邻接表 G_adjlist.txt is the adjaceny list representation of G1. It can be read as follows: 0 1 2 3 5 →→ node 0 is adjacent to nodes 1, 2, 3, 5 1 3 6 →→ n
阅读全文
posted @
2018-03-15 14:55
郑哲
阅读(917)
推荐(0) 编辑
文本情感分析
摘要:CountVectorizer AUC: 0.889951006492 AUC: 0.889951006492 AUC: 0.889951006492 AUC: 0.889951006492 AUC: 0.889951006492 1 feature_names = np.array(vect.ge
阅读全文
posted @
2018-03-15 13:48
郑哲
阅读(782)
推荐(0) 编辑
使用NLTK进行基础的NLP处理
摘要:1 import nltk 2 from nltk.book import * *** Introductory Examples for the NLTK Book *** Loading text1, ..., text9 and sent1, ..., sent9 Type the name
阅读全文
posted @
2018-03-15 13:24
郑哲
阅读(1363)
推荐(1) 编辑
使用pandas对文本数据进行处理
摘要:1 import pandas as pd 2 3 time_sentences = ["Monday: The doctor's appointment is at 2:45pm.", 4 "Tuesday: The dentist's appointment is at 11:30 am.", 5 "Wed...
阅读全文
posted @
2018-03-15 12:53
郑哲
阅读(2019)
推荐(0) 编辑
文本处理
摘要:['#UNSG'] ['#UNSG'] ['#UNSG'] ['#UNSG'] ['#UNSG'] 1 [w for w in text6 if w.startswith('@')] ['@'] 1 text7 = '@UN @UN_Women "Ethics are built right int
阅读全文
posted @
2018-03-15 09:52
郑哲
阅读(194)
推荐(0) 编辑
分类器可视化
摘要:这本笔记本的目的是让你可视化各种分类器的决策边界。 本笔记本中使用的数据基于存储在mushrooms.csv中的UCI蘑菇数据集。 为了更好地确定决策边界,我们将对数据执行主成分分析(PCA)以将维度降至2维。 降维将在本课程后面的模块中介绍。 玩弄不同的模型和参数,看看它们如何影响分类器的决策边界
阅读全文
posted @
2018-03-15 09:41
郑哲
阅读(2074)
推荐(0) 编辑
无监督学习
摘要:数据准备 降维和流形学习 PCA 使用PCA查找乳腺癌数据集的前两个主要组成部分 画出各个因素对两个主成分的影响大小 PCA用于水果数据集(用于比较) 多种学习方法 水果数据集上的多维缩放(MDS) 乳腺癌上的多维缩放 t-SNE on the fruit dataset (结果不是很好) t-SN
阅读全文
posted @
2018-03-14 15:10
郑哲
阅读(553)
推荐(0) 编辑
监督学习2
摘要:序言和数据集 贝叶斯分类器 Application to a real-world dataset 决策树集成 随机森林 Random forest: Fruit dataset Random Forests on a real-world dataset Gradient-boosted deci
阅读全文
posted @
2018-03-14 14:44
郑哲
阅读(482)
推荐(0) 编辑
模型验证
摘要:对分类模型的检验 加载数据 Decision tree classifier (max_depth = 2) [[400 7] [ 17 26]] Decision tree classifier (max_depth = 2) [[400 7] [ 17 26]] Decision tree cl
阅读全文
posted @
2018-03-12 10:16
郑哲
阅读(612)
推荐(0) 编辑
监督学习模型(线性回归,非线性回归,逻辑回归,SVM,决策树,岭回归,Losso回归)
摘要:一.数据产生 KNN分类 KNN回归预测 KNN参数k对回归预测的影响 线性回归预测模型 线性回归图示 多元线性回归预测 岭回归 Lasso 回归 逻辑回归正则化参数的影响 应用于真实数据 SVM 线性SVM Linear Support Vector Machine: C parameter 线性
阅读全文
posted @
2018-03-11 22:57
郑哲
阅读(4479)
推荐(0) 编辑
一个简单的分类模型knn
摘要:knn中聚类个数k对最后准确率的影响 knn对数据集train/test划分比例的敏感性
阅读全文
posted @
2018-03-10 12:14
郑哲
阅读(1425)
推荐(0) 编辑
Seaborn
摘要:1 import numpy as np 2 import pandas as pd 3 import matplotlib.pyplot as plt 4 import seaborn as sns 5 6 %matplotlib notebook 1 np.random.seed(1234) 2 3 v1 = pd.Series(np.random.normal(0,10,1000)...
阅读全文
posted @
2018-03-09 21:32
郑哲
阅读(341)
推荐(0) 编辑
Pandas可视化
摘要:DataFrame.plot 我们可以设置plot函数中的kind来决定我们想画什么 下面列举kind的的可选值 kind : 'line' : 直线(默认) 'bar' : 垂直条形图 'barh' : 水平条形图 'hist' : 直方图 'box' : 箱型图 'kde' : 核密度估计图 '
阅读全文
posted @
2018-03-09 21:18
郑哲
阅读(232)
推荐(0) 编辑
交互性(Interactivity)
摘要:1 plt.figure() 2 data = np.random.rand(10) 3 plt.plot(data) 4 #创建点击事件 5 def onclick(event): 6 plt.cla() 7 plt.plot(data) 8 plt.gca().set_title('Event at pixels {},{} \nand data {}...
阅读全文
posted @
2018-03-09 20:50
郑哲
阅读(1109)
推荐(0) 编辑
动画(animation)
摘要:1 import matplotlib.animation as animation 2 3 n = 100 4 x = np.random.randn(n) 1 # create the function that will do the plotting, where curr is the current frame 2 def update(curr): 3 # ch...
阅读全文
posted @
2018-03-09 20:44
郑哲
阅读(242)
推荐(0) 编辑
热图
摘要:1 plt.figure() 2 3 Y = np.random.normal(loc=0.0, scale=1.0, size=10000) 4 X = np.random.random(size=10000) #bins设置区间大小 5 _ = plt.hist2d(X, Y, bins=25) 1 plt.figure() 2 _ = plt.hist2d(X, Y, bins=1...
阅读全文
posted @
2018-03-09 20:40
郑哲
阅读(195)
推荐(0) 编辑
箱型图
摘要:1 import pandas as pd 2 normal_sample = np.random.normal(loc=0.0, scale=1.0, size=10000) 3 random_sample = np.random.random(size=10000) 4 gamma_sample = np.random.gamma(2, size=10000) 5 6 #创建新...
阅读全文
posted @
2018-03-09 20:34
郑哲
阅读(393)
推荐(0) 编辑
直方图
摘要:在图像上直方图和条形图相似,但是直方图是用来统计数据在某个值上的数量。
阅读全文
posted @
2018-03-09 20:10
郑哲
阅读(358)
推荐(0) 编辑
柱形图
摘要:用线性数据画柱状图 1 plt.figure() 2 xvals = range(len(linear_data)) 3 plt.bar(xvals, linear_data, width = 0.3) 4 5 new_xvals = [] 6 7 # 创建new_xvals使横坐标向右移动0.3,用平方数据画红色的柱状图 8 for item in xvals: 9 ...
阅读全文
posted @
2018-03-09 19:41
郑哲
阅读(200)
推荐(0) 编辑
Scatterplots画点
摘要:1 import numpy as np 2 3 x = np.array([1,2,3,4,5,6,7,8]) 4 y = x 5 6 plt.figure() 7 plt.scatter(x, y) # similar to plt.plot(x, y, '.'), but the underlying child objects in the axes are not Line2D ...
阅读全文
posted @
2018-03-09 18:47
郑哲
阅读(654)
推荐(0) 编辑
matplotlib基础画线
摘要:%%html<img src='test.png' />
阅读全文
posted @
2018-03-06 15:38
郑哲
阅读(311)
推荐(0) 编辑
数据拷贝
摘要:1 r2 = r[:3,:3] 2 r2 array([[ 0, 1, 2], [ 6, 7, 8], [12, 13, 14]]) 1 r2[:] = 0 2 r2 array([[0, 0, 0], [0, 0, 0], [0, 0, 0]])此时r= array([[ 0, 0, 0, 3,
阅读全文
posted @
2018-03-05 20:27
郑哲
阅读(185)
推荐(0) 编辑
数组索引
摘要:1 s = np.arange(13)**2 2 s array([ 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144]) 1 s[0], s[4], s[-1] (0, 16, 144) 1 s[1:5] array([ 1, 4, 9, 16])
阅读全文
posted @
2018-03-05 20:24
郑哲
阅读(201)
推荐(0) 编辑
数组函数
摘要:1 a = np.array([-4, -2, 1, 3, 5]) 2 a.sum() 3 1 a.max() 5 1 a.min() -4 1 a.mean() 0.60 1 a.std() 3.26 1 a.argmax() 4 1 a.argmin() 0
阅读全文
posted @
2018-03-05 20:19
郑哲
阅读(105)
推荐(0) 编辑
数组操作符
摘要:1 print(x + y) # elementwise addition [1 2 3] + [4 5 6] = [5 7 9] 2 print(x - y) # elementwise subtraction [1 2 3] - [4 5 6] = [-3 -3 -3] [5 7 9] [-3
阅读全文
posted @
2018-03-05 20:17
郑哲
阅读(117)
推荐(0) 编辑
numpy
摘要:1 import numpy as np %通过链表创建数组1 mylist = [1, 2, 3] 2 x = np.array(mylist) 3 x array([1, 2, 3]) %直接创建数组1 y = np.array([4, 5, 6]) 2 y array([4, 5, 6]) %创建多维数组1 m = np.array([[7, 8, 9], [10, 11,...
阅读全文
posted @
2018-03-05 20:13
郑哲
阅读(113)
推荐(0) 编辑
λ和列表解析
摘要:%下面是lambda的示例,它包含三个参数并添加前两个参数。1 my_function = lambda a, b, c : a + b 2 my_function(1, 2, 3) 3 1 my_list = [] 2 for number in range(0, 1000): 3 if numb
阅读全文
posted @
2018-03-05 20:03
郑哲
阅读(112)
推荐(0) 编辑
object和map
摘要:1 class Person: 2 department = 'School of Information' #a class variable 3 4 def set_name(self, new_name): #a method 5 self.name = new_name 6 def set_
阅读全文
posted @
2018-03-05 20:00
郑哲
阅读(111)
推荐(0) 编辑
日期Dates时间Times
摘要:1 import datetime as dt 2 import time as tm %时间从纪元开始以秒为单位返回当前时间。(1970年1月1日)1 tm.time() 1520242063.03 1 dtnow = dt.datetime.fromtimestamp(tm.time()) 2
阅读全文
posted @
2018-03-05 19:56
郑哲
阅读(223)
推荐(0) 编辑
csv文件的读写
摘要:Let's import our datafile mpg.csv, which contains fuel economy data for 234 cars. mpg : miles per gallon class : car classification cty : city mpg cyl
阅读全文
posted @
2018-03-05 19:53
郑哲
阅读(494)
推荐(0) 编辑
更多关于字符串string
摘要:1 print('Chris' + 2) TypeError Traceback (most recent call last) <ipython-input-37-82ccfdd3d5d3> in <module>() > 1 print('Chris' + 2) TypeError: must
阅读全文
posted @
2018-03-05 19:32
郑哲
阅读(112)
推荐(0) 编辑
解压序列
摘要:%解压序列到不同的变量中1 x = ('Christopher', 'Brooks', 'brooksch@umich.edu') 2 fname, lname, email = x 1 fname 'Christopher' 1 lname 'Brooks' %确保变量的数量和解压的值相同1 x = ('Christopher', 'Brooks', 'brooksch@umi...
阅读全文
posted @
2018-03-05 19:30
郑哲
阅读(75)
推荐(0) 编辑
字典
摘要:%字典用keys来连接values1 x = {'Christopher Brooks': 'brooksch@umich.edu', 'Bill Gates': 'billg@microsoft.com'} 2 x['Christopher Brooks'] # Retrieve a value
阅读全文
posted @
2018-03-05 19:28
郑哲
阅读(89)
推荐(0) 编辑
python类型和序列
摘要:NoneType int float function
阅读全文
posted @
2018-03-05 18:51
郑哲
阅读(111)
推荐(0) 编辑