-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdummy_variables.py
More file actions
48 lines (29 loc) · 919 Bytes
/
Copy pathdummy_variables.py
File metadata and controls
48 lines (29 loc) · 919 Bytes
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
import pandas as pd
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import LabelEncoder
from sklearn.preprocessing import OneHotEncoder
# DUMMY VARIABLE METHOD
df = pd.read_csv("homeprices.csv")
# print(df)
dummies = pd.get_dummies(df.town)
merged = pd.concat([df,dummies], axis= "columns")
# print(merged)
final = merged.drop(["town", "west windsor"], axis= "columns")
# print(final)
model = LinearRegression()
x_ = final.drop("price", axis= "columns").values
y_ = final.price.values
model.fit(x_,y_)
# print(x_)
# print(model.predict([[2800, 0,1]]))
print(model.score(x_,y_))
# ONE HOT ENCODING METHOD
# le =LabelEncoder()
# dfle = df
# dfle.town = le.fit_transform(dfle.town)
# x = dfle[["town", "area"]].values
# y = dfle.price
# ohe = OneHotEncoder(categories= [0])
# x = ohe.fit_transform(x)
# print(x)
# print(dfle)