关联分析算法

分享到 评论

sklearn 预测Titanics乘客生还率

导入外部包
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import pandas as pd
from pandas import Series,DataFrame

import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style('whitegrid')
%matplotlib inline

# machine learning
from sklearn.linear_model import LogisticRegression
from sklearn.svm import SVC,LinearSVC
from sklearn.ensemble import RandomForestClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.naive_bayes import GaussianNB
使用pandas导入并分析数据集
1
2
3
4
titanic_df = pd.read_csv(r"F:\数据集\Titanic数据分析\train.csv")
test_df = pd.read_csv(r"F:\数据集\Titanic数据分析\test.csv")
# 查看df前5行
titanic_df.head()




使用dataFram.info 和describe查看具体信息




查看更多

分享到 评论

使用python和plotly分析可视化mysql数据库

分析结果

选择Mysql官网上的world数据库,包含所有国家的所属大洲、人口、平均寿命、国民生产总值GNP,得出的结论如下:

  1. 全球平均寿命37岁,平均国民生产总值1.2万亿美元
  2. 在美国、中国、韩国、匈牙利、澳大利亚五个国家中,国民生产总值最高的是澳大利亚,平均寿命最高的是美国79.4,人口最多的中国13亿
  3. 看国民产生总值与人口、平均寿命有没有相关性,都是弱相关,人口相关性高一点
    相关系数<0.4显著弱相关; 0.4-0.75中等相关; 大于0.75强相关
  4. 北美的国民生产总值最高,人口亚洲最多占51%
  5. 平均寿命65-75最多,84个,占38%
  6. 国民生产总值和平均寿命都位于前前列的国家是美国、中国、日本

分析步骤

在Mysql中创建world数据库

将MySQL的“world”样例数据库导入到本地中。

1
2
3
CREATE DATABASE world;
USE world;
SOURCE /Desktop/world.sql;

分析可视化world数据

导入外部包

sns.set_style 为微软雅黑,才能在图表中正常显示中文

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# plotly库
import pymysql.cursors
import pandas as pd
import plotly.plotly as py
import plotly
from plotly.graph_objs import *
plotly.tools.set_credentials_file(username='walsky', api_key='...')
py.sign_in("walsky", "...")

# pandas、nump、seaborn库
from pandas import DataFrame, Series
import numpy as np
from numpy import random
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
sns.set_style('whitegrid',{'font.sans-serif':['simhei','Arial']})
import plotly.graph_objs as go
plotly.offline.init_notebook_mode()
使用pymysql连接查询数据库
1
2
3
4
5
6
7
8
9
10
11
12
13
14
connection = pymysql.connect(host = 'localhost',
user = 'walsky',
password = 'wal139491007',
db = 'world',
charset='utf8mb4',
cursorclass = pymysql.cursors.DictCursor
)
try:
with connection.cursor() as cursor:
sql = 'select Name, Continent, Population, LifeExpectancy, GNP from Country'
cursor.execute(sql)
result = cursor.fetchall()
finally:
connection.close()
将查询的结果加载到DataFrame中

df1 按照原始查询到的数据生成的DataFrame

1
2
df1 = pd.DataFrame(result)
df1.columns

df 是按照平均寿命升序排列的DataFrame

1
2
3
df = pd.DataFrame( result )
df = df[['Name','Continent','Population','LifeExpectancy','GNP']]
df = df.sort_values(['LifeExpectancy'],ascending=True)

计算汇总统计量

汇总统计量是 数字列的计算结果,包括非空值count数量,最大最小,中位数、均值等。

1
df.describe()

观测前五行数据和中国的数据:

查看更多

分享到 评论

mathjax的使用

Mathjax与LaTex公式简介(英文)
mathjax使用

csdn_Mathjax基本使用方法
简书Haroopad使用

显示目录使用空行+[toc] 如下面显示的那样

Haroopad的额外使用

haroopad插入音频视频

audio

video

[toc]

Tasklist

  • [x] Be happy everyday, silme, and talk more
  • [x] 2016.12.1 学习mathjax语法
  • [x] ng Linear Regression
  • [x] 每天进步一点就够了,Do not make youself terid and unhappy

视图 Presentation mode

Haroopad支持直接撰写PPT。
使用***作为每一个PPT的分页,这样显示的就是一个独立的一页,如果需要使用Haroopad做PPT的话


Mathjax

MathJax是一款运行在浏览器中的开源的数学符号渲染引擎,使用MathJax可以方便的在浏览器中显示数学公式,不需要使用图片。可以解析LaTex、MathML和ASCIIMathMl的标记语言。

\ 右斜杠大法好, 一般都是右斜杠+字母

有两种公式显示形式:

  • 行内的公式,写在$...$
  • 单独展示的公式,使用$$...$$
    这两种方式的渲染效果不同,如下所示:
    1
    2
    $\sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}6\tag{inline}$
    $$\sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}6\tag{displayed}$$

$\sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}6\tag{inline}$

$$\sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}6\tag{displayed}
$$

####上标与下标:
x_i^2     $x_i^2$

一般都是先写下标再写上标

x^{yz}     $x^{yz}$
x^{y^z}     $x^{y^z}$
x_{i^2}     $x_{i^2}$

希腊字母(大小写)

比如用:使用\Gamma, \Delta, ...,\Omega表示大写的希腊字母:
$\Gamma$ ,$\Delta$, $\Omega$

使用\alpha,\beta,\gamma,epsilon表示希腊小写字母
$\alpha$,$\beta$,$\gamma$,$\epsilon$

      详情看下表:

查看更多

分享到 评论