Machine learning in GCP(first week)

以下是coursera上的課程:
Machine learning with tensorflow on Google Cloud Platform
https://www.coursera.org/learn/google-machine-learning/home/welcome
第一周內容的一些摘錄與個人思考

1,To be successful at ML, you need to think, not just about creating models, but also serving out ML predictions
如果想好好利用機器學習,讓其在你的業務中發揮作用,你應該多想想,如何實現prediction這一步,而不僅是創建模型。

2,we should make sure that we could process batch data and stream data the same way.
這和#1說的是同一個問題,有很多公司使用ML改進業務都是失敗的,比如建好了模型,卻不知道如何把生產中的數據源源不斷地塞進這個模型來進行訓練,比如:batch data,也就是常見的日志文件,圖片等,stream data也就是收集上來的metrics和events,你有考慮過如何把這些不同類型的實際數據,轉換成你模型定義的數據,然后傳輸進模型嗎?
從數據角度,轉換方式是否可靠?
從工程角度,打算選用什么消息引擎?
從代碼角度,如何實現?

3,need to be good at data engineering
Machine Learning
Data Pipeline
Data Analytics
Data Collection
Scalability Reliability Engineering
如果要做好機器學習的實踐,需要對數據工程有一定的積累。上面的5個詞匯是一個金字塔從頭到底的排序。可以看到,最底層也是一個SRE,不過這里的S指的是擴展,而不是站點。對于底層這個詞匯我的理解是,你能保證你的可伸縮的服務在發展過程中,也能很好契合我們這次機器學習實踐嗎?(如提供訓練數據,之后再使用模型提供的預測功能)
然后是數據收集,這里的難點應主要是收集系統的構建,能架得住負載、能隨服務擴展、還得好實現
數據收集到了就是分析和處理,臟數據該過濾的過濾,過于原始的數據該加工的加工
之后怎么把這些數據傳入進模型也是個問題(pipeline),我們可以在網上找到很多tensorflow的例子,就拿最火爆的識別衣服鞋子照片來說,別人的模型默認輸入的是28X28像素的照片,可問題是,你怎么把你從生產環境搞來的各種各樣的數據轉化成如何規整的數據然后pipeline給模型來訓練呢?

4,what's difference between ML and AI?
AI(artificial intelligence) is discipline, make machine act like human
ML(machine learning) is toolset, like neurton network
AI contains ML(AI技術包含ML)
機器學習和人工智能的關系是什么?簡單說:AI是規則,AI讓機器能以人的方式行動(比如人類做很多判斷時,除了理性還有感性的因素)
機器學習是工具集,比如神經網絡。
人工智能包含機器學習,也就是名詞“水果”和“蘋果”的關系

5,the old neurton network just have one hidden layer for :
computer power
data
computational tricks
神經網絡其實在三十多年前就提出了,并且當時也實現了,但那時候的應用很有限,基本上也只有一層隱藏層(不像現在的模型有很多層,可能卷積或者壓縮層就有好幾層)
造成這個原因主要有:計算機算力太弱、數據量太少、tricks(這里可以理解為一些輔助技術,比如現在做ML,很多卷積模型、過濾手段、壓縮手段都非常重組)

6,every product in Google has a dozen of ML models
this is an example:
Predict product demand
Predict inventory
Predict restocking time
16年底谷歌內部的ML模型大概有4000個,現在估計過萬了。但是要注意,一個產品會有多個機器學習模型

Google photos

Google translate: when your take photo to a signal that you don not recognize
Model1: Identify the Sign
Model2: OCR the Characters
Model3: Identify Language
Model4: Translate Language
Model5: Superimpose Text
Model6: Select Correct Font
比如你用google翻譯,拍了個標識,然后自動識別,這里就至少涉及了6個模型:1,識別出標識(停車、限速的牌子等)2,提取出字符 3,識別字符的語言 4,翻譯 5,把翻譯后的內容覆蓋到原先的標識上 6,選擇一個適合的字體

Smart Reply Inbox: a complicated ML application
sequence to sequence model
the output of previous model will be the input of next model

7, what kinds of problems can ML solve?
eric schmidt said ML is about replacing programming, but most of us think of predicting data.
機器學習到底要解決什么問題

注意!!

我們可以通過訓練已有數據獲取一個模型,然后我們自然而然想到訓練好之后,來進行預測。但這個理解還需要更進一步,機器學習真正的目的是為了替代我們原有的業務模型,我們發現需求,然后我們編寫代碼,然后迭代

Machine learning scales better than hand-coded rules
機器學習的伸縮性能力好于手寫業務邏輯規則
like you search "park" in search engine:
這里舉了一個例子,比如n年前你在谷歌上搜索一個公園,那么實際上背后就有人為編寫的一套邏輯,會查看用戶的地理位置或資料里面的位置,然后根據一套手寫的邏輯來返回搜索結果

hand-coded rules are really hard to maintain, ML scales better because it's automated
但這種手寫的規則真的太難維護了

Google RankBrain (a deep neural network for search ranking and improve performance significantly)
這里提到了RankBrain,也就是谷歌搜索引擎的機器學習系統,它會學習用戶的搜索,然后來判斷或猜測用戶到底想搜什么東西

So, we get conclusion: what kinds of problems can ML solve?
the answer is Anything for which you are writing rules for today
所以結論就是,機器學習到底是解決什么問題的呢?
只要你的業務中有需要人手動去編寫規則,就可以用機器學習來替代
(這里讓我想起做網絡設備CMDB時,添加不同廠商不同類型的設備,可能就需要編寫不同的巡檢規則、不同的指標收集規則)

8,It'all about data
when you search "coffee near me"

example equals labelled data, label this above example is "Does the user like the result or does he not?"

9,Framing an ML problem

將機器學習問題框架化

如果我們要實踐機器學習,那么可以從三個層面來框架化問題
cast it as learning problem(what data is for training, what is for predicting?)
機器學習層面:要訓練哪些數據,要預測哪些信息,如何模型成 train_data 與 label(這里要結合tensorflow的樣例代碼,比如數字09自然可以用09來表述數據的label,但真實問題,如何定義數據的label呢?)
cast it as software problem(API for service,who will use service?how it doing today?)
從軟件層面:最后要提供怎樣的API?誰會使用這項服務(使用者關心的是什么),目前沒實踐機器學習之前是怎樣處理業務問題?(痛點是?)
cast it in framework of a data problem(key actions to collect,analyze,)

Some scenario

10,Infuse your apps with ML
一些成功的實踐經驗
AUCNET as an example
AUCNET是一個日本網站,通過你拍攝汽車的照片,然后給你分析汽車型號,并整合其它服務(比如該型號的所有配置,購買信息等)

11,What is the pre-trained model?
GCP provide:
Vision API
Speech API
Jobs API
Translation API
Natural Language API
Video Intelligence API
這里相當于給GCP,谷歌云平臺打的廣告,意思是比如你要做一個識別翻譯服務,沒必要實現全部模型,比如谷歌云平臺已經提供視覺識別的機器學習API

12,The ML marketplace is moving towards increasing levels of ML abstraction
ML的市場發展方向,是提升機器學習的抽象能力(怎么理解這句話呢,個人理解就好比從小學到大學甚至master phd所接觸到的數學一樣)
數學的核心是通過模型來解釋現實,而很明顯,y = kx+b這種方程能概括的現實問題遠不如 傅里葉能 抽線的現實問題多

13,Build a data strategy around ML

14,Simple ML and More Data > Fancy ML and Small Data
so spend your energy collecting more data, not only quantity but also varity
機器學習最重要的不是你有多漂亮一個模型,或者這個模型多么高端和精準,模型是一個迭代的過程,而更重要的是大量的數據,并且除了足夠的“量”,還需要盡可能多的種類

15,how to successfully applied ML?
Collecting data is often the longest and hardest part of ML project and the most likey to fail
應用ML的過程中,總耗時并且最容易導致失敗的環節就是收集數據
collecting data contains rating, rating means finding labels for the data
這里的收集(collecting)還包括rating,這里的rating的意思是為數據設置label(這里我理解的是,在現實的業務環境下,更多的生產數據是很難用yes或no來簡單的描述,我們或許會用還行、很好等詞來形容,但對于機器,則不能適用這樣模糊的描述,特別是用于訓練的數據,則需要有明確用于區分的label)

ML is a journey towards automation and scale
請把我,實踐機器學習的目的是為了自動化與業務規模化

when we talking ML, most engineers keep thinking training, but the true utility of ML comes during predictions
當我們談論機器學習,大多數工程師會一直想如何訓練,但機器學習真正的用處是預測這個過程,請把握這一點,不要過分糾結于模型訓練

your models have to work on streaming data
你所創建的模型一定得能工作于流數據(這句話的意思就是,當我們學習tensorflow時,使用的數據集可能是預先準備好的,但如果投入實際生產,模型則需要能在從流數據中得到不斷修正,也能為流數據做預測)

sometimes fail cuz something called training-serving skew
to reduce this skew, you'd better take the same code that was used to process historical data during training and reuse it during predictions
我們需要保證訓練和預測使用相同的環境、相同的代碼

your data pipeline have to process both batch and stream
你的數據管道需要能同時處理batch和stream data,這句和上面的work on streaming data是一個意思。batch data好理解也好實現,但是stream data就沒那么好處理(這里也好想明白,特別機器學習這種很需要大量數據的業務,如果你搭建并使用過分布式消息引擎就明白stream data會帶來的麻煩)

During prediction, the key performance aspect is speed of response
在預測環節,最重要的性能指標就是響應速度

the magic of ML comes with quantity, not complexity
ML的magic來自大量數據,而不是這東西的復雜度(不是代碼寫得復雜,b格高就好)

Unstructed data accounts for 90% of enterprise data(like email, video footage, texts, reports, catalog, events)
雖然我們學習ML,學習tensorflow時用的訓練數據都是規整的,但實際業務中,超過90%數據都是非結構化的,比如郵件、視頻、文本、報告等

pre-trained models make processing unstructed data easier
所以要學會使用別的公司、機構提供的現成模型來做數據處理(一方面給GCP的ML API打廣告,另外一方面告誡希望實踐ML的工程師,不要強求自己去實現ML中的各個環節)

business can benefit from ML?
1,Infuse your apps with ML, simplify user input adapt to user
2,fine-tune your business, streamline your business processes
3,Anticipate users' need creatively fulfill intent

How Google Does ML

Google suggests that we should pay more focus on collecting data and building infrastrucutre instead of optimizing ML algorithm
谷歌很講自己是機器學習應用最成功的公司,甚至沒有說之一。如果你想實踐機器學習并幫助自己的業務,那么請為收集數據和創建基礎設施(這里的基礎設施,比如數據管道pipeline,比如應對服務批量部署的基礎設施,記得前面說了ML的目標之一就是scale)下足夠多的精力

Avoid these top 10 ML pitfalls
10個ML陷阱
1,ML requires just as much software infrastructure
successful ML practise needs lots of things around the algorithm like a whole software stack to serve
2,no data collected yet
there is no need to talk about ML without collecting great data or access to great data
3,assume the data is ready for use
4,keep human in loop
5,product launch for the wrong thing
6,ML optimizing for the wrong thing
7,is your ML improving things in the real world
8,using a pre-trained ML algorithm vs building your own
9,ML algorithm are trained more than once
10,trying to design your own perception or NLP algorithm


微信截圖_20191101184501.png

這里可以學習下PPT技巧,在上面這張圖中,除了1~10列舉了10個陷阱,還通過前面帶顏色的小方塊說明可能出現的階段

the good thing to hear: most of the values comes along the way.
as you march towards ML, you may not get there, and you will still greatly improve everything you're working on.when you get there, ML improves alomost everything it touches once you're ready.
前面講了很多機器學習失敗的原因,這里也需要給所有鼓鼓勁,在實踐ML的過程中就會給你的業務帶來好處

if the process to build and use ML is hard for your company, it's likely hard for the other members of your industry.
你需要明白,如果覺得實踐過程很難,那么對同行也是一樣的。
但如果你能做出一點成果,得到的反饋卻是極好的,客戶會容易感知到更好的服務,并給與你更多積極、準確的數據反饋,然后這個反饋又會促進你去微調業務

ML and business processes
Look at 5 phases:
1, Individual contributor
2, Delegation
3, Digitization
4, Big data and Analytics
5, Analytics Machine Learning
1~3階段是傳統的業務模型,45是最近幾年火熱的大數據與機器學習

微信截圖_20191101190257.png

微信截圖_20191101190305.png
微信截圖_20191104091059.png
微信截圖_20191104091456.png
微信截圖_20191104091759.png
微信截圖_20191104091855.png
微信截圖_20191104092049.png
微信截圖_20191104092120.png

微信截圖_20191104092424.png
微信截圖_20191104092433.png
微信截圖_20191104092532.png
微信截圖_20191104152930.png

finally, great ML systems will need humans in the loop.
and you should think about ML as a way to expand the impact or to scale the impact of your people, not as a way of complete removing them.

the more people you have in your organization, the more voices you have to say, automation is impossible
這句話就是上面delegation這個階段過久的一個問題,你的組織中人員越多,自動化就越難實現

Learn how to identify the origins of bias in ML/ make models inclusive/ evaluate ML models with biases

ML and human bias
想象一張鞋子的圖片,不同人會有不同想象,這就是human bias
but just because something is based on data doesn't automatically make it neutral
因為模型是人類訓練的,而即便對于相同的東西,不同的人也有不同的傾向,所以human bias是需要關注的一個問題

a common way that we evaluate performance in ML is by using a confusion matrix.
我們評估ML模型性能的一個方式就是使用confusion matrix

statistical measurement and acceptable tradeoff
we should focus on the False Positive Rate(labels says something doesn't exist but Model predicts it)
我們更應關心上圖中的False Positive Rate
Rate = False Negatives / False Negatives + True Positives

False positive rate (α) = type I error = 1 ? specificity = FP / (FP + TN) = 180 / (180 + 1820) = 9%
False negative rate (β) = type II error = 1 ? sensitivity = FN / (TP + FN) = 10 / (20 + 10) = 33%
True positive rate (TPR), Recall, Sensitivity, probability of detection = Σ True positive/Σ Condition positive
Accuracy (ACC) = Σ True positive + Σ True negative/Σ Total population
Precision = Σ True positive/Σ Predicted condition positive
https://en.wikipedia.org/wiki/Sensitivity_and_specificity

后面所講的內容就是利用google的datalab在線進行學習與測試
這個產品就是類似google docs的在線編輯器

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 230,501評論 6 544
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 99,673評論 3 429
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 178,610評論 0 383
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 63,939評論 1 318
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 72,668評論 6 412
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 56,004評論 1 329
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 44,001評論 3 449
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 43,173評論 0 290
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 49,705評論 1 336
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 41,426評論 3 359
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 43,656評論 1 374
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 39,139評論 5 364
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,833評論 3 350
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 35,247評論 0 28
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 36,580評論 1 295
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 52,371評論 3 400
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 48,621評論 2 380