數(shù)據(jù)挖掘之Python學習筆記

ml-python.png

本文是關于learning data mining with python的學習筆記渗柿。記錄下在學習過程中的一些知識點勇婴。該書用的是python3.4攻询。
本書所用到的python包
scikit-learnhttp://scikit-learn.org/stable/
The scikit-learn package is a machine learning library, written in Python. Itcontains numerous algorithms, datasets, utilities, and frameworks for performingmachine learning.

"Data mining provides a way for a computer to learn how to make decisions with data. "


Datasets comprise of two aspects:
? Samples that are objects in the real world. This can be a book, photograph,animal, person, or any other object.
? Features that are descriptions of the samples in our dataset. Features couldbe the length, frequency of a given word, number of legs, date it was created,and so on.

Support is the number of times that a rule occurs in a dataset, which is computed bysimply counting the number of samples that the rule is valid for.
While the support measures how often a rule exists, confdence measures howaccurate they are when they can be used.

Overftting is the problem of creating a model that classifes our training datasetvery well, but performs poorly on new samples. *The solution is quite simple: neveruse training data to test your algorithm. *

scikit-learn library contains a function to split data into training andtesting components:from sklearn.cross_validation import train_test_split .

'''
This function will split the dataset into two subdatasets, 
according to a given ratio(which by default uses 25 percent of the dataset for testing). 
Xd_train contains our data for training andXd_test contains our data for testing.
 y_train and y_test give the correspondingclass values for these datasets.
random_state. Setting the random state will give the samesplit every time the same value is entered.
It will look random, but the algorithm usedis deterministic and the output will be consistent.  
'''
//test_size是樣本占比。如果是整數(shù)的話就是樣本的數(shù)量怜森。
//random_state是隨機數(shù)的種子齐遵。不同的種子會造成不同的隨機采樣結果。相同的種子采樣結果相同塔插。
from sklearn.cross_validation import train_test_split 
Xd_train, Xd_test, y_train, y_test = train_test_split(X_d, y, test_size=0.4, random_state=14) 

scikit-learn estimators

  1. support vectormachines (SVM)
  2. random forests
  3. neural networks
  • Estimators are scikit-learn's abstraction.
  • Estimators are usedfor classifcation.
    Estimators have the following two main functions :

? fit(): This performs the training of the algorithm and sets internalparameters. It takes two inputs, the training sample dataset and thecorresponding classes for those samples.
? predict(): This predicts the class of the testing samples that is given asinput. This function returns an array with the predictions of each inputtesting sample.

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末梗摇,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子想许,更是在濱河造成了極大的恐慌伶授,老刑警劉巖,帶你破解...
    沈念sama閱讀 222,729評論 6 517
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件流纹,死亡現(xiàn)場離奇詭異糜烹,居然都是意外死亡,警方通過查閱死者的電腦和手機漱凝,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 95,226評論 3 399
  • 文/潘曉璐 我一進店門疮蹦,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人茸炒,你說我怎么就攤上這事愕乎。” “怎么了壁公?”我有些...
    開封第一講書人閱讀 169,461評論 0 362
  • 文/不壞的土叔 我叫張陵感论,是天一觀的道長。 經(jīng)常有香客問我紊册,道長比肄,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 60,135評論 1 300
  • 正文 為了忘掉前任囊陡,我火速辦了婚禮芳绩,結果婚禮上,老公的妹妹穿的比我還像新娘撞反。我一直安慰自己妥色,他們只是感情好,可當我...
    茶點故事閱讀 69,130評論 6 398
  • 文/花漫 我一把揭開白布痢畜。 她就那樣靜靜地躺著垛膝,像睡著了一般。 火紅的嫁衣襯著肌膚如雪丁稀。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,736評論 1 312
  • 那天倚聚,我揣著相機與錄音线衫,去河邊找鬼。 笑死惑折,一個胖子當著我的面吹牛授账,可吹牛的內容都是我干的枯跑。 我是一名探鬼主播,決...
    沈念sama閱讀 41,179評論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼白热,長吁一口氣:“原來是場噩夢啊……” “哼敛助!你這毒婦竟也來了?” 一聲冷哼從身側響起屋确,我...
    開封第一講書人閱讀 40,124評論 0 277
  • 序言:老撾萬榮一對情侶失蹤纳击,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后攻臀,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體焕数,經(jīng)...
    沈念sama閱讀 46,657評論 1 320
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 38,723評論 3 342
  • 正文 我和宋清朗相戀三年刨啸,在試婚紗的時候發(fā)現(xiàn)自己被綠了堡赔。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,872評論 1 353
  • 序言:一個原本活蹦亂跳的男人離奇死亡设联,死狀恐怖善已,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情离例,我是刑警寧澤雕拼,帶...
    沈念sama閱讀 36,533評論 5 351
  • 正文 年R本政府宣布,位于F島的核電站粘招,受9級特大地震影響啥寇,放射性物質發(fā)生泄漏。R本人自食惡果不足惜洒扎,卻給世界環(huán)境...
    茶點故事閱讀 42,213評論 3 336
  • 文/蒙蒙 一辑甜、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧袍冷,春花似錦磷醋、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,700評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至煌恢,卻和暖如春骇陈,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背瑰抵。 一陣腳步聲響...
    開封第一講書人閱讀 33,819評論 1 274
  • 我被黑心中介騙來泰國打工你雌, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人二汛。 一個月前我還...
    沈念sama閱讀 49,304評論 3 379
  • 正文 我出身青樓婿崭,卻偏偏與公主長得像拨拓,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子氓栈,可洞房花燭夜當晚...
    茶點故事閱讀 45,876評論 2 361

推薦閱讀更多精彩內容

  • 作者:伊麗莎白·吉爾博特 一個星期五的下午渣磷,在單位的圖書室發(fā)現(xiàn)了這本書,當然授瘦,對內容一無所知醋界,就僅僅是被她的...
    木瓜書閱讀 202評論 0 0
  • 今天睡到自然醒。聽說悉尼前幾天還熱到三十多度奥务,我們呆的這兩天都下小雨物独,最高氣溫25度左右剛剛好! 在酒店簡單吃過早...
    心理師靜怡閱讀 228評論 2 2
  • 后來啊 我是怎么發(fā)現(xiàn)的呢 我不小心得知了她的聯(lián)系方式 真的是不小心 世界就是這么奇妙氯葬、這么小 然后我終于知道 當年...
    林茨閱讀 97評論 0 0
  • 年少的時候挡篓,我們都會覺得非“他,她”不可了帚称,可是過了些年官研,”他和她“即使成不了朋友,但也可以甚是平靜的說:“他呀闯睹,...
    五行缺火miss頁閱讀 245評論 0 0