Skip to content

Commit 8f9709f

Browse files
committed
updated linear regression multi variable tutorial
1 parent 9a24450 commit 8f9709f

File tree

2 files changed

+421
-45
lines changed

2 files changed

+421
-45
lines changed

ML/2_linear_reg_multivariate/2_linear_regression_multivariate.ipynb

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,8 @@
6262
},
6363
{
6464
"cell_type": "code",
65-
"execution_count": 44,
66-
"metadata": {
67-
"collapsed": true
68-
},
65+
"execution_count": 1,
66+
"metadata": {},
6967
"outputs": [],
7068
"source": [
7169
"import pandas as pd\n",
@@ -75,7 +73,7 @@
7573
},
7674
{
7775
"cell_type": "code",
78-
"execution_count": 45,
76+
"execution_count": 2,
7977
"metadata": {
8078
"scrolled": true
8179
},
@@ -164,7 +162,7 @@
164162
"5 4100 6.0 8 810000"
165163
]
166164
},
167-
"execution_count": 45,
165+
"execution_count": 2,
168166
"metadata": {},
169167
"output_type": "execute_result"
170168
}
@@ -183,30 +181,27 @@
183181
},
184182
{
185183
"cell_type": "code",
186-
"execution_count": 46,
187-
"metadata": {
188-
"collapsed": true
189-
},
190-
"outputs": [],
191-
"source": [
192-
"import math\n",
193-
"med_bedrooms = math.floor(df.bedrooms.median())"
194-
]
195-
},
196-
{
197-
"cell_type": "code",
198-
"execution_count": 47,
199-
"metadata": {
200-
"collapsed": true
201-
},
202-
"outputs": [],
184+
"execution_count": 3,
185+
"metadata": {},
186+
"outputs": [
187+
{
188+
"data": {
189+
"text/plain": [
190+
"4.0"
191+
]
192+
},
193+
"execution_count": 3,
194+
"metadata": {},
195+
"output_type": "execute_result"
196+
}
197+
],
203198
"source": [
204-
"df.bedrooms = df.bedrooms.fillna(med_bedrooms)"
199+
"df.bedrooms.median()"
205200
]
206201
},
207202
{
208203
"cell_type": "code",
209-
"execution_count": 48,
204+
"execution_count": 5,
210205
"metadata": {},
211206
"outputs": [
212207
{
@@ -293,50 +288,52 @@
293288
"5 4100 6.0 8 810000"
294289
]
295290
},
296-
"execution_count": 48,
291+
"execution_count": 5,
297292
"metadata": {},
298293
"output_type": "execute_result"
299294
}
300295
],
301296
"source": [
297+
"df.bedrooms = df.bedrooms.fillna(df.bedrooms.median())\n",
302298
"df"
303299
]
304300
},
305301
{
306302
"cell_type": "code",
307-
"execution_count": 49,
303+
"execution_count": 6,
308304
"metadata": {
309305
"scrolled": true
310306
},
311307
"outputs": [
312308
{
313309
"data": {
314310
"text/plain": [
315-
"LinearRegression(copy_X=True, fit_intercept=True, n_jobs=1, normalize=False)"
311+
"LinearRegression(copy_X=True, fit_intercept=True, n_jobs=None,\n",
312+
" normalize=False)"
316313
]
317314
},
318-
"execution_count": 49,
315+
"execution_count": 6,
319316
"metadata": {},
320317
"output_type": "execute_result"
321318
}
322319
],
323320
"source": [
324321
"reg = linear_model.LinearRegression()\n",
325-
"reg.fit(df[['area','bedrooms','age']],df.price)"
322+
"reg.fit(df.drop('price',axis='columns'),df.price)"
326323
]
327324
},
328325
{
329326
"cell_type": "code",
330-
"execution_count": 50,
327+
"execution_count": 7,
331328
"metadata": {},
332329
"outputs": [
333330
{
334331
"data": {
335332
"text/plain": [
336-
"array([ 112.06244194, 23388.88007794, -3231.71790863])"
333+
"array([ 112.06244194, 23388.88007794, -3231.71790863])"
337334
]
338335
},
339-
"execution_count": 50,
336+
"execution_count": 7,
340337
"metadata": {},
341338
"output_type": "execute_result"
342339
}
@@ -347,18 +344,18 @@
347344
},
348345
{
349346
"cell_type": "code",
350-
"execution_count": 51,
347+
"execution_count": 8,
351348
"metadata": {
352349
"scrolled": true
353350
},
354351
"outputs": [
355352
{
356353
"data": {
357354
"text/plain": [
358-
"221323.00186540384"
355+
"221323.00186540408"
359356
]
360357
},
361-
"execution_count": 51,
358+
"execution_count": 8,
362359
"metadata": {},
363360
"output_type": "execute_result"
364361
}
@@ -376,16 +373,16 @@
376373
},
377374
{
378375
"cell_type": "code",
379-
"execution_count": 52,
376+
"execution_count": 9,
380377
"metadata": {},
381378
"outputs": [
382379
{
383380
"data": {
384381
"text/plain": [
385-
"array([ 498408.25158031])"
382+
"array([498408.25158031])"
386383
]
387384
},
388-
"execution_count": 52,
385+
"execution_count": 9,
389386
"metadata": {},
390387
"output_type": "execute_result"
391388
}
@@ -396,7 +393,7 @@
396393
},
397394
{
398395
"cell_type": "code",
399-
"execution_count": 55,
396+
"execution_count": 10,
400397
"metadata": {
401398
"scrolled": true
402399
},
@@ -407,7 +404,7 @@
407404
"498408.25157402386"
408405
]
409406
},
410-
"execution_count": 55,
407+
"execution_count": 10,
411408
"metadata": {},
412409
"output_type": "execute_result"
413410
}
@@ -425,16 +422,16 @@
425422
},
426423
{
427424
"cell_type": "code",
428-
"execution_count": 54,
425+
"execution_count": 11,
429426
"metadata": {},
430427
"outputs": [
431428
{
432429
"data": {
433430
"text/plain": [
434-
"array([ 578876.03748933])"
431+
"array([578876.03748933])"
435432
]
436433
},
437-
"execution_count": 54,
434+
"execution_count": 11,
438435
"metadata": {},
439436
"output_type": "execute_result"
440437
}
@@ -493,7 +490,7 @@
493490
"name": "python",
494491
"nbconvert_exporter": "python",
495492
"pygments_lexer": "ipython3",
496-
"version": "3.6.1"
493+
"version": "3.7.3"
497494
}
498495
},
499496
"nbformat": 4,

0 commit comments

Comments
 (0)