码迷,mamicode.com
首页 > 其他好文 > 详细

udacity 机器学习课程

时间:2016-07-09 17:58:12      阅读:499      评论:0      收藏:0      [点我收藏+]

标签:

 

MODE 众数

mean 均值

median 中位数

standard deviation 标准差

 

numpy: 

    import numpy as np

    array_1 = np.array([[1, 2], [3, 4]], float)
    array_2 = np.array([[5, 6], [7, 8]], float)
    print array_1 + array_2
    print ""
    print array_1 - array_2
    print ""
    print array_1 * array_2


    array_1 = np.array([1, 2, 3], float)
    array_2 = np.array([[6], [7], [8]], float)
    print np.mean(array_1)
    print np.mean(array_2)
    print ""
    print np.dot(array_1, array_2)

np.dot

 

    Pandas:

    创建一个Series:

import pandas as pd
series = pd.Series([Dave, Cheng-Han, Udacity, 42, -1789710578])
print series

 

cuteness = pd.Series([1, 2, 3, 4, 5], index=[Cockroach, Fish, Mini Pig,
                                                 Puppy, Kitten])
print cuteness > 3
print ""
print cuteness[cuteness > 3]

    创建一个数据框,DataFram

    data = {year: [2010, 2011, 2012, 2011, 2012, 2010, 2011, 2012],
            team: [Bears, Bears, Bears, Packers, Packers, Lions,
                     Lions, Lions],
            wins: [11, 8, 10, 15, 11, 6, 10, 4],
            losses: [5, 8, 6, 1, 5, 10, 6, 12]}
    football = pd.DataFrame(data)
    print football

    print football.dtypes
    print ""
    print football.describe()
    print ""
    print football.head()
    print ""
    print football.tail()

 

data = {year: [2010, 2011, 2012, 2011, 2012, 2010, 2011, 2012],
            team: [Bears, Bears, Bears, Packers, Packers, Lions,
                     Lions, Lions],
            wins: [11, 8, 10, 15, 11, 6, 10, 4],
            losses: [5, 8, 6, 1, 5, 10, 6, 12]}
football = pd.DataFrame(data)
print football[year]
print ‘‘
print football.year  # shorthand for football[‘year‘]
print ‘‘
print football[[year, wins, losses]]   #显示year,wins,losses,列

print football.iloc[[0]]    #显示第一行
print football[3:5] 
print football[football.wins > 10]  #打印wins大于10的数据
print football[(football.wins > 10) & (football.team == "Packers")]

 

udacity 机器学习课程

标签:

原文地址:http://www.cnblogs.com/lixiang-/p/5656086.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!