岁月不饶人是什么意思| 人生没有什么不可放下| 8月10日是什么星座| 才高八斗代表什么生肖| 女右眉毛跳是什么预兆| 咳嗽不能吃什么| cpb是什么意思| 趣味相投是什么意思| 办护照有什么要求| fcm是什么意思| 喉咙嘶哑是什么原因| 723是什么意思| 江小白加雪碧什么意思| 梅核气吃什么药最好| 雷锋属什么生肖| 独什么心什么| 心房纤颤是什么意思| 谷维素是治疗什么的| 同型半胱氨酸高吃什么| 今日农历是什么日子| 七月半是什么日子| 头皮痒头皮屑多是什么原因| 嘴角裂口是什么原因| 晚上九点半是什么时辰| CA是什么激素| 梦见自己坐车是什么意思| 胸椎退行性变什么意思| 血脂指的是什么| 什么花草| 带状疱疹吃什么药| 12月29号是什么星座| 后背疼是什么原因引起的| 梦见蛇挡路是什么意思| 马六甲板材是什么木材| 冲锋衣是什么意思| 金字旁加者念什么| chanel是什么牌子| 冰释前嫌的释是什么意思| 甲硝唑有什么副作用| 打开心扉是什么意思| pcl是什么意思| 10月7日什么星座| 孕吐喝什么水可以缓解| 肉丝炒什么菜好吃| 水煮肉片用什么肉| 吃布洛芬不能吃什么| 尿酸高什么水果不能吃| 三十六计第一计是什么| 天龙八部是什么朝代| 美元长什么样子图片| 丰富是什么意思| 裂隙灯能查出什么眼病| 越南三宝是什么| 牡丹花是什么颜色的| 低密度脂蛋白高是什么意思| 甲状腺偏高有什么影响| 雍是什么意思| 久而久之下一句是什么| 全身体检挂什么科| 氟西汀是什么药| 藿香正气水能治什么病| 职业年金是什么| 率性是什么意思| 肚子突然疼是什么原因| 做梦梦见狗是什么意思| 查血糖挂什么科| 三体是什么意思| 温州有什么特产| 虎皮羊质是指什么生肖| 双侧胸膜增厚是什么意思| 胳膊脱臼是什么症状| 左侧附件区囊性回声是什么意思| icu病房是什么意思| 手心发痒是什么原因| 1987年什么命| 布洛芬什么时候起效| 复方板蓝根和板蓝根有什么区别| 胆管炎吃什么药| 干眼症用什么药| 惹上官司是犯了什么煞| 缓释片是什么意思| 去湿气喝什么| 浮粉是什么原因引起的| 喝什么酒容易醉| 早搏是什么原因引起的| 蹲不下去是什么原因| 什么是卒中| 倾诉是什么意思| 既往病史是什么意思| hpv亚型是什么意思| 迪根是什么药| 布鲁氏菌病是什么病| 暗合是什么意思| 泡黄芪水喝有什么好处| 胃痛怎么办吃什么药| 知柏地黄丸适合什么人吃| 壅是什么意思| 腹痛吃什么药| 助听器什么品牌最好| 怀孕乳房会有什么变化| 五行缺金有什么影响| 雍正姓什么| 属龙的和什么属相最配| 为什么这么热| 胃打嗝是什么原因| 流弹是什么意思| 尿酸高吃什么药降尿酸效果好| 女性检查甲功是什么病| 老人头晕吃什么药效果好| 西游记告诉我们什么道理| colorful是什么牌子| 浮瓜沉李什么意思| 金钱肚是什么| 2月是什么星座| 什么病需要做透析| 鱼胶是鱼的什么部位| 梦见抓蛇是什么预兆| 六八年属什么生肖| 替拉依是什么药| 5月6日是什么星座| 吃木瓜有什么作用| 令瓦念什么| 治疗呼吸道感染用什么药最好| 高血压适合吃什么水果| 北京大学前身叫什么| 晚上20点是什么时辰| 四川的耗儿鱼是什么鱼| nba打铁是什么意思| 包皮红肿用什么药| 73年属牛的是什么命| 北北是什么意思| 什么是双相情感障碍| 关节疼痛吃什么药| 武则天代表什么生肖| 小孩晚上睡觉流口水是什么原因| 屙是什么意思| 敏感什么意思| 中医经方是什么意思| hpv亚临床感染是什么意思| 檄文是什么意思| 什么是裙带菜| 什么虎什么山| 认真是什么意思| 甲沟炎是什么样子的| 日出东方下一句是什么| 天天喝白酒对身体有什么危害| 绝经什么意思| 除湿气喝什么茶| 健身后应该吃什么| 坠积效应是什么意思| 耳鸣吃什么| 献血有什么好处| 什么是静息心率| 水加日念什么| 增生性贫血是什么意思| 水逆退散是什么意思| 火车为什么会晚点| 满满的回忆什么意思| 早孕期间吃什么最营养| 皮革是什么材质| 小孩腿抽筋是什么原因引起的| 咳嗽吃什么能治好| 葡萄球菌用什么抗生素| 男人为什么会遗精| 叩首是什么意思| 对眼是什么意思| 细菌属于什么生物| kitty是什么意思| 占卜是什么意思| 24是什么生肖| 白带变绿用什么药| 吃什么去肝火| 补肾吃什么药最好| 感知力是什么意思| 月老叫什么名字| 什么是安全期和排卵期| 经期吃什么缓解痛经| 痰盂是什么意思| 总胆汁酸高吃什么药| 孔雀喜欢吃什么食物| 脚气用什么药膏最好| 4.23是什么星座| 内膜欠均匀是什么意思| 梦到猫是什么意思| 阴茎是什么| 1月30日什么星座| 大便是红色的是什么原因| wh是什么颜色| 心室早复极是什么意思| 脸发红是什么原因| 吃葵花籽有什么好处和坏处吗| 伤心的反义词是什么| 懵逼是什么意思| 有氧运动是什么| 土字旁有什么字| 滋养细胞疾病是什么病| 优甲乐过量有什么症状| 四不像长什么样| 总胆红素偏高什么意思| 干白是什么酒| 强磁对人体有什么危害| 七月一是什么星座| 三唑仑是什么| 蟑螂喜欢吃什么东西| 什么原因引起甲亢| 直肠给药对小孩身体有什么影响| 黄花鱼是什么鱼| 什么是冬虫夏草| 左心房增大是什么原因| 敲定是什么意思| 2048年是什么年| 什么是会车| 维生素b12是什么| 敬谢不敏什么意思| 发烧头痛吃什么药| 翻糖是什么| 边缘心电图是什么意思| 小儿拉肚子吃什么药好得快| 感冒是什么意思| 马英九属什么| 药物流产后吃什么好| 驴血为什么是白色的| 母亲是o型血孩子是什么血型| 眼睛流水是什么原因| 切糕为什么这么贵| 胰岛素针头4mm和5mm有什么区别| 桃花依旧笑春风什么意思| 外阴萎缩是什么症状| 拜土地公时要念什么好| joma是什么牌子| 哺乳期感冒了能吃什么药| 雪貂吃什么| 岁月蹉跎什么意思| 什么掌不能拍| 老是打喷嚏是什么原因| 冬天喝什么茶| 早上8点到9点是什么时辰| 十月二十二什么星座| 大保健是什么意思| 梦见修路什么意思| 红楼梦为什么是四大名著之首| 三千大千世界什么意思| 金字旁土念什么字| it代表什么| 梦到吃蛇肉预示着什么| 见血是什么兆头| 6是什么意思| 胸口堵是什么原因| 违拗是什么意思| 芬太尼是什么| 全职太太是什么意思| 附骨疽在现代叫什么病| 酸菜炒什么好吃| 五十坐地能吸土是什么意思| 手术后可以吃什么水果| 无创什么时候出结果| hkc是什么牌子| 什么的气泡| 胃酸有什么办法缓解| 嘴角长水泡是什么原因| 奶茶三兄弟是什么| 水逆什么意思| 肌酐高有什么症状表现| 小姨的女儿叫什么| 百度
Machine Learning & Big Data Blog

浙江省预防医学会五届六次常务理事和五...

4 minute read
Walker Rowe
百度 而香港证监会主席唐家成早前也指出,内地和香港并非竞争对象,新加坡才是竞争对象,未来内地企业如果以CDR和同股不同权形式在内地及香港一起上市,将会是双赢的结果。

Here we explore another machine learning framework, scikit-learn, as well as show how to use matplotlib, to draw graphs. Check out the official site for scikit-learn.

The scikit-learn python ML API predates Apache Spark and TensorFlow, which is to say it has been around longer than big data. It has long been used by those who see themselves as pure data scientists, as opposed to data engineers. Still you can connect scikit-learn to Spark so that the transformations and calculations you can run across a cluster of machines. Without that you can only work with datasets that fit into the memory, cpu speed, and disk space of a single machine.

Scikit-learn is very strong on statistical functions and packed full of almost every algorithm you can think of, including those that only academics and mathematicians would understand, plus neural networks, which is applied ML. But you need not be a mathematician to get started with the product. Here we show how to code the simplest possible example.

(This article is part of our scikit-learn Guide. Use the right-hand menu to navigate.)

Environment

You should use conda to setup Python and install packages. This will make it easy to integrate sckit-learn with Zeppelin Notebooks. It is difficult to add python packages to Zeppelin otherwise.

You could run this example from the Python command line, but Zeppelin is graphical, so you can draw nice graphs with matplotlib.

When you install Zeppelin, install the package with ALL interpreters so that Python, Spark, matplotlib. etc. are there. Follow this example if you are new to Zeppelin to understand that.

Install Anaconda and then enter this command to install scikit-learn:

conda install scikit-learn

Then in Zeppelin point your Python interpreter to the Anaconda Python like this:

Example

We will do the simplest possible example, which is linear regression with 1 independent variable and 1 dependant variable. And we will set up our data so that the data is perfectly correlated, meaning the variance is 1. In other words, with LR the goal is to solve this equation for a straight line by finding the coefficient m and y intercept b.

y = mx + b

But our goal here is just to show how to use scikit-learn. So we will mock our data using y = 2x + 0 = 2x. (If you want a more realistic example you could use the standard normal distribution and draw a random noise factor from that and add that to y.)

The code from this example is stored here as a Zeppelin notebook. Below we show the code in sections. You can paste the sections into Zeppelin paragraphs in a Zeppelin notebook. Be sure to select the python interpreter when you create the notebook.

import matplotlib.pyplot as plt
from sklearn import linear_model
import numpy as np
from sklearn.metrics import mean_squared_error, r2_score

First we instantiate the LinearRegression model.

reg = linear_model.LinearRegression()

Next we make an array. On the left are the independent variables 1,2,3. On the right are the dependant ones 2,4,6. As you can see each dependent variable y is equal to each dependant variable x times 2, i.e., y=2x.

Scikit-learn expects you to use a numpy array.

ar = np.array([[[1],[2],[3]], [[2],[4],[6]]])
ar

Results. Printing out each result helps to visualize and understand it.

array([[[1],
[2],
[3]],
[[2],
[4],
[6]]])

Here we slice the array taking just the y variables. (Slicing and reshaping arrays is a complicated topic. You can read about that here.) This array shape, ar.shape, is given in this tuple (2,3,1). This is an array 1 of 2 arrays. So we alternatives take the first 1 x 3 array at the second position for y:

y = ar[1,:]
y

Results:

array([[2],
[4],
[6]])

Then take the first one for x.

x = ar[0,:]
x

Results:

array([[1],
[2],
[3]])

Now we have the independent variables stored in a simple vector x and the dependant variables in y. In terms of machine learning we say we have 1 feature and 1 label.

Now we run fit() which uses the least squares method to find the line y=mx, by finding the slope m, which is the same as saying the coefficient m for the line y = mx.

reg.fit(x,y)

Now we can print the coefficient from the linear regression API.

print('Coefficients: \n', reg.coef_)

Result is 2, which we would expect since we know the line is y = 2x.

Coefficients: 
[[2.]]

Now let’s make test data the same way, 4,5,6 and then 2 times that for y:

xTest = np.array([[4],[5],[6]])
xTest

Results:

array([[4],
[5],
[6]])

Now feed the x test values xTest into predict method. It will return an array of y prediction.

ytest =  np.array([[8],[10],[12]])
preds = reg.predict(xTest)
preds

Results:

array([[ 8.],
[10.],
[12.]])

Now look at the error, which is the difference between the observed values (ytest) and predicted (preds). Of course, it is zero.

print("Mean squared error: %.2f" % mean_squared_error(ytest,preds))

Results:

Mean squared error: 0.00

And the variance is 1, since the data is perfectly correlated.

print("Variance score: %.2f" % r2_score(ytest,preds))

Results

Variance score: 1.00

Now we can plot is using matplotlib:

plt.scatter(xTest,preds, color='black')
plt.plot(xTest,preds,color='blue', linewidth=3)
plt.show()

That is the simplest possible example of how to use scikit-learn ML library to do linear regression.

Learn ML with our free downloadable guide

This e-book teaches machine learning in the simplest way possible. This book is for managers, programmers, directors – and anyone else who wants to learn machine learning. We start with very basic stats and algebra and build upon that.


These postings are my own and do not necessarily represent BMC's position, strategies, or opinion.

See an error or have a suggestion? Please let us know by emailing [email protected].

About Us

As BMC and BMC Helix, we are committed to a shared purpose for customers in every industry and around the globe. BMC empowers 86% of the Forbes Global 50 to accelerate business value faster than humanly possible by automating critical applications, systems, and services to take advantage of cloud, data, and emerging AI technologies. BMC Helix, now operating as an independent company, helps the world’s most forward-thinking IT organizations turn AI into action—unlocking human potential to multiply productivity so teams can focus on the work that matters most.
Learn more about BMC and BMC Helix ?

About the author

Walker Rowe

Walker Rowe is an American freelancer tech writer and programmer living in Cyprus. He writes tutorials on analytics and big data and specializes in documenting SDKs and APIs. He is the founder of the Hypatia Academy Cyprus, an online school to teach secondary school children programming. You can find Walker here and here.

螃蟹为什么横着走 梦见下小雨是什么征兆 做激光近视眼手术有什么危害 为什么会闪电 陈皮是什么水果的皮
阻生齿是什么意思 337是什么意思 什么是黑色星期五 女人大把掉头发是什么原因 么么叽是什么意思
溃疡是什么病 一个小时尿一次是什么原因 ne医学上是什么意思 蟑螂的天敌是什么 6.7是什么星座
急性荨麻疹不能吃什么食物 哺乳期感冒吃什么药不影响哺乳 什么药可以流产 肝内多发低密度影是什么意思 生育酚乙酸酯是什么
什么夺目hcv8jop6ns4r.cn 误食干燥剂有什么危害hcv9jop5ns4r.cn 嘴唇发白是什么原因引起的hcv8jop3ns8r.cn 酸菜鱼什么鱼最好96micro.com 原位癌是什么意思hcv8jop9ns2r.cn
什么叫闺蜜hcv9jop5ns8r.cn 什么是燕麦hcv8jop1ns4r.cn 肝结节是什么意思beikeqingting.com 玄武是什么动物hcv8jop6ns5r.cn 血小板减少有什么症状hcv8jop1ns7r.cn
tj什么意思dajiketang.com 2003是什么年hcv8jop7ns5r.cn 湿疹要注意什么hcv9jop7ns9r.cn 观音坐莲是什么意思shenchushe.com 恐龙是什么时候灭绝hcv9jop0ns6r.cn
人爱出汗是什么原因hcv8jop0ns8r.cn 枭神夺食会发生什么hcv8jop5ns4r.cn 亚硝酸钠是什么东西hcv9jop5ns1r.cn 吃什么药马上硬起来hcv8jop5ns1r.cn 翌是什么意思hcv8jop4ns5r.cn
百度