1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Created on Fri Jun 28 16:18:11 2019
5
+
6
+ @author: aman
7
+ """
8
+
9
+ import numpy as np
10
+ import pandas as pd
11
+ import matplotlib .pyplot as plt
12
+
13
+ #from pandas.plotting import scatter_matrix
14
+
15
+
16
+ dataset = pd .read_csv ("/home/aman/ML/DataSet/housing.csv" )
17
+ dataset .head ()
18
+
19
+ X = dataset .iloc [:,[0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,9 ]].values
20
+ y = dataset .iloc [:,8 ].values
21
+
22
+ #pd.plotting.scatter_matrix(dataset)
23
+
24
+
25
+ dataset .isnull ().sum ()
26
+
27
+
28
+ #dataset["total_bedrooms"].isnull().sum()
29
+
30
+
31
+
32
+
33
+ from sklearn .preprocessing import Imputer
34
+ im = Imputer (missing_values = "NaN" ,strategy = "median" )
35
+ X [:,[4 ]]= im .fit_transform (X [:,[4 ]])
36
+
37
+ from sklearn .preprocessing import LabelEncoder
38
+ lib = LabelEncoder ()
39
+ X [:,8 ]= lib .fit_transform (X [:,8 ])
40
+
41
+ from sklearn .preprocessing import OneHotEncoder
42
+ one = OneHotEncoder (categorical_features = [8 ])
43
+ X = one .fit_transform (X )
44
+ X = X .toarray ()
45
+
46
+
47
+ from sklearn .linear_model import LinearRegression
48
+ linreg = LinearRegression ()
49
+ linreg .fit (X ,y )
50
+ linreg .score (X ,y )
51
+
52
+ from sklearn .preprocessing import StandardScaler
53
+ sc = StandardScaler ()
54
+ X = sc .fit_transform (X )
55
+
56
+
57
+ from sklearn .model_selection import train_test_split
58
+ X_train ,X_test ,y_train ,y_test = train_test_split (X ,y )
59
+
60
+ from sklearn .linear_model import LinearRegression
61
+ lin = LinearRegression ()
62
+ lin .fit (X_train ,y_train )
63
+
64
+
65
+ ypred = lin .predict (X_test )
66
+
67
+ lin .score (X_test ,y_test )
68
+
69
+
70
+ from
71
+ #if radj is negetive then the model you created is not eliiglible for the prediction
0 commit comments