1
- #!/usr/bin/env python
2
- # coding: utf-8
3
-
4
- # In[17]:
5
-
6
-
7
1
"""Implementation of GradientBoostingRegressor in sklearn using the
8
2
boston dataset which is very popular for regression problem to
9
3
predict house price.
@@ -19,19 +13,19 @@ def main():
19
13
# loading the dataset from the sklearn package
20
14
df = load_boston ()
21
15
print (df .keys ())
22
- # now let constract a data frame with data and target variables
16
+ # now let construct a data frame with data and target variables
23
17
df_boston = pd .DataFrame (df .data ,columns = df .feature_names )
24
18
# let add the target to the dataframe
25
19
df_boston ['Price' ]= df .target
26
20
# let us print the first five rows using the head function
27
21
print (df_boston .head ())
28
22
print (df_boston .describe ().T ) # to see summary statistics of the dataset
29
- # Feature selection means for independant and dependent variables
23
+ # Feature selection means for independent and dependent variables
30
24
X = df_boston .iloc [:,:- 1 ]
31
25
y = df_boston .iloc [:,- 1 ] # target variable
32
26
# we are going to split the data with 75% train and 25% test sets.
33
27
X_train ,X_test ,y_train ,y_test = train_test_split (X ,y ,random_state = 0 , test_size = .25 )
34
- # now let set the parametes of our model
28
+ # now let set the parameters of the model
35
29
params = {'n_estimators' : 500 , 'max_depth' : 5 , 'min_samples_split' : 4 ,
36
30
'learning_rate' : 0.01 , 'loss' : 'ls' }
37
31
model = GradientBoostingRegressor (** params )
@@ -56,7 +50,7 @@ def main():
56
50
ax .set_xlabel ('Actual' )
57
51
ax .set_ylabel ('Predicted' )
58
52
ax .set_title ("Truth vs Predicted" )
59
- # this show function will display the ploting
53
+ # this show function will display the plotting
60
54
plt .show ()
61
55
62
56
0 commit comments