Skip to content

Commit 305e7fd

Browse files
committed
Linear Regression Tutorial Fixed for Questions
1 parent 8069722 commit 305e7fd

9 files changed

+840
-13
lines changed

.DS_Store

0 Bytes
Binary file not shown.

PySpark_Basics/PySpark_Part1_Word_Count_Removing_Punctuation_Pride_Prejudice.ipynb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,9 @@
341341
}
342342
],
343343
"metadata": {
344+
"anaconda-cloud": {},
344345
"kernelspec": {
345-
"display_name": "Python 2",
346+
"display_name": "Python [default]",
346347
"language": "python",
347348
"name": "python2"
348349
},
@@ -356,7 +357,7 @@
356357
"name": "python",
357358
"nbconvert_exporter": "python",
358359
"pygments_lexer": "ipython2",
359-
"version": "2.7.11"
360+
"version": "2.7.12"
360361
}
361362
},
362363
"nbformat": 4,

Python_Basics/.DS_Store

0 Bytes
Binary file not shown.

Python_Basics/Linear_Regression/.ipynb_checkpoints/Linear_Regression_Python-checkpoint.ipynb

Lines changed: 254 additions & 0 deletions
Large diffs are not rendered by default.

Python_Basics/Linear_Regression/.ipynb_checkpoints/Linear_Regression_Python_clean-checkpoint.ipynb

Lines changed: 273 additions & 0 deletions
Large diffs are not rendered by default.

Python_Basics/Linear_Regression/Linear_Regression_Python.ipynb

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,7 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"Linear Regression Python Tutorial by Michael Galarnyk <p></p><p></p>\n",
8-
"youtube video on how to install anaconda on mac osx: <p></p>\n",
9-
"<a href = \"https://www.youtube.com/watch?v=B6d5LrA8bNE\" style=\"color: rgb(0,0,255)\"><u> https://www.youtube.com/watch?v=B6d5LrA8bNE </u> </a><p></p><p></p>\n",
10-
"\n",
11-
"youtube video explaining linear regression using python (this notebook): <p></p><p></p>\n",
12-
"<a href = \"https://www.youtube.com/watch?v=dSYJVbj4Eew\" style=\"color: rgb(0,0,255)\"><u>https://www.youtube.com/watch?v=dSYJVbj4Eew </u> </a><p></p><p></p>\n",
13-
"\n"
7+
"Linear Regression Python Tutorial <p></p><p></p>"
148
]
159
},
1610
{
@@ -89,7 +83,7 @@
8983
],
9084
"source": [
9185
"raw_data = pd.read_csv(\"linear.csv\") #any dataset will work. You can get the data from my github\n",
92-
"# https://github.com/mGalarnyk/Linear_Regression\n",
86+
"# https://github.com/mGalarnyk/Python_Tutorials/blob/master/Python_Basics/Linear_Regression/linear.csv\n",
9387
"raw_data.head(3)"
9488
]
9589
},
@@ -236,8 +230,9 @@
236230
}
237231
],
238232
"metadata": {
233+
"anaconda-cloud": {},
239234
"kernelspec": {
240-
"display_name": "Python 2",
235+
"display_name": "Python [default]",
241236
"language": "python",
242237
"name": "python2"
243238
},
@@ -251,7 +246,7 @@
251246
"name": "python",
252247
"nbconvert_exporter": "python",
253248
"pygments_lexer": "ipython2",
254-
"version": "2.7.11"
249+
"version": "2.7.12"
255250
}
256251
},
257252
"nbformat": 4,

Python_Basics/Linear_Regression/Linear_Regression_Python_clean.ipynb

Lines changed: 273 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import numpy as np
2+
import pandas as pd
3+
from sklearn.linear_model import LinearRegression
4+
import matplotlib.pyplot as plt
5+
6+
raw_data = pd.read_csv("linear.csv")
7+
8+
# Removes rows with NaN in them
9+
10+
filtered_data = raw_data[~np.isnan(raw_data["y"])]
11+
12+
13+
14+
npMatrix = np.matrix(filtered_data)
15+
X, Y = npMatrix[:,0], npMatrix[:,1]
16+
mdl = LinearRegression().fit(X,Y) # either this or the next line
17+
#mdl = LinearRegression().fit(filtered_data[['x']],filtered_data.y)
18+
m = mdl.coef_[0]
19+
b = mdl.intercept_
20+
21+
# show alternate way to get equation of the line
22+
print "formula: y = {0}x + {1}".format(m, b) # following slope intercept form
23+
24+
#
25+
# show how to plot using non python notebooks
26+
plt.scatter(X,Y, color='blue')
27+
plt.plot([0,100],[b,m*100+b],'r')
28+
plt.title('Linear Regression Example', fontsize = 20)
29+
plt.xlabel('X', fontsize = 15)
30+
plt.ylabel('Y', fontsize = 15)

TensorFlow/LinearRegression_TensorFlow.ipynb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,9 @@
480480
}
481481
],
482482
"metadata": {
483+
"anaconda-cloud": {},
483484
"kernelspec": {
484-
"display_name": "Python 2",
485+
"display_name": "Python [default]",
485486
"language": "python",
486487
"name": "python2"
487488
},

0 commit comments

Comments
 (0)