-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrediction using Supervised ML.py
More file actions
96 lines (46 loc) · 1.31 KB
/
Prediction using Supervised ML.py
File metadata and controls
96 lines (46 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# In[3]:
url="http://bit.ly/w-data"
data_load = pd.read_csv(url)
print("Successfully imported data into console" )
# In[4]:
data_load.head(10)
# In[7]:
data_load.plot(x='Hours', y='Scores', style='o')
plt.title('Hours vs Percentage')
plt.xlabel('The Hours Studied')
plt.ylabel('The Percentage Scored')
plt.show()
# In[8]:
X = data_load.iloc[:, :-1].values
y = data_load.iloc[:, 1].values
# In[9]:
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y,test_size=0.2, random_state=0)
# In[10]:
from sklearn.linear_model import LinearRegression
regressor = LinearRegression()
regressor.fit(X_train, y_train)
print("Training ... Completed !.")
# In[11]:
line = regressor.coef_*X+regressor.intercept_
plt.scatter(X, y)
plt.plot(X, line);
plt.show()
# In[12]:
print(X_test)
y_pred = regressor.predict(X_test)
# In[13]:
df = pd.DataFrame({'Actual': y_test, 'Predicted': y_pred})
df
# In[14]:
hours = [[9.25]]
own_pred = regressor.predict(hours)
print("Number of hours = {}".format(hours))
print("Prediction Score = {}".format(own_pred[0]))
# In[ ]: